vlm | fa67ddc | 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 | |
vlm | dfbff8c | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 7 | struct asn1p_constraint_s; /* Forward declaration */ |
| 8 | |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 9 | /* |
| 10 | * A wrapper around various kinds of values. |
| 11 | */ |
| 12 | typedef struct asn1p_value_s { |
| 13 | /* |
| 14 | * The value of the element. |
| 15 | */ |
| 16 | enum { |
| 17 | ATV_NOVALUE, |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 18 | ATV_NULL, /* A "NULL" value of type NULL. */ |
| 19 | ATV_REAL, /* A constant floating-point value */ |
| 20 | ATV_INTEGER, /* An integer constant */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 21 | ATV_MAX, |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 22 | ATV_MIN, |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 23 | ATV_TRUE, |
vlm | 39e5ed7 | 2004-09-05 10:40:41 +0000 | [diff] [blame] | 24 | ATV_FALSE, |
vlm | e1e6ed8 | 2005-03-24 14:26:38 +0000 | [diff] [blame] | 25 | ATV_TUPLE, /* { 1, 15 } */ |
| 26 | ATV_QUADRUPLE, /* { 0, 14, 0, 255 } */ |
| 27 | ATV_STRING, /* "abcdef" */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 28 | ATV_UNPARSED, |
| 29 | ATV_BITVECTOR, |
vlm | dfbff8c | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 30 | ATV_VALUESET, /* { 1 | 2 | 3 } */ |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 31 | ATV_REFERENCED, /* Reference to a value defined elsewhere */ |
| 32 | ATV_CHOICE_IDENTIFIER, /* ChoiceIdentifier value */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 33 | } type; /* Value type and location */ |
| 34 | |
| 35 | union { |
vlm | dfbff8c | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 36 | struct asn1p_constraint_s *constraint; /* ValueSet */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 37 | asn1p_ref_t *reference; |
vlm | ec6acd4 | 2004-09-29 13:18:09 +0000 | [diff] [blame] | 38 | asn1c_integer_t v_integer; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 39 | double v_double; |
| 40 | /* |
| 41 | * Binary bits vector. |
| 42 | */ |
| 43 | struct { |
| 44 | uint8_t *buf; |
| 45 | int size; |
| 46 | } string; |
| 47 | struct { |
| 48 | uint8_t *bits; |
| 49 | int size_in_bits; |
| 50 | } binary_vector; |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 51 | struct { |
| 52 | char *identifier; |
| 53 | struct asn1p_value_s *value; |
| 54 | } choice_identifier; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 55 | } value; |
| 56 | } asn1p_value_t; |
| 57 | |
| 58 | /* |
vlm | 0c6d381 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 59 | * Destructor and constructors for value. |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 60 | * If ref, bits or buffer are omitted, the corresponding function returns |
| 61 | * (asn1p_value_t *)0 with errno = EINVAL. |
| 62 | * Allocated value (where applicable) is guaranteed to be NUL-terminated. |
| 63 | */ |
vlm | 0c6d381 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 64 | void asn1p_value_free(asn1p_value_t *); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 65 | asn1p_value_t *asn1p_value_fromref(asn1p_ref_t *ref, int do_copy); |
vlm | dfbff8c | 2006-03-21 09:41:28 +0000 | [diff] [blame] | 66 | asn1p_value_t *asn1p_value_fromconstr(struct asn1p_constraint_s *ct, int dc); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 67 | asn1p_value_t *asn1p_value_frombits(uint8_t *bits, int size_in_bits, int dc); |
| 68 | asn1p_value_t *asn1p_value_frombuf(char *buffer, int size, int do_copy); |
| 69 | asn1p_value_t *asn1p_value_fromdouble(double); |
vlm | ec6acd4 | 2004-09-29 13:18:09 +0000 | [diff] [blame] | 70 | asn1p_value_t *asn1p_value_fromint(asn1c_integer_t); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 71 | asn1p_value_t *asn1p_value_clone(asn1p_value_t *); |
vlm | 0c6d381 | 2006-03-21 03:40:38 +0000 | [diff] [blame] | 72 | asn1p_value_t *asn1p_value_clone_with_resolver(asn1p_value_t *, |
| 73 | asn1p_value_t *(*resolver)(asn1p_value_t *, void *rarg), |
| 74 | void *rarg); |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 75 | |
| 76 | #endif /* ASN1_PARSER_VALUE_H */ |