blob: a0103413fad3ac2c1236f2fe2e0fba4005f85921 [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
7/*
8 * A wrapper around various kinds of values.
9 */
10typedef struct asn1p_value_s {
11 /*
12 * The value of the element.
13 */
14 enum {
15 ATV_NOVALUE,
Lev Walkin9c974182004-09-15 11:59:51 +000016 ATV_NULL, /* A "NULL" value of type NULL. */
17 ATV_REAL, /* A constant floating-point value */
18 ATV_INTEGER, /* An integer constant */
Lev Walkinf15320b2004-06-03 03:38:44 +000019 ATV_MAX,
Lev Walkinceb20e72004-09-05 10:40:41 +000020 ATV_MIN,
Lev Walkinf15320b2004-06-03 03:38:44 +000021 ATV_TRUE,
Lev Walkinceb20e72004-09-05 10:40:41 +000022 ATV_FALSE,
Lev Walkin1e448d32005-03-24 14:26:38 +000023 ATV_TUPLE, /* { 1, 15 } */
24 ATV_QUADRUPLE, /* { 0, 14, 0, 255 } */
25 ATV_STRING, /* "abcdef" */
Lev Walkinf15320b2004-06-03 03:38:44 +000026 ATV_UNPARSED,
27 ATV_BITVECTOR,
Lev Walkin9c974182004-09-15 11:59:51 +000028 ATV_REFERENCED, /* Reference to a value defined elsewhere */
29 ATV_CHOICE_IDENTIFIER, /* ChoiceIdentifier value */
Lev Walkinf15320b2004-06-03 03:38:44 +000030 } type; /* Value type and location */
31
32 union {
33 asn1p_ref_t *reference;
Lev Walkind21c5052004-09-29 13:18:09 +000034 asn1c_integer_t v_integer;
Lev Walkinf15320b2004-06-03 03:38:44 +000035 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;
Lev Walkin9c974182004-09-15 11:59:51 +000047 struct {
48 char *identifier;
49 struct asn1p_value_s *value;
50 } choice_identifier;
Lev Walkinf15320b2004-06-03 03:38:44 +000051 } 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 */
60asn1p_value_t *asn1p_value_fromref(asn1p_ref_t *ref, int do_copy);
61asn1p_value_t *asn1p_value_frombits(uint8_t *bits, int size_in_bits, int dc);
62asn1p_value_t *asn1p_value_frombuf(char *buffer, int size, int do_copy);
63asn1p_value_t *asn1p_value_fromdouble(double);
Lev Walkind21c5052004-09-29 13:18:09 +000064asn1p_value_t *asn1p_value_fromint(asn1c_integer_t);
Lev Walkinf15320b2004-06-03 03:38:44 +000065asn1p_value_t *asn1p_value_clone(asn1p_value_t *);
66void asn1p_value_free(asn1p_value_t *);
67
68#endif /* ASN1_PARSER_VALUE_H */