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 | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 23 | ATV_STRING, |
| 24 | ATV_UNPARSED, |
| 25 | ATV_BITVECTOR, |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 26 | ATV_REFERENCED, /* Reference to a value defined elsewhere */ |
| 27 | ATV_CHOICE_IDENTIFIER, /* ChoiceIdentifier value */ |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 28 | } type; /* Value type and location */ |
| 29 | |
| 30 | union { |
| 31 | asn1p_ref_t *reference; |
| 32 | asn1_integer_t v_integer; |
| 33 | double v_double; |
| 34 | /* |
| 35 | * Binary bits vector. |
| 36 | */ |
| 37 | struct { |
| 38 | uint8_t *buf; |
| 39 | int size; |
| 40 | } string; |
| 41 | struct { |
| 42 | uint8_t *bits; |
| 43 | int size_in_bits; |
| 44 | } binary_vector; |
vlm | c94e28f | 2004-09-15 11:59:51 +0000 | [diff] [blame] | 45 | struct { |
| 46 | char *identifier; |
| 47 | struct asn1p_value_s *value; |
| 48 | } choice_identifier; |
vlm | fa67ddc | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 49 | } value; |
| 50 | } asn1p_value_t; |
| 51 | |
| 52 | /* |
| 53 | * Constructors and destructor for value. |
| 54 | * If ref, bits or buffer are omitted, the corresponding function returns |
| 55 | * (asn1p_value_t *)0 with errno = EINVAL. |
| 56 | * Allocated value (where applicable) is guaranteed to be NUL-terminated. |
| 57 | */ |
| 58 | asn1p_value_t *asn1p_value_fromref(asn1p_ref_t *ref, int do_copy); |
| 59 | asn1p_value_t *asn1p_value_frombits(uint8_t *bits, int size_in_bits, int dc); |
| 60 | asn1p_value_t *asn1p_value_frombuf(char *buffer, int size, int do_copy); |
| 61 | asn1p_value_t *asn1p_value_fromdouble(double); |
| 62 | asn1p_value_t *asn1p_value_fromint(asn1_integer_t); |
| 63 | asn1p_value_t *asn1p_value_clone(asn1p_value_t *); |
| 64 | void asn1p_value_free(asn1p_value_t *); |
| 65 | |
| 66 | #endif /* ASN1_PARSER_VALUE_H */ |