williamr@2
|
1 |
/* asn1t.h */
|
williamr@2
|
2 |
/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
|
williamr@2
|
3 |
* project 2000.
|
williamr@2
|
4 |
*/
|
williamr@2
|
5 |
/* ====================================================================
|
williamr@2
|
6 |
* Copyright (c) 2000 The OpenSSL Project. All rights reserved.
|
williamr@2
|
7 |
*
|
williamr@2
|
8 |
* Redistribution and use in source and binary forms, with or without
|
williamr@2
|
9 |
* modification, are permitted provided that the following conditions
|
williamr@2
|
10 |
* are met:
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* 1. Redistributions of source code must retain the above copyright
|
williamr@2
|
13 |
* notice, this list of conditions and the following disclaimer.
|
williamr@2
|
14 |
*
|
williamr@2
|
15 |
* 2. Redistributions in binary form must reproduce the above copyright
|
williamr@2
|
16 |
* notice, this list of conditions and the following disclaimer in
|
williamr@2
|
17 |
* the documentation and/or other materials provided with the
|
williamr@2
|
18 |
* distribution.
|
williamr@2
|
19 |
*
|
williamr@2
|
20 |
* 3. All advertising materials mentioning features or use of this
|
williamr@2
|
21 |
* software must display the following acknowledgment:
|
williamr@2
|
22 |
* "This product includes software developed by the OpenSSL Project
|
williamr@2
|
23 |
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
williamr@2
|
24 |
*
|
williamr@2
|
25 |
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
williamr@2
|
26 |
* endorse or promote products derived from this software without
|
williamr@2
|
27 |
* prior written permission. For written permission, please contact
|
williamr@2
|
28 |
* licensing@OpenSSL.org.
|
williamr@2
|
29 |
*
|
williamr@2
|
30 |
* 5. Products derived from this software may not be called "OpenSSL"
|
williamr@2
|
31 |
* nor may "OpenSSL" appear in their names without prior written
|
williamr@2
|
32 |
* permission of the OpenSSL Project.
|
williamr@2
|
33 |
*
|
williamr@2
|
34 |
* 6. Redistributions of any form whatsoever must retain the following
|
williamr@2
|
35 |
* acknowledgment:
|
williamr@2
|
36 |
* "This product includes software developed by the OpenSSL Project
|
williamr@2
|
37 |
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
williamr@2
|
38 |
*
|
williamr@2
|
39 |
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
williamr@2
|
40 |
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
williamr@2
|
41 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
williamr@2
|
42 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
williamr@2
|
43 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
williamr@2
|
44 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
williamr@2
|
45 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
williamr@2
|
46 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
williamr@2
|
47 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
williamr@2
|
48 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
williamr@2
|
49 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
williamr@2
|
50 |
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
williamr@2
|
51 |
* ====================================================================
|
williamr@2
|
52 |
*
|
williamr@2
|
53 |
* This product includes cryptographic software written by Eric Young
|
williamr@2
|
54 |
* (eay@cryptsoft.com). This product includes software written by Tim
|
williamr@2
|
55 |
* Hudson (tjh@cryptsoft.com).
|
williamr@2
|
56 |
*
|
williamr@2
|
57 |
*/
|
williamr@2
|
58 |
#ifndef HEADER_ASN1T_H
|
williamr@2
|
59 |
#define HEADER_ASN1T_H
|
williamr@2
|
60 |
|
williamr@2
|
61 |
#include <stddef.h>
|
williamr@2
|
62 |
#include <openssl/e_os2.h>
|
williamr@2
|
63 |
#include <openssl/asn1.h>
|
williamr@2
|
64 |
|
williamr@2
|
65 |
#ifdef OPENSSL_BUILD_SHLIBCRYPTO
|
williamr@2
|
66 |
# undef OPENSSL_EXTERN
|
williamr@2
|
67 |
# define OPENSSL_EXTERN OPENSSL_EXPORT
|
williamr@2
|
68 |
#endif
|
williamr@2
|
69 |
|
williamr@2
|
70 |
/* ASN1 template defines, structures and functions */
|
williamr@2
|
71 |
|
williamr@2
|
72 |
#ifdef __cplusplus
|
williamr@2
|
73 |
extern "C" {
|
williamr@2
|
74 |
#endif
|
williamr@2
|
75 |
|
williamr@2
|
76 |
|
williamr@2
|
77 |
#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
|
williamr@2
|
78 |
|
williamr@2
|
79 |
/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
|
williamr@2
|
80 |
#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))
|
williamr@2
|
81 |
|
williamr@2
|
82 |
|
williamr@2
|
83 |
/* Macros for start and end of ASN1_ITEM definition */
|
williamr@2
|
84 |
|
williamr@2
|
85 |
#define ASN1_ITEM_start(itname) \
|
williamr@2
|
86 |
OPENSSL_GLOBAL const ASN1_ITEM itname##_it = {
|
williamr@2
|
87 |
|
williamr@2
|
88 |
#define ASN1_ITEM_end(itname) \
|
williamr@2
|
89 |
};
|
williamr@2
|
90 |
|
williamr@2
|
91 |
#else
|
williamr@2
|
92 |
|
williamr@2
|
93 |
/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
|
williamr@2
|
94 |
#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr()))
|
williamr@2
|
95 |
|
williamr@2
|
96 |
|
williamr@2
|
97 |
/* Macros for start and end of ASN1_ITEM definition */
|
williamr@2
|
98 |
|
williamr@2
|
99 |
#define ASN1_ITEM_start(itname) \
|
williamr@2
|
100 |
EXPORT_C const ASN1_ITEM * itname##_it(void) \
|
williamr@2
|
101 |
{ \
|
williamr@2
|
102 |
static const ASN1_ITEM local_it = {
|
williamr@2
|
103 |
|
williamr@2
|
104 |
#define ASN1_ITEM_end(itname) \
|
williamr@2
|
105 |
}; \
|
williamr@2
|
106 |
return &local_it; \
|
williamr@2
|
107 |
}
|
williamr@2
|
108 |
|
williamr@2
|
109 |
#endif
|
williamr@2
|
110 |
|
williamr@2
|
111 |
|
williamr@2
|
112 |
/* Macros to aid ASN1 template writing */
|
williamr@2
|
113 |
|
williamr@2
|
114 |
#define ASN1_ITEM_TEMPLATE(tname) \
|
williamr@2
|
115 |
static const ASN1_TEMPLATE tname##_item_tt
|
williamr@2
|
116 |
|
williamr@2
|
117 |
#define ASN1_ITEM_TEMPLATE_END(tname) \
|
williamr@2
|
118 |
;\
|
williamr@2
|
119 |
ASN1_ITEM_start(tname) \
|
williamr@2
|
120 |
ASN1_ITYPE_PRIMITIVE,\
|
williamr@2
|
121 |
-1,\
|
williamr@2
|
122 |
&tname##_item_tt,\
|
williamr@2
|
123 |
0,\
|
williamr@2
|
124 |
NULL,\
|
williamr@2
|
125 |
0,\
|
williamr@2
|
126 |
#tname \
|
williamr@2
|
127 |
ASN1_ITEM_end(tname)
|
williamr@2
|
128 |
|
williamr@2
|
129 |
|
williamr@2
|
130 |
/* This is a ASN1 type which just embeds a template */
|
williamr@2
|
131 |
|
williamr@2
|
132 |
/* This pair helps declare a SEQUENCE. We can do:
|
williamr@2
|
133 |
*
|
williamr@2
|
134 |
* ASN1_SEQUENCE(stname) = {
|
williamr@2
|
135 |
* ... SEQUENCE components ...
|
williamr@2
|
136 |
* } ASN1_SEQUENCE_END(stname)
|
williamr@2
|
137 |
*
|
williamr@2
|
138 |
* This will produce an ASN1_ITEM called stname_it
|
williamr@2
|
139 |
* for a structure called stname.
|
williamr@2
|
140 |
*
|
williamr@2
|
141 |
* If you want the same structure but a different
|
williamr@2
|
142 |
* name then use:
|
williamr@2
|
143 |
*
|
williamr@2
|
144 |
* ASN1_SEQUENCE(itname) = {
|
williamr@2
|
145 |
* ... SEQUENCE components ...
|
williamr@2
|
146 |
* } ASN1_SEQUENCE_END_name(stname, itname)
|
williamr@2
|
147 |
*
|
williamr@2
|
148 |
* This will create an item called itname_it using
|
williamr@2
|
149 |
* a structure called stname.
|
williamr@2
|
150 |
*/
|
williamr@2
|
151 |
|
williamr@2
|
152 |
#define ASN1_SEQUENCE(tname) \
|
williamr@2
|
153 |
static const ASN1_TEMPLATE tname##_seq_tt[]
|
williamr@2
|
154 |
|
williamr@2
|
155 |
#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
|
williamr@2
|
156 |
|
williamr@2
|
157 |
#define ASN1_SEQUENCE_END_name(stname, tname) \
|
williamr@2
|
158 |
;\
|
williamr@2
|
159 |
ASN1_ITEM_start(tname) \
|
williamr@2
|
160 |
ASN1_ITYPE_SEQUENCE,\
|
williamr@2
|
161 |
V_ASN1_SEQUENCE,\
|
williamr@2
|
162 |
tname##_seq_tt,\
|
williamr@2
|
163 |
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
williamr@2
|
164 |
NULL,\
|
williamr@2
|
165 |
sizeof(stname),\
|
williamr@2
|
166 |
#stname \
|
williamr@2
|
167 |
ASN1_ITEM_end(tname)
|
williamr@2
|
168 |
|
williamr@2
|
169 |
#define ASN1_NDEF_SEQUENCE(tname) \
|
williamr@2
|
170 |
ASN1_SEQUENCE(tname)
|
williamr@2
|
171 |
|
williamr@2
|
172 |
#define ASN1_SEQUENCE_cb(tname, cb) \
|
williamr@2
|
173 |
static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
|
williamr@2
|
174 |
ASN1_SEQUENCE(tname)
|
williamr@2
|
175 |
|
williamr@2
|
176 |
#define ASN1_BROKEN_SEQUENCE(tname) \
|
williamr@2
|
177 |
static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \
|
williamr@2
|
178 |
ASN1_SEQUENCE(tname)
|
williamr@2
|
179 |
|
williamr@2
|
180 |
#define ASN1_SEQUENCE_ref(tname, cb, lck) \
|
williamr@2
|
181 |
static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \
|
williamr@2
|
182 |
ASN1_SEQUENCE(tname)
|
williamr@2
|
183 |
|
williamr@2
|
184 |
#define ASN1_SEQUENCE_enc(tname, enc, cb) \
|
williamr@2
|
185 |
static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \
|
williamr@2
|
186 |
ASN1_SEQUENCE(tname)
|
williamr@2
|
187 |
|
williamr@2
|
188 |
#define ASN1_NDEF_SEQUENCE_END(tname) \
|
williamr@2
|
189 |
;\
|
williamr@2
|
190 |
ASN1_ITEM_start(tname) \
|
williamr@2
|
191 |
ASN1_ITYPE_NDEF_SEQUENCE,\
|
williamr@2
|
192 |
V_ASN1_SEQUENCE,\
|
williamr@2
|
193 |
tname##_seq_tt,\
|
williamr@2
|
194 |
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
williamr@2
|
195 |
NULL,\
|
williamr@2
|
196 |
sizeof(tname),\
|
williamr@2
|
197 |
#tname \
|
williamr@2
|
198 |
ASN1_ITEM_end(tname)
|
williamr@2
|
199 |
|
williamr@2
|
200 |
#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)
|
williamr@2
|
201 |
|
williamr@2
|
202 |
#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
|
williamr@2
|
203 |
|
williamr@2
|
204 |
#define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
|
williamr@2
|
205 |
|
williamr@2
|
206 |
#define ASN1_SEQUENCE_END_ref(stname, tname) \
|
williamr@2
|
207 |
;\
|
williamr@2
|
208 |
ASN1_ITEM_start(tname) \
|
williamr@2
|
209 |
ASN1_ITYPE_SEQUENCE,\
|
williamr@2
|
210 |
V_ASN1_SEQUENCE,\
|
williamr@2
|
211 |
tname##_seq_tt,\
|
williamr@2
|
212 |
sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
|
williamr@2
|
213 |
&tname##_aux,\
|
williamr@2
|
214 |
sizeof(stname),\
|
williamr@2
|
215 |
#stname \
|
williamr@2
|
216 |
ASN1_ITEM_end(tname)
|
williamr@2
|
217 |
|
williamr@2
|
218 |
|
williamr@2
|
219 |
/* This pair helps declare a CHOICE type. We can do:
|
williamr@2
|
220 |
*
|
williamr@2
|
221 |
* ASN1_CHOICE(chname) = {
|
williamr@2
|
222 |
* ... CHOICE options ...
|
williamr@2
|
223 |
* ASN1_CHOICE_END(chname)
|
williamr@2
|
224 |
*
|
williamr@2
|
225 |
* This will produce an ASN1_ITEM called chname_it
|
williamr@2
|
226 |
* for a structure called chname. The structure
|
williamr@2
|
227 |
* definition must look like this:
|
williamr@2
|
228 |
* typedef struct {
|
williamr@2
|
229 |
* int type;
|
williamr@2
|
230 |
* union {
|
williamr@2
|
231 |
* ASN1_SOMETHING *opt1;
|
williamr@2
|
232 |
* ASN1_SOMEOTHER *opt2;
|
williamr@2
|
233 |
* } value;
|
williamr@2
|
234 |
* } chname;
|
williamr@2
|
235 |
*
|
williamr@2
|
236 |
* the name of the selector must be 'type'.
|
williamr@2
|
237 |
* to use an alternative selector name use the
|
williamr@2
|
238 |
* ASN1_CHOICE_END_selector() version.
|
williamr@2
|
239 |
*/
|
williamr@2
|
240 |
|
williamr@2
|
241 |
#define ASN1_CHOICE(tname) \
|
williamr@2
|
242 |
static const ASN1_TEMPLATE tname##_ch_tt[]
|
williamr@2
|
243 |
|
williamr@2
|
244 |
#define ASN1_CHOICE_cb(tname, cb) \
|
williamr@2
|
245 |
static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
|
williamr@2
|
246 |
ASN1_CHOICE(tname)
|
williamr@2
|
247 |
|
williamr@2
|
248 |
#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
|
williamr@2
|
249 |
|
williamr@2
|
250 |
#define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)
|
williamr@2
|
251 |
|
williamr@2
|
252 |
#define ASN1_CHOICE_END_selector(stname, tname, selname) \
|
williamr@2
|
253 |
;\
|
williamr@2
|
254 |
ASN1_ITEM_start(tname) \
|
williamr@2
|
255 |
ASN1_ITYPE_CHOICE,\
|
williamr@2
|
256 |
offsetof(stname,selname) ,\
|
williamr@2
|
257 |
tname##_ch_tt,\
|
williamr@2
|
258 |
sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
|
williamr@2
|
259 |
NULL,\
|
williamr@2
|
260 |
sizeof(stname),\
|
williamr@2
|
261 |
#stname \
|
williamr@2
|
262 |
ASN1_ITEM_end(tname)
|
williamr@2
|
263 |
|
williamr@2
|
264 |
#define ASN1_CHOICE_END_cb(stname, tname, selname) \
|
williamr@2
|
265 |
;\
|
williamr@2
|
266 |
ASN1_ITEM_start(tname) \
|
williamr@2
|
267 |
ASN1_ITYPE_CHOICE,\
|
williamr@2
|
268 |
offsetof(stname,selname) ,\
|
williamr@2
|
269 |
tname##_ch_tt,\
|
williamr@2
|
270 |
sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
|
williamr@2
|
271 |
&tname##_aux,\
|
williamr@2
|
272 |
sizeof(stname),\
|
williamr@2
|
273 |
#stname \
|
williamr@2
|
274 |
ASN1_ITEM_end(tname)
|
williamr@2
|
275 |
|
williamr@2
|
276 |
/* This helps with the template wrapper form of ASN1_ITEM */
|
williamr@2
|
277 |
|
williamr@2
|
278 |
#define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \
|
williamr@2
|
279 |
(flags), (tag), 0,\
|
williamr@2
|
280 |
#name, ASN1_ITEM_ref(type) }
|
williamr@2
|
281 |
|
williamr@2
|
282 |
/* These help with SEQUENCE or CHOICE components */
|
williamr@2
|
283 |
|
williamr@2
|
284 |
/* used to declare other types */
|
williamr@2
|
285 |
|
williamr@2
|
286 |
#define ASN1_EX_TYPE(flags, tag, stname, field, type) { \
|
williamr@2
|
287 |
(flags), (tag), offsetof(stname, field),\
|
williamr@2
|
288 |
#field, ASN1_ITEM_ref(type) }
|
williamr@2
|
289 |
|
williamr@2
|
290 |
/* used when the structure is combined with the parent */
|
williamr@2
|
291 |
|
williamr@2
|
292 |
#define ASN1_EX_COMBINE(flags, tag, type) { \
|
williamr@2
|
293 |
(flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) }
|
williamr@2
|
294 |
|
williamr@2
|
295 |
/* implicit and explicit helper macros */
|
williamr@2
|
296 |
|
williamr@2
|
297 |
#define ASN1_IMP_EX(stname, field, type, tag, ex) \
|
williamr@2
|
298 |
ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)
|
williamr@2
|
299 |
|
williamr@2
|
300 |
#define ASN1_EXP_EX(stname, field, type, tag, ex) \
|
williamr@2
|
301 |
ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)
|
williamr@2
|
302 |
|
williamr@2
|
303 |
/* Any defined by macros: the field used is in the table itself */
|
williamr@2
|
304 |
|
williamr@2
|
305 |
#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
|
williamr@2
|
306 |
#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
|
williamr@2
|
307 |
#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
|
williamr@2
|
308 |
#else
|
williamr@2
|
309 |
#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb }
|
williamr@2
|
310 |
#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb }
|
williamr@2
|
311 |
#endif
|
williamr@2
|
312 |
/* Plain simple type */
|
williamr@2
|
313 |
#define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)
|
williamr@2
|
314 |
|
williamr@2
|
315 |
/* OPTIONAL simple type */
|
williamr@2
|
316 |
#define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)
|
williamr@2
|
317 |
|
williamr@2
|
318 |
/* IMPLICIT tagged simple type */
|
williamr@2
|
319 |
#define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)
|
williamr@2
|
320 |
|
williamr@2
|
321 |
/* IMPLICIT tagged OPTIONAL simple type */
|
williamr@2
|
322 |
#define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
|
williamr@2
|
323 |
|
williamr@2
|
324 |
/* Same as above but EXPLICIT */
|
williamr@2
|
325 |
|
williamr@2
|
326 |
#define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)
|
williamr@2
|
327 |
#define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
|
williamr@2
|
328 |
|
williamr@2
|
329 |
/* SEQUENCE OF type */
|
williamr@2
|
330 |
#define ASN1_SEQUENCE_OF(stname, field, type) \
|
williamr@2
|
331 |
ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)
|
williamr@2
|
332 |
|
williamr@2
|
333 |
/* OPTIONAL SEQUENCE OF */
|
williamr@2
|
334 |
#define ASN1_SEQUENCE_OF_OPT(stname, field, type) \
|
williamr@2
|
335 |
ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
|
williamr@2
|
336 |
|
williamr@2
|
337 |
/* Same as above but for SET OF */
|
williamr@2
|
338 |
|
williamr@2
|
339 |
#define ASN1_SET_OF(stname, field, type) \
|
williamr@2
|
340 |
ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)
|
williamr@2
|
341 |
|
williamr@2
|
342 |
#define ASN1_SET_OF_OPT(stname, field, type) \
|
williamr@2
|
343 |
ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
|
williamr@2
|
344 |
|
williamr@2
|
345 |
/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */
|
williamr@2
|
346 |
|
williamr@2
|
347 |
#define ASN1_IMP_SET_OF(stname, field, type, tag) \
|
williamr@2
|
348 |
ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
|
williamr@2
|
349 |
|
williamr@2
|
350 |
#define ASN1_EXP_SET_OF(stname, field, type, tag) \
|
williamr@2
|
351 |
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
|
williamr@2
|
352 |
|
williamr@2
|
353 |
#define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \
|
williamr@2
|
354 |
ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
|
williamr@2
|
355 |
|
williamr@2
|
356 |
#define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \
|
williamr@2
|
357 |
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
|
williamr@2
|
358 |
|
williamr@2
|
359 |
#define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \
|
williamr@2
|
360 |
ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
|
williamr@2
|
361 |
|
williamr@2
|
362 |
#define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \
|
williamr@2
|
363 |
ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
|
williamr@2
|
364 |
|
williamr@2
|
365 |
#define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \
|
williamr@2
|
366 |
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
|
williamr@2
|
367 |
|
williamr@2
|
368 |
#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
|
williamr@2
|
369 |
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
|
williamr@2
|
370 |
|
williamr@2
|
371 |
/* EXPLICIT OPTIONAL using indefinite length constructed form */
|
williamr@2
|
372 |
#define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \
|
williamr@2
|
373 |
ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF)
|
williamr@2
|
374 |
|
williamr@2
|
375 |
/* Macros for the ASN1_ADB structure */
|
williamr@2
|
376 |
|
williamr@2
|
377 |
#define ASN1_ADB(name) \
|
williamr@2
|
378 |
static const ASN1_ADB_TABLE name##_adbtbl[]
|
williamr@2
|
379 |
|
williamr@2
|
380 |
#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
|
williamr@2
|
381 |
|
williamr@2
|
382 |
#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
|
williamr@2
|
383 |
;\
|
williamr@2
|
384 |
static const ASN1_ADB name##_adb = {\
|
williamr@2
|
385 |
flags,\
|
williamr@2
|
386 |
offsetof(name, field),\
|
williamr@2
|
387 |
app_table,\
|
williamr@2
|
388 |
name##_adbtbl,\
|
williamr@2
|
389 |
sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
|
williamr@2
|
390 |
def,\
|
williamr@2
|
391 |
none\
|
williamr@2
|
392 |
}
|
williamr@2
|
393 |
|
williamr@2
|
394 |
#else
|
williamr@2
|
395 |
|
williamr@2
|
396 |
#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
|
williamr@2
|
397 |
;\
|
williamr@2
|
398 |
EXPORT_C static const ASN1_ITEM *name##_adb(void) \
|
williamr@2
|
399 |
{ \
|
williamr@2
|
400 |
static const ASN1_ADB internal_adb = \
|
williamr@2
|
401 |
{\
|
williamr@2
|
402 |
flags,\
|
williamr@2
|
403 |
offsetof(name, field),\
|
williamr@2
|
404 |
app_table,\
|
williamr@2
|
405 |
name##_adbtbl,\
|
williamr@2
|
406 |
sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
|
williamr@2
|
407 |
def,\
|
williamr@2
|
408 |
none\
|
williamr@2
|
409 |
}; \
|
williamr@2
|
410 |
return (const ASN1_ITEM *) &internal_adb; \
|
williamr@2
|
411 |
} \
|
williamr@2
|
412 |
void dummy_function(void)
|
williamr@2
|
413 |
|
williamr@2
|
414 |
#endif
|
williamr@2
|
415 |
|
williamr@2
|
416 |
#define ADB_ENTRY(val, template) {val, template}
|
williamr@2
|
417 |
|
williamr@2
|
418 |
#define ASN1_ADB_TEMPLATE(name) \
|
williamr@2
|
419 |
static const ASN1_TEMPLATE name##_tt
|
williamr@2
|
420 |
|
williamr@2
|
421 |
/* This is the ASN1 template structure that defines
|
williamr@2
|
422 |
* a wrapper round the actual type. It determines the
|
williamr@2
|
423 |
* actual position of the field in the value structure,
|
williamr@2
|
424 |
* various flags such as OPTIONAL and the field name.
|
williamr@2
|
425 |
*/
|
williamr@2
|
426 |
|
williamr@2
|
427 |
struct ASN1_TEMPLATE_st {
|
williamr@2
|
428 |
unsigned long flags; /* Various flags */
|
williamr@2
|
429 |
long tag; /* tag, not used if no tagging */
|
williamr@2
|
430 |
unsigned long offset; /* Offset of this field in structure */
|
williamr@2
|
431 |
#ifndef NO_ASN1_FIELD_NAMES
|
williamr@2
|
432 |
const char *field_name; /* Field name */
|
williamr@2
|
433 |
#endif
|
williamr@2
|
434 |
ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */
|
williamr@2
|
435 |
};
|
williamr@2
|
436 |
|
williamr@2
|
437 |
/* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */
|
williamr@2
|
438 |
|
williamr@2
|
439 |
#define ASN1_TEMPLATE_item(t) (t->item_ptr)
|
williamr@2
|
440 |
#define ASN1_TEMPLATE_adb(t) (t->item_ptr)
|
williamr@2
|
441 |
|
williamr@2
|
442 |
typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;
|
williamr@2
|
443 |
typedef struct ASN1_ADB_st ASN1_ADB;
|
williamr@2
|
444 |
|
williamr@2
|
445 |
struct ASN1_ADB_st {
|
williamr@2
|
446 |
unsigned long flags; /* Various flags */
|
williamr@2
|
447 |
unsigned long offset; /* Offset of selector field */
|
williamr@2
|
448 |
STACK_OF(ASN1_ADB_TABLE) **app_items; /* Application defined items */
|
williamr@2
|
449 |
const ASN1_ADB_TABLE *tbl; /* Table of possible types */
|
williamr@2
|
450 |
long tblcount; /* Number of entries in tbl */
|
williamr@2
|
451 |
const ASN1_TEMPLATE *default_tt; /* Type to use if no match */
|
williamr@2
|
452 |
const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */
|
williamr@2
|
453 |
};
|
williamr@2
|
454 |
|
williamr@2
|
455 |
struct ASN1_ADB_TABLE_st {
|
williamr@2
|
456 |
long value; /* NID for an object or value for an int */
|
williamr@2
|
457 |
const ASN1_TEMPLATE tt; /* item for this value */
|
williamr@2
|
458 |
};
|
williamr@2
|
459 |
|
williamr@2
|
460 |
/* template flags */
|
williamr@2
|
461 |
|
williamr@2
|
462 |
/* Field is optional */
|
williamr@2
|
463 |
#define ASN1_TFLG_OPTIONAL (0x1)
|
williamr@2
|
464 |
|
williamr@2
|
465 |
/* Field is a SET OF */
|
williamr@2
|
466 |
#define ASN1_TFLG_SET_OF (0x1 << 1)
|
williamr@2
|
467 |
|
williamr@2
|
468 |
/* Field is a SEQUENCE OF */
|
williamr@2
|
469 |
#define ASN1_TFLG_SEQUENCE_OF (0x2 << 1)
|
williamr@2
|
470 |
|
williamr@2
|
471 |
/* Special case: this refers to a SET OF that
|
williamr@2
|
472 |
* will be sorted into DER order when encoded *and*
|
williamr@2
|
473 |
* the corresponding STACK will be modified to match
|
williamr@2
|
474 |
* the new order.
|
williamr@2
|
475 |
*/
|
williamr@2
|
476 |
#define ASN1_TFLG_SET_ORDER (0x3 << 1)
|
williamr@2
|
477 |
|
williamr@2
|
478 |
/* Mask for SET OF or SEQUENCE OF */
|
williamr@2
|
479 |
#define ASN1_TFLG_SK_MASK (0x3 << 1)
|
williamr@2
|
480 |
|
williamr@2
|
481 |
/* These flags mean the tag should be taken from the
|
williamr@2
|
482 |
* tag field. If EXPLICIT then the underlying type
|
williamr@2
|
483 |
* is used for the inner tag.
|
williamr@2
|
484 |
*/
|
williamr@2
|
485 |
|
williamr@2
|
486 |
/* IMPLICIT tagging */
|
williamr@2
|
487 |
#define ASN1_TFLG_IMPTAG (0x1 << 3)
|
williamr@2
|
488 |
|
williamr@2
|
489 |
|
williamr@2
|
490 |
/* EXPLICIT tagging, inner tag from underlying type */
|
williamr@2
|
491 |
#define ASN1_TFLG_EXPTAG (0x2 << 3)
|
williamr@2
|
492 |
|
williamr@2
|
493 |
#define ASN1_TFLG_TAG_MASK (0x3 << 3)
|
williamr@2
|
494 |
|
williamr@2
|
495 |
/* context specific IMPLICIT */
|
williamr@2
|
496 |
#define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT
|
williamr@2
|
497 |
|
williamr@2
|
498 |
/* context specific EXPLICIT */
|
williamr@2
|
499 |
#define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT
|
williamr@2
|
500 |
|
williamr@2
|
501 |
/* If tagging is in force these determine the
|
williamr@2
|
502 |
* type of tag to use. Otherwise the tag is
|
williamr@2
|
503 |
* determined by the underlying type. These
|
williamr@2
|
504 |
* values reflect the actual octet format.
|
williamr@2
|
505 |
*/
|
williamr@2
|
506 |
|
williamr@2
|
507 |
/* Universal tag */
|
williamr@2
|
508 |
#define ASN1_TFLG_UNIVERSAL (0x0<<6)
|
williamr@2
|
509 |
/* Application tag */
|
williamr@2
|
510 |
#define ASN1_TFLG_APPLICATION (0x1<<6)
|
williamr@2
|
511 |
/* Context specific tag */
|
williamr@2
|
512 |
#define ASN1_TFLG_CONTEXT (0x2<<6)
|
williamr@2
|
513 |
/* Private tag */
|
williamr@2
|
514 |
#define ASN1_TFLG_PRIVATE (0x3<<6)
|
williamr@2
|
515 |
|
williamr@2
|
516 |
#define ASN1_TFLG_TAG_CLASS (0x3<<6)
|
williamr@2
|
517 |
|
williamr@2
|
518 |
/* These are for ANY DEFINED BY type. In this case
|
williamr@2
|
519 |
* the 'item' field points to an ASN1_ADB structure
|
williamr@2
|
520 |
* which contains a table of values to decode the
|
williamr@2
|
521 |
* relevant type
|
williamr@2
|
522 |
*/
|
williamr@2
|
523 |
|
williamr@2
|
524 |
#define ASN1_TFLG_ADB_MASK (0x3<<8)
|
williamr@2
|
525 |
|
williamr@2
|
526 |
#define ASN1_TFLG_ADB_OID (0x1<<8)
|
williamr@2
|
527 |
|
williamr@2
|
528 |
#define ASN1_TFLG_ADB_INT (0x1<<9)
|
williamr@2
|
529 |
|
williamr@2
|
530 |
/* This flag means a parent structure is passed
|
williamr@2
|
531 |
* instead of the field: this is useful is a
|
williamr@2
|
532 |
* SEQUENCE is being combined with a CHOICE for
|
williamr@2
|
533 |
* example. Since this means the structure and
|
williamr@2
|
534 |
* item name will differ we need to use the
|
williamr@2
|
535 |
* ASN1_CHOICE_END_name() macro for example.
|
williamr@2
|
536 |
*/
|
williamr@2
|
537 |
|
williamr@2
|
538 |
#define ASN1_TFLG_COMBINE (0x1<<10)
|
williamr@2
|
539 |
|
williamr@2
|
540 |
/* This flag when present in a SEQUENCE OF, SET OF
|
williamr@2
|
541 |
* or EXPLICIT causes indefinite length constructed
|
williamr@2
|
542 |
* encoding to be used if required.
|
williamr@2
|
543 |
*/
|
williamr@2
|
544 |
|
williamr@2
|
545 |
#define ASN1_TFLG_NDEF (0x1<<11)
|
williamr@2
|
546 |
|
williamr@2
|
547 |
/* This is the actual ASN1 item itself */
|
williamr@2
|
548 |
|
williamr@2
|
549 |
struct ASN1_ITEM_st {
|
williamr@2
|
550 |
char itype; /* The item type, primitive, SEQUENCE, CHOICE or extern */
|
williamr@2
|
551 |
long utype; /* underlying type */
|
williamr@2
|
552 |
const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains the contents */
|
williamr@2
|
553 |
long tcount; /* Number of templates if SEQUENCE or CHOICE */
|
williamr@2
|
554 |
const void *funcs; /* functions that handle this type */
|
williamr@2
|
555 |
long size; /* Structure size (usually)*/
|
williamr@2
|
556 |
#ifndef NO_ASN1_FIELD_NAMES
|
williamr@2
|
557 |
const char *sname; /* Structure name */
|
williamr@2
|
558 |
#endif
|
williamr@2
|
559 |
};
|
williamr@2
|
560 |
|
williamr@2
|
561 |
/* These are values for the itype field and
|
williamr@2
|
562 |
* determine how the type is interpreted.
|
williamr@2
|
563 |
*
|
williamr@2
|
564 |
* For PRIMITIVE types the underlying type
|
williamr@2
|
565 |
* determines the behaviour if items is NULL.
|
williamr@2
|
566 |
*
|
williamr@2
|
567 |
* Otherwise templates must contain a single
|
williamr@2
|
568 |
* template and the type is treated in the
|
williamr@2
|
569 |
* same way as the type specified in the template.
|
williamr@2
|
570 |
*
|
williamr@2
|
571 |
* For SEQUENCE types the templates field points
|
williamr@2
|
572 |
* to the members, the size field is the
|
williamr@2
|
573 |
* structure size.
|
williamr@2
|
574 |
*
|
williamr@2
|
575 |
* For CHOICE types the templates field points
|
williamr@2
|
576 |
* to each possible member (typically a union)
|
williamr@2
|
577 |
* and the 'size' field is the offset of the
|
williamr@2
|
578 |
* selector.
|
williamr@2
|
579 |
*
|
williamr@2
|
580 |
* The 'funcs' field is used for application
|
williamr@2
|
581 |
* specific functions.
|
williamr@2
|
582 |
*
|
williamr@2
|
583 |
* For COMPAT types the funcs field gives a
|
williamr@2
|
584 |
* set of functions that handle this type, this
|
williamr@2
|
585 |
* supports the old d2i, i2d convention.
|
williamr@2
|
586 |
*
|
williamr@2
|
587 |
* The EXTERN type uses a new style d2i/i2d.
|
williamr@2
|
588 |
* The new style should be used where possible
|
williamr@2
|
589 |
* because it avoids things like the d2i IMPLICIT
|
williamr@2
|
590 |
* hack.
|
williamr@2
|
591 |
*
|
williamr@2
|
592 |
* MSTRING is a multiple string type, it is used
|
williamr@2
|
593 |
* for a CHOICE of character strings where the
|
williamr@2
|
594 |
* actual strings all occupy an ASN1_STRING
|
williamr@2
|
595 |
* structure. In this case the 'utype' field
|
williamr@2
|
596 |
* has a special meaning, it is used as a mask
|
williamr@2
|
597 |
* of acceptable types using the B_ASN1 constants.
|
williamr@2
|
598 |
*
|
williamr@2
|
599 |
* NDEF_SEQUENCE is the same as SEQUENCE except
|
williamr@2
|
600 |
* that it will use indefinite length constructed
|
williamr@2
|
601 |
* encoding if requested.
|
williamr@2
|
602 |
*
|
williamr@2
|
603 |
*/
|
williamr@2
|
604 |
|
williamr@2
|
605 |
#define ASN1_ITYPE_PRIMITIVE 0x0
|
williamr@2
|
606 |
|
williamr@2
|
607 |
#define ASN1_ITYPE_SEQUENCE 0x1
|
williamr@2
|
608 |
|
williamr@2
|
609 |
#define ASN1_ITYPE_CHOICE 0x2
|
williamr@2
|
610 |
|
williamr@2
|
611 |
#define ASN1_ITYPE_COMPAT 0x3
|
williamr@2
|
612 |
|
williamr@2
|
613 |
#define ASN1_ITYPE_EXTERN 0x4
|
williamr@2
|
614 |
|
williamr@2
|
615 |
#define ASN1_ITYPE_MSTRING 0x5
|
williamr@2
|
616 |
|
williamr@2
|
617 |
#define ASN1_ITYPE_NDEF_SEQUENCE 0x6
|
williamr@2
|
618 |
|
williamr@2
|
619 |
/* Cache for ASN1 tag and length, so we
|
williamr@2
|
620 |
* don't keep re-reading it for things
|
williamr@2
|
621 |
* like CHOICE
|
williamr@2
|
622 |
*/
|
williamr@2
|
623 |
|
williamr@2
|
624 |
struct ASN1_TLC_st{
|
williamr@2
|
625 |
char valid; /* Values below are valid */
|
williamr@2
|
626 |
int ret; /* return value */
|
williamr@2
|
627 |
long plen; /* length */
|
williamr@2
|
628 |
int ptag; /* class value */
|
williamr@2
|
629 |
int pclass; /* class value */
|
williamr@2
|
630 |
int hdrlen; /* header length */
|
williamr@2
|
631 |
};
|
williamr@2
|
632 |
|
williamr@2
|
633 |
/* Typedefs for ASN1 function pointers */
|
williamr@2
|
634 |
|
williamr@2
|
635 |
typedef ASN1_VALUE * ASN1_new_func(void);
|
williamr@2
|
636 |
typedef void ASN1_free_func(ASN1_VALUE *a);
|
williamr@2
|
637 |
typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in, long length);
|
williamr@2
|
638 |
typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in);
|
williamr@2
|
639 |
|
williamr@2
|
640 |
typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it,
|
williamr@2
|
641 |
int tag, int aclass, char opt, ASN1_TLC *ctx);
|
williamr@2
|
642 |
|
williamr@2
|
643 |
typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
|
williamr@2
|
644 |
typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
williamr@2
|
645 |
typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
williamr@2
|
646 |
|
williamr@2
|
647 |
typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
|
williamr@2
|
648 |
typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
|
williamr@2
|
649 |
|
williamr@2
|
650 |
typedef struct ASN1_COMPAT_FUNCS_st {
|
williamr@2
|
651 |
ASN1_new_func *asn1_new;
|
williamr@2
|
652 |
ASN1_free_func *asn1_free;
|
williamr@2
|
653 |
ASN1_d2i_func *asn1_d2i;
|
williamr@2
|
654 |
ASN1_i2d_func *asn1_i2d;
|
williamr@2
|
655 |
} ASN1_COMPAT_FUNCS;
|
williamr@2
|
656 |
|
williamr@2
|
657 |
typedef struct ASN1_EXTERN_FUNCS_st {
|
williamr@2
|
658 |
void *app_data;
|
williamr@2
|
659 |
ASN1_ex_new_func *asn1_ex_new;
|
williamr@2
|
660 |
ASN1_ex_free_func *asn1_ex_free;
|
williamr@2
|
661 |
ASN1_ex_free_func *asn1_ex_clear;
|
williamr@2
|
662 |
ASN1_ex_d2i *asn1_ex_d2i;
|
williamr@2
|
663 |
ASN1_ex_i2d *asn1_ex_i2d;
|
williamr@2
|
664 |
} ASN1_EXTERN_FUNCS;
|
williamr@2
|
665 |
|
williamr@2
|
666 |
typedef struct ASN1_PRIMITIVE_FUNCS_st {
|
williamr@2
|
667 |
void *app_data;
|
williamr@2
|
668 |
unsigned long flags;
|
williamr@2
|
669 |
ASN1_ex_new_func *prim_new;
|
williamr@2
|
670 |
ASN1_ex_free_func *prim_free;
|
williamr@2
|
671 |
ASN1_ex_free_func *prim_clear;
|
williamr@2
|
672 |
ASN1_primitive_c2i *prim_c2i;
|
williamr@2
|
673 |
ASN1_primitive_i2c *prim_i2c;
|
williamr@2
|
674 |
} ASN1_PRIMITIVE_FUNCS;
|
williamr@2
|
675 |
|
williamr@2
|
676 |
/* This is the ASN1_AUX structure: it handles various
|
williamr@2
|
677 |
* miscellaneous requirements. For example the use of
|
williamr@2
|
678 |
* reference counts and an informational callback.
|
williamr@2
|
679 |
*
|
williamr@2
|
680 |
* The "informational callback" is called at various
|
williamr@2
|
681 |
* points during the ASN1 encoding and decoding. It can
|
williamr@2
|
682 |
* be used to provide minor customisation of the structures
|
williamr@2
|
683 |
* used. This is most useful where the supplied routines
|
williamr@2
|
684 |
* *almost* do the right thing but need some extra help
|
williamr@2
|
685 |
* at a few points. If the callback returns zero then
|
williamr@2
|
686 |
* it is assumed a fatal error has occurred and the
|
williamr@2
|
687 |
* main operation should be abandoned.
|
williamr@2
|
688 |
*
|
williamr@2
|
689 |
* If major changes in the default behaviour are required
|
williamr@2
|
690 |
* then an external type is more appropriate.
|
williamr@2
|
691 |
*/
|
williamr@2
|
692 |
|
williamr@2
|
693 |
typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it);
|
williamr@2
|
694 |
|
williamr@2
|
695 |
typedef struct ASN1_AUX_st {
|
williamr@2
|
696 |
void *app_data;
|
williamr@2
|
697 |
int flags;
|
williamr@2
|
698 |
int ref_offset; /* Offset of reference value */
|
williamr@2
|
699 |
int ref_lock; /* Lock type to use */
|
williamr@2
|
700 |
ASN1_aux_cb *asn1_cb;
|
williamr@2
|
701 |
int enc_offset; /* Offset of ASN1_ENCODING structure */
|
williamr@2
|
702 |
} ASN1_AUX;
|
williamr@2
|
703 |
|
williamr@2
|
704 |
/* Flags in ASN1_AUX */
|
williamr@2
|
705 |
|
williamr@2
|
706 |
/* Use a reference count */
|
williamr@2
|
707 |
#define ASN1_AFLG_REFCOUNT 1
|
williamr@2
|
708 |
/* Save the encoding of structure (useful for signatures) */
|
williamr@2
|
709 |
#define ASN1_AFLG_ENCODING 2
|
williamr@2
|
710 |
/* The Sequence length is invalid */
|
williamr@2
|
711 |
#define ASN1_AFLG_BROKEN 4
|
williamr@2
|
712 |
|
williamr@2
|
713 |
/* operation values for asn1_cb */
|
williamr@2
|
714 |
|
williamr@2
|
715 |
#define ASN1_OP_NEW_PRE 0
|
williamr@2
|
716 |
#define ASN1_OP_NEW_POST 1
|
williamr@2
|
717 |
#define ASN1_OP_FREE_PRE 2
|
williamr@2
|
718 |
#define ASN1_OP_FREE_POST 3
|
williamr@2
|
719 |
#define ASN1_OP_D2I_PRE 4
|
williamr@2
|
720 |
#define ASN1_OP_D2I_POST 5
|
williamr@2
|
721 |
#define ASN1_OP_I2D_PRE 6
|
williamr@2
|
722 |
#define ASN1_OP_I2D_POST 7
|
williamr@2
|
723 |
|
williamr@2
|
724 |
/* Macro to implement a primitive type */
|
williamr@2
|
725 |
#define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
|
williamr@2
|
726 |
#define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \
|
williamr@2
|
727 |
ASN1_ITEM_start(itname) \
|
williamr@2
|
728 |
ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \
|
williamr@2
|
729 |
ASN1_ITEM_end(itname)
|
williamr@2
|
730 |
|
williamr@2
|
731 |
/* Macro to implement a multi string type */
|
williamr@2
|
732 |
#define IMPLEMENT_ASN1_MSTRING(itname, mask) \
|
williamr@2
|
733 |
ASN1_ITEM_start(itname) \
|
williamr@2
|
734 |
ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \
|
williamr@2
|
735 |
ASN1_ITEM_end(itname)
|
williamr@2
|
736 |
|
williamr@2
|
737 |
/* Macro to implement an ASN1_ITEM in terms of old style funcs */
|
williamr@2
|
738 |
|
williamr@2
|
739 |
#define IMPLEMENT_COMPAT_ASN1(sname) IMPLEMENT_COMPAT_ASN1_type(sname, V_ASN1_SEQUENCE)
|
williamr@2
|
740 |
|
williamr@2
|
741 |
#define IMPLEMENT_COMPAT_ASN1_type(sname, tag) \
|
williamr@2
|
742 |
static const ASN1_COMPAT_FUNCS sname##_ff = { \
|
williamr@2
|
743 |
(ASN1_new_func *)sname##_new, \
|
williamr@2
|
744 |
(ASN1_free_func *)sname##_free, \
|
williamr@2
|
745 |
(ASN1_d2i_func *)d2i_##sname, \
|
williamr@2
|
746 |
(ASN1_i2d_func *)i2d_##sname, \
|
williamr@2
|
747 |
}; \
|
williamr@2
|
748 |
ASN1_ITEM_start(sname) \
|
williamr@2
|
749 |
ASN1_ITYPE_COMPAT, \
|
williamr@2
|
750 |
tag, \
|
williamr@2
|
751 |
NULL, \
|
williamr@2
|
752 |
0, \
|
williamr@2
|
753 |
&sname##_ff, \
|
williamr@2
|
754 |
0, \
|
williamr@2
|
755 |
#sname \
|
williamr@2
|
756 |
ASN1_ITEM_end(sname)
|
williamr@2
|
757 |
|
williamr@2
|
758 |
#define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \
|
williamr@2
|
759 |
ASN1_ITEM_start(sname) \
|
williamr@2
|
760 |
ASN1_ITYPE_EXTERN, \
|
williamr@2
|
761 |
tag, \
|
williamr@2
|
762 |
NULL, \
|
williamr@2
|
763 |
0, \
|
williamr@2
|
764 |
&fptrs, \
|
williamr@2
|
765 |
0, \
|
williamr@2
|
766 |
#sname \
|
williamr@2
|
767 |
ASN1_ITEM_end(sname)
|
williamr@2
|
768 |
|
williamr@2
|
769 |
/* Macro to implement standard functions in terms of ASN1_ITEM structures */
|
williamr@2
|
770 |
|
williamr@2
|
771 |
#define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)
|
williamr@2
|
772 |
|
williamr@2
|
773 |
#define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)
|
williamr@2
|
774 |
|
williamr@2
|
775 |
#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
|
williamr@2
|
776 |
IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
|
williamr@2
|
777 |
|
williamr@2
|
778 |
#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \
|
williamr@2
|
779 |
IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)
|
williamr@2
|
780 |
|
williamr@2
|
781 |
#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
|
williamr@2
|
782 |
EXPORT_C stname *fname##_new(void) \
|
williamr@2
|
783 |
{ \
|
williamr@2
|
784 |
return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
|
williamr@2
|
785 |
} \
|
williamr@2
|
786 |
EXPORT_C void fname##_free(stname *a) \
|
williamr@2
|
787 |
{ \
|
williamr@2
|
788 |
ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
|
williamr@2
|
789 |
}
|
williamr@2
|
790 |
|
williamr@2
|
791 |
#define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \
|
williamr@2
|
792 |
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
|
williamr@2
|
793 |
IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
|
williamr@2
|
794 |
|
williamr@2
|
795 |
#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
|
williamr@2
|
796 |
EXPORT_C stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
|
williamr@2
|
797 |
{ \
|
williamr@2
|
798 |
return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
|
williamr@2
|
799 |
} \
|
williamr@2
|
800 |
EXPORT_C int i2d_##fname(stname *a, unsigned char **out) \
|
williamr@2
|
801 |
{ \
|
williamr@2
|
802 |
return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
|
williamr@2
|
803 |
}
|
williamr@2
|
804 |
|
williamr@2
|
805 |
#define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \
|
williamr@2
|
806 |
EXPORT_C int i2d_##stname##_NDEF(stname *a, unsigned char **out) \
|
williamr@2
|
807 |
{ \
|
williamr@2
|
808 |
return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\
|
williamr@2
|
809 |
}
|
williamr@2
|
810 |
|
williamr@2
|
811 |
/* This includes evil casts to remove const: they will go away when full
|
williamr@2
|
812 |
* ASN1 constification is done.
|
williamr@2
|
813 |
*/
|
williamr@2
|
814 |
#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
|
williamr@2
|
815 |
EXPORT_C stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
|
williamr@2
|
816 |
{ \
|
williamr@2
|
817 |
return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
|
williamr@2
|
818 |
} \
|
williamr@2
|
819 |
EXPORT_C int i2d_##fname(const stname *a, unsigned char **out) \
|
williamr@2
|
820 |
{ \
|
williamr@2
|
821 |
return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
|
williamr@2
|
822 |
}
|
williamr@2
|
823 |
|
williamr@2
|
824 |
#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
|
williamr@2
|
825 |
EXPORT_C stname * stname##_dup(stname *x) \
|
williamr@2
|
826 |
{ \
|
williamr@2
|
827 |
return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
|
williamr@2
|
828 |
}
|
williamr@2
|
829 |
|
williamr@2
|
830 |
#define IMPLEMENT_ASN1_FUNCTIONS_const(name) \
|
williamr@2
|
831 |
IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)
|
williamr@2
|
832 |
|
williamr@2
|
833 |
#define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \
|
williamr@2
|
834 |
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
|
williamr@2
|
835 |
IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
|
williamr@2
|
836 |
|
williamr@2
|
837 |
/* external definitions for primitive types */
|
williamr@2
|
838 |
|
williamr@2
|
839 |
DECLARE_ASN1_ITEM(ASN1_BOOLEAN)
|
williamr@2
|
840 |
DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)
|
williamr@2
|
841 |
DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)
|
williamr@2
|
842 |
DECLARE_ASN1_ITEM(ASN1_SEQUENCE)
|
williamr@2
|
843 |
DECLARE_ASN1_ITEM(CBIGNUM)
|
williamr@2
|
844 |
DECLARE_ASN1_ITEM(BIGNUM)
|
williamr@2
|
845 |
DECLARE_ASN1_ITEM(LONG)
|
williamr@2
|
846 |
DECLARE_ASN1_ITEM(ZLONG)
|
williamr@2
|
847 |
|
williamr@2
|
848 |
DECLARE_STACK_OF(ASN1_VALUE)
|
williamr@2
|
849 |
|
williamr@2
|
850 |
/* Functions used internally by the ASN1 code */
|
williamr@2
|
851 |
|
williamr@2
|
852 |
IMPORT_C int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
williamr@2
|
853 |
IMPORT_C void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
williamr@2
|
854 |
int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
|
williamr@2
|
855 |
int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
williamr@2
|
856 |
|
williamr@2
|
857 |
IMPORT_C void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
|
williamr@2
|
858 |
int ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_TEMPLATE *tt);
|
williamr@2
|
859 |
IMPORT_C int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it,
|
williamr@2
|
860 |
int tag, int aclass, char opt, ASN1_TLC *ctx);
|
williamr@2
|
861 |
|
williamr@2
|
862 |
IMPORT_C int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
|
williamr@2
|
863 |
int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt);
|
williamr@2
|
864 |
IMPORT_C void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
williamr@2
|
865 |
|
williamr@2
|
866 |
int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
|
williamr@2
|
867 |
int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
|
williamr@2
|
868 |
|
williamr@2
|
869 |
IMPORT_C int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
williamr@2
|
870 |
IMPORT_C int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it);
|
williamr@2
|
871 |
|
williamr@2
|
872 |
IMPORT_C ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
|
williamr@2
|
873 |
|
williamr@2
|
874 |
IMPORT_C const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr);
|
williamr@2
|
875 |
|
williamr@2
|
876 |
IMPORT_C int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);
|
williamr@2
|
877 |
|
williamr@2
|
878 |
IMPORT_C void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
williamr@2
|
879 |
IMPORT_C void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
williamr@2
|
880 |
IMPORT_C int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it);
|
williamr@2
|
881 |
IMPORT_C int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const ASN1_ITEM *it);
|
williamr@2
|
882 |
|
williamr@2
|
883 |
#ifdef __cplusplus
|
williamr@2
|
884 |
}
|
williamr@2
|
885 |
#endif
|
williamr@2
|
886 |
#endif
|