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