- leak detective is usable, but does not show static function names
[strongswan.git] / Source / lib / asn1 / asn1.h
1 /**
2 * @file asn1.h
3 *
4 * @brief Definition of asn1_rule_t and other ASN1 stuff.
5 *
6 */
7
8 /*
9 * Copyright (C) 2006 Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 */
22
23 #ifndef ASN1_H_
24 #define ASN1_H_
25
26 #include <types.h>
27
28 typedef enum asn1_type_t asn1_type_t;
29
30 /**
31 * @brief Real and some special ASN1 types.
32 *
33 * @ingroup asn1
34 */
35 enum asn1_type_t {
36 /**
37 * End of a sequence, set, choice
38 */
39 ASN1_END = 0x00,
40 ASN1_BOOLEAN = 0x01,
41 ASN1_INTEGER = 0x02,
42 ASN1_BITSTRING = 0x03,
43 ASN1_OCTETSTRING = 0x04,
44 ASN1_NULL = 0x05,
45 ASN1_OID = 0x06,
46 ASN1_ENUMERATED = 0x0A,
47 ASN1_UTF8STRING = 0x0C,
48 ASN1_NUMERICSTRING = 0x12,
49 ASN1_PRINTABLESTRING = 0x13,
50 ASN1_T61STRING = 0x14,
51 ASN1_VIDEOTEXSTRING = 0x15,
52 ASN1_IA5STRING = 0x16,
53 ASN1_UTCTIME = 0x17,
54 ASN1_GENERALIZEDTIME = 0x18,
55 ASN1_GRAPHICSTRING = 0x19,
56 ASN1_VISIBLESTRING = 0x1A,
57 ASN1_GENERALSTRING = 0x1B,
58 ASN1_UNIVERSALSTRING = 0x1C,
59 ASN1_BMPSTRING = 0x1E,
60 ASN1_CONSTRUCTED = 0x20,
61 ASN1_SEQUENCE = 0x30,
62 ASN1_SET = 0x31,
63 /**
64 * EXCPLICIT tags
65 */
66 ASN1_TAG_E_0 = 0xA0,
67 ASN1_TAG_E_1 = 0xA1,
68 ASN1_TAG_E_2 = 0xA2,
69 ASN1_TAG_E_3 = 0xA3,
70 ASN1_TAG_E_4 = 0xA4,
71 ASN1_TAG_E_5 = 0xA5,
72 ASN1_TAG_E_6 = 0xA6,
73 ASN1_TAG_E_7 = 0xA7,
74 /**
75 * IMPLICIT tags
76 */
77 ASN1_TAG_I_0 = 0x80,
78 ASN1_TAG_I_1 = 0x81,
79 ASN1_TAG_I_2 = 0x82,
80 ASN1_TAG_I_3 = 0x83,
81 ASN1_TAG_I_4 = 0x84,
82 ASN1_TAG_I_5 = 0x85,
83 ASN1_TAG_I_6 = 0x86,
84 ASN1_TAG_I_7 = 0x87,
85 /**
86 * Begin of a choice
87 */
88 ASN1_CHOICE = 0xFE,
89 /**
90 * ANY type
91 */
92 ASN1_ANY = 0xFF,
93 };
94
95 /**
96 * String mappings for asn1_type_t
97 */
98 extern mapping_t asn1_type_m[];
99
100
101 typedef enum asn1_flag_t asn1_flag_t;
102
103 /**
104 * @brief Flags used to build ASN1 rules.
105 *
106 * @ingroup asn1
107 */
108 enum asn1_flag_t {
109 /**
110 * Field is optional
111 */
112 ASN1_OPTIONAL = 0x01,
113 /**
114 * Field has a default value and is therefore optional
115 */
116 ASN1_DEFAULT = 0x02,
117 /**
118 * Convert this INTEGER to an mpz_t
119 */
120 ASN1_MPZ = 0x04,
121 /**
122 * SEQUENCE or SET OF
123 */
124 ASN1_OF = 0x08,
125 /**
126 * Parse this Sequence in a RAW chunk too.
127 * Used for crypto calculations...
128 */
129 ASN1_RAW = 0x10,
130 };
131
132 /**
133 * String mappings for asn1_flag_t
134 */
135 extern mapping_t asn1_flag_m[];
136
137
138 typedef struct asn1_rule_t asn1_rule_t;
139
140 /**
141 * @brief Single rule of a complet ruleset.
142 *
143 * This rule containing a type, flags and additional
144 * data allow modellation of complex ASN1 structures and
145 * allow their en- and decoding...
146 *
147 * @ingroup asn1
148 */
149 struct asn1_rule_t {
150 /**
151 * ASN1 type
152 */
153 asn1_type_t type;
154 /**
155 * implicit or explicit tag, if any
156 */
157 asn1_flag_t flags;
158 /**
159 * offset of data in structure
160 */
161 u_int data_offset;
162 /**
163 * offset to a boolean, which says if optional
164 * data is available at data_offset. Used if
165 * flags & ASN1_OPTIONAL.
166 * default value, used if flags & ASN1_DEFAULT
167 */
168 u_int additional;
169 };
170
171
172 #endif /* ASN1_H_ */