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