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