blob: c260c27e300bb4b044e45a136f3246e658917bc0 [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
Lev Walkin5045dfa2006-03-21 09:41:28 +00007struct asn1p_constraint_s; /* Forward declaration */
Lev Walkina9532f42006-09-17 04:52:50 +00008struct asn1p_expr_s;
Lev Walkin5045dfa2006-03-21 09:41:28 +00009
Lev Walkinf15320b2004-06-03 03:38:44 +000010/*
11 * A wrapper around various kinds of values.
12 */
13typedef struct asn1p_value_s {
14 /*
15 * The value of the element.
16 */
17 enum {
18 ATV_NOVALUE,
Lev Walkina9532f42006-09-17 04:52:50 +000019 ATV_TYPE, /* A type (as in CONTAINING Type) */
Lev Walkin9c974182004-09-15 11:59:51 +000020 ATV_NULL, /* A "NULL" value of type NULL. */
21 ATV_REAL, /* A constant floating-point value */
22 ATV_INTEGER, /* An integer constant */
Lev Walkinf15320b2004-06-03 03:38:44 +000023 ATV_MAX,
Lev Walkinceb20e72004-09-05 10:40:41 +000024 ATV_MIN,
Lev Walkinf15320b2004-06-03 03:38:44 +000025 ATV_TRUE,
Lev Walkinceb20e72004-09-05 10:40:41 +000026 ATV_FALSE,
Lev Walkin1e448d32005-03-24 14:26:38 +000027 ATV_TUPLE, /* { 1, 15 } */
28 ATV_QUADRUPLE, /* { 0, 14, 0, 255 } */
29 ATV_STRING, /* "abcdef" */
Lev Walkinf15320b2004-06-03 03:38:44 +000030 ATV_UNPARSED,
31 ATV_BITVECTOR,
Lev Walkin5045dfa2006-03-21 09:41:28 +000032 ATV_VALUESET, /* { 1 | 2 | 3 } */
Lev Walkin9c974182004-09-15 11:59:51 +000033 ATV_REFERENCED, /* Reference to a value defined elsewhere */
34 ATV_CHOICE_IDENTIFIER, /* ChoiceIdentifier value */
Lev Walkinf15320b2004-06-03 03:38:44 +000035 } type; /* Value type and location */
36
37 union {
Lev Walkin5045dfa2006-03-21 09:41:28 +000038 struct asn1p_constraint_s *constraint; /* ValueSet */
Lev Walkina9532f42006-09-17 04:52:50 +000039 struct asn1p_expr_s *v_type; /* Type */
Lev Walkinf15320b2004-06-03 03:38:44 +000040 asn1p_ref_t *reference;
Lev Walkind21c5052004-09-29 13:18:09 +000041 asn1c_integer_t v_integer;
Lev Walkinf15320b2004-06-03 03:38:44 +000042 double v_double;
43 /*
44 * Binary bits vector.
45 */
46 struct {
47 uint8_t *buf;
48 int size;
49 } string;
50 struct {
51 uint8_t *bits;
52 int size_in_bits;
53 } binary_vector;
Lev Walkin9c974182004-09-15 11:59:51 +000054 struct {
55 char *identifier;
56 struct asn1p_value_s *value;
57 } choice_identifier;
Lev Walkinf15320b2004-06-03 03:38:44 +000058 } value;
59} asn1p_value_t;
60
61/*
Lev Walkina00d6b32006-03-21 03:40:38 +000062 * Destructor and constructors for value.
Lev Walkinf15320b2004-06-03 03:38:44 +000063 * If ref, bits or buffer are omitted, the corresponding function returns
64 * (asn1p_value_t *)0 with errno = EINVAL.
65 * Allocated value (where applicable) is guaranteed to be NUL-terminated.
66 */
Lev Walkina00d6b32006-03-21 03:40:38 +000067void asn1p_value_free(asn1p_value_t *);
Lev Walkinf15320b2004-06-03 03:38:44 +000068asn1p_value_t *asn1p_value_fromref(asn1p_ref_t *ref, int do_copy);
Lev Walkin5045dfa2006-03-21 09:41:28 +000069asn1p_value_t *asn1p_value_fromconstr(struct asn1p_constraint_s *ct, int dc);
Lev Walkinf15320b2004-06-03 03:38:44 +000070asn1p_value_t *asn1p_value_frombits(uint8_t *bits, int size_in_bits, int dc);
71asn1p_value_t *asn1p_value_frombuf(char *buffer, int size, int do_copy);
72asn1p_value_t *asn1p_value_fromdouble(double);
Lev Walkind21c5052004-09-29 13:18:09 +000073asn1p_value_t *asn1p_value_fromint(asn1c_integer_t);
Lev Walkina9532f42006-09-17 04:52:50 +000074asn1p_value_t *asn1p_value_fromtype(struct asn1p_expr_s *);
Lev Walkinf15320b2004-06-03 03:38:44 +000075asn1p_value_t *asn1p_value_clone(asn1p_value_t *);
Lev Walkina00d6b32006-03-21 03:40:38 +000076asn1p_value_t *asn1p_value_clone_with_resolver(asn1p_value_t *,
77 asn1p_value_t *(*resolver)(asn1p_value_t *, void *rarg),
78 void *rarg);
Lev Walkinf15320b2004-06-03 03:38:44 +000079
80#endif /* ASN1_PARSER_VALUE_H */