blob: c1167f3e2626ec7a68fec54c1b6026a99cf70922 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*
2 * A generic value of different syntaxes.
3 */
4#ifndef ASN1_PARSER_VALUE_H
5#define ASN1_PARSER_VALUE_H
6
Lev Walkin5045dfa2006-03-21 09:41:28 +00007struct asn1p_constraint_s; /* Forward declaration */
Lev Walkinea6635b2017-08-06 23:23:04 -07008struct asn1p_module_s;
Lev Walkina9532f42006-09-17 04:52:50 +00009struct asn1p_expr_s;
Lev Walkin5045dfa2006-03-21 09:41:28 +000010
Lev Walkinf15320b2004-06-03 03:38:44 +000011/*
12 * A wrapper around various kinds of values.
13 */
14typedef struct asn1p_value_s {
15 /*
16 * The value of the element.
17 */
18 enum {
19 ATV_NOVALUE,
Lev Walkina9532f42006-09-17 04:52:50 +000020 ATV_TYPE, /* A type (as in CONTAINING Type) */
Lev Walkin9c974182004-09-15 11:59:51 +000021 ATV_NULL, /* A "NULL" value of type NULL. */
22 ATV_REAL, /* A constant floating-point value */
23 ATV_INTEGER, /* An integer constant */
Lev Walkinf15320b2004-06-03 03:38:44 +000024 ATV_MAX,
Lev Walkinceb20e72004-09-05 10:40:41 +000025 ATV_MIN,
Lev Walkinf15320b2004-06-03 03:38:44 +000026 ATV_TRUE,
Lev Walkinceb20e72004-09-05 10:40:41 +000027 ATV_FALSE,
Lev Walkin1e448d32005-03-24 14:26:38 +000028 ATV_TUPLE, /* { 1, 15 } */
29 ATV_QUADRUPLE, /* { 0, 14, 0, 255 } */
30 ATV_STRING, /* "abcdef" */
Lev Walkinf15320b2004-06-03 03:38:44 +000031 ATV_UNPARSED,
32 ATV_BITVECTOR,
Lev Walkin5045dfa2006-03-21 09:41:28 +000033 ATV_VALUESET, /* { 1 | 2 | 3 } */
Lev Walkin9c974182004-09-15 11:59:51 +000034 ATV_REFERENCED, /* Reference to a value defined elsewhere */
35 ATV_CHOICE_IDENTIFIER, /* ChoiceIdentifier value */
Lev Walkinf15320b2004-06-03 03:38:44 +000036 } type; /* Value type and location */
37
38 union {
Lev Walkin5045dfa2006-03-21 09:41:28 +000039 struct asn1p_constraint_s *constraint; /* ValueSet */
Lev Walkina9532f42006-09-17 04:52:50 +000040 struct asn1p_expr_s *v_type; /* Type */
Lev Walkinf15320b2004-06-03 03:38:44 +000041 asn1p_ref_t *reference;
Lev Walkind21c5052004-09-29 13:18:09 +000042 asn1c_integer_t v_integer;
Lev Walkinf15320b2004-06-03 03:38:44 +000043 double v_double;
44 /*
45 * Binary bits vector.
46 */
47 struct {
48 uint8_t *buf;
49 int size;
50 } string;
51 struct {
52 uint8_t *bits;
53 int size_in_bits;
54 } binary_vector;
Lev Walkin9c974182004-09-15 11:59:51 +000055 struct {
56 char *identifier;
57 struct asn1p_value_s *value;
58 } choice_identifier;
Lev Walkinf15320b2004-06-03 03:38:44 +000059 } value;
60} asn1p_value_t;
61
62/*
Lev Walkina00d6b32006-03-21 03:40:38 +000063 * Destructor and constructors for value.
Lev Walkinf15320b2004-06-03 03:38:44 +000064 * If ref, bits or buffer are omitted, the corresponding function returns
65 * (asn1p_value_t *)0 with errno = EINVAL.
66 * Allocated value (where applicable) is guaranteed to be NUL-terminated.
67 */
Lev Walkina00d6b32006-03-21 03:40:38 +000068void asn1p_value_free(asn1p_value_t *);
Lev Walkinf15320b2004-06-03 03:38:44 +000069asn1p_value_t *asn1p_value_fromref(asn1p_ref_t *ref, int do_copy);
Lev Walkin5045dfa2006-03-21 09:41:28 +000070asn1p_value_t *asn1p_value_fromconstr(struct asn1p_constraint_s *ct, int dc);
Lev Walkinf15320b2004-06-03 03:38:44 +000071asn1p_value_t *asn1p_value_frombits(uint8_t *bits, int size_in_bits, int dc);
72asn1p_value_t *asn1p_value_frombuf(char *buffer, int size, int do_copy);
73asn1p_value_t *asn1p_value_fromdouble(double);
Lev Walkind21c5052004-09-29 13:18:09 +000074asn1p_value_t *asn1p_value_fromint(asn1c_integer_t);
Lev Walkina9532f42006-09-17 04:52:50 +000075asn1p_value_t *asn1p_value_fromtype(struct asn1p_expr_s *);
Lev Walkinf15320b2004-06-03 03:38:44 +000076asn1p_value_t *asn1p_value_clone(asn1p_value_t *);
Lev Walkina00d6b32006-03-21 03:40:38 +000077asn1p_value_t *asn1p_value_clone_with_resolver(asn1p_value_t *,
78 asn1p_value_t *(*resolver)(asn1p_value_t *, void *rarg),
79 void *rarg);
Lev Walkinea6635b2017-08-06 23:23:04 -070080int asn1p_value_compare(const asn1p_value_t *, const asn1p_value_t *);
81void asn1p_value_set_source(asn1p_value_t *, struct asn1p_module_s *, int line);
Lev Walkinf15320b2004-06-03 03:38:44 +000082
83#endif /* ASN1_PARSER_VALUE_H */