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