Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * A generic value of different syntaxes. |
| 3 | */ |
| 4 | #ifndef ASN1_PARSER_VALUE_H |
| 5 | #define ASN1_PARSER_VALUE_H |
| 6 | |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 7 | struct asn1p_constraint_s; /* Forward declaration */ |
Lev Walkin | ea6635b | 2017-08-06 23:23:04 -0700 | [diff] [blame] | 8 | struct asn1p_module_s; |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 9 | struct asn1p_expr_s; |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 10 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 11 | /* |
| 12 | * A wrapper around various kinds of values. |
| 13 | */ |
| 14 | typedef struct asn1p_value_s { |
| 15 | /* |
| 16 | * The value of the element. |
| 17 | */ |
| 18 | enum { |
| 19 | ATV_NOVALUE, |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 20 | ATV_TYPE, /* A type (as in CONTAINING Type) */ |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 21 | ATV_NULL, /* A "NULL" value of type NULL. */ |
| 22 | ATV_REAL, /* A constant floating-point value */ |
| 23 | ATV_INTEGER, /* An integer constant */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 24 | ATV_MAX, |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 25 | ATV_MIN, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 26 | ATV_TRUE, |
Lev Walkin | ceb20e7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 27 | ATV_FALSE, |
Lev Walkin | 1e448d3 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 28 | ATV_TUPLE, /* { 1, 15 } */ |
| 29 | ATV_QUADRUPLE, /* { 0, 14, 0, 255 } */ |
| 30 | ATV_STRING, /* "abcdef" */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 31 | ATV_UNPARSED, |
| 32 | ATV_BITVECTOR, |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 33 | ATV_VALUESET, /* { 1 | 2 | 3 } */ |
Lev Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 34 | ATV_REFERENCED, /* Reference to a value defined elsewhere */ |
| 35 | ATV_CHOICE_IDENTIFIER, /* ChoiceIdentifier value */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 36 | } type; /* Value type and location */ |
| 37 | |
| 38 | union { |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 39 | struct asn1p_constraint_s *constraint; /* ValueSet */ |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 40 | struct asn1p_expr_s *v_type; /* Type */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 41 | asn1p_ref_t *reference; |
Lev Walkin | d21c505 | 2004-09-29 13:18:09 +0000 | [diff] [blame] | 42 | asn1c_integer_t v_integer; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 43 | 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 Walkin | 9c97418 | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 55 | struct { |
| 56 | char *identifier; |
| 57 | struct asn1p_value_s *value; |
| 58 | } choice_identifier; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 59 | } value; |
| 60 | } asn1p_value_t; |
| 61 | |
| 62 | /* |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 63 | * Destructor and constructors for value. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 64 | * 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 Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 68 | void asn1p_value_free(asn1p_value_t *); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 69 | asn1p_value_t *asn1p_value_fromref(asn1p_ref_t *ref, int do_copy); |
Lev Walkin | 5045dfa | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 70 | asn1p_value_t *asn1p_value_fromconstr(struct asn1p_constraint_s *ct, int dc); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 71 | asn1p_value_t *asn1p_value_frombits(uint8_t *bits, int size_in_bits, int dc); |
| 72 | asn1p_value_t *asn1p_value_frombuf(char *buffer, int size, int do_copy); |
| 73 | asn1p_value_t *asn1p_value_fromdouble(double); |
Lev Walkin | d21c505 | 2004-09-29 13:18:09 +0000 | [diff] [blame] | 74 | asn1p_value_t *asn1p_value_fromint(asn1c_integer_t); |
Lev Walkin | a9532f4 | 2006-09-17 04:52:50 +0000 | [diff] [blame] | 75 | asn1p_value_t *asn1p_value_fromtype(struct asn1p_expr_s *); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 76 | asn1p_value_t *asn1p_value_clone(asn1p_value_t *); |
Lev Walkin | a00d6b3 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 77 | asn1p_value_t *asn1p_value_clone_with_resolver(asn1p_value_t *, |
| 78 | asn1p_value_t *(*resolver)(asn1p_value_t *, void *rarg), |
| 79 | void *rarg); |
Lev Walkin | ea6635b | 2017-08-06 23:23:04 -0700 | [diff] [blame] | 80 | int asn1p_value_compare(const asn1p_value_t *, const asn1p_value_t *); |
| 81 | void asn1p_value_set_source(asn1p_value_t *, struct asn1p_module_s *, int line); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 82 | |
| 83 | #endif /* ASN1_PARSER_VALUE_H */ |