asn1t.h
Go to the documentation of this file.
1 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
2  * project 2000.
3  */
4 /* ====================================================================
5  * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * 3. All advertising materials mentioning features or use of this
20  * software must display the following acknowledgment:
21  * "This product includes software developed by the OpenSSL Project
22  * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
23  *
24  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25  * endorse or promote products derived from this software without
26  * prior written permission. For written permission, please contact
27  * licensing@OpenSSL.org.
28  *
29  * 5. Products derived from this software may not be called "OpenSSL"
30  * nor may "OpenSSL" appear in their names without prior written
31  * permission of the OpenSSL Project.
32  *
33  * 6. Redistributions of any form whatsoever must retain the following
34  * acknowledgment:
35  * "This product includes software developed by the OpenSSL Project
36  * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49  * OF THE POSSIBILITY OF SUCH DAMAGE.
50  * ====================================================================
51  *
52  * This product includes cryptographic software written by Eric Young
53  * (eay@cryptsoft.com). This product includes software written by Tim
54  * Hudson (tjh@cryptsoft.com).
55  *
56  */
57 #ifndef HEADER_ASN1T_H
58 #define HEADER_ASN1T_H
59 
60 #include <openssl/base.h>
61 #include <openssl/asn1.h>
62 
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
67 
68 /* Legacy ASN.1 library template definitions.
69  *
70  * This header is used to define new types in OpenSSL's ASN.1 implementation. It
71  * is deprecated and will be unexported from the library. Use the new |CBS| and
72  * |CBB| library in <openssl/bytestring.h> instead. */
73 
74 
76 typedef struct ASN1_TLC_st ASN1_TLC;
77 
78 /* Macro to obtain ASN1_ADB pointer from a type (only used internally) */
79 #define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))
80 
81 
82 /* Macros for start and end of ASN1_ITEM definition */
83 
84 #define ASN1_ITEM_start(itname) \
85  const ASN1_ITEM itname##_it = {
86 
87 #define ASN1_ITEM_end(itname) \
88  };
89 
90 /* Macros to aid ASN1 template writing */
91 
92 #define ASN1_ITEM_TEMPLATE(tname) \
93  static const ASN1_TEMPLATE tname##_item_tt
94 
95 #define ASN1_ITEM_TEMPLATE_END(tname) \
96  ;\
97  ASN1_ITEM_start(tname) \
98  ASN1_ITYPE_PRIMITIVE,\
99  -1,\
100  &tname##_item_tt,\
101  0,\
102  NULL,\
103  0,\
104  #tname \
105  ASN1_ITEM_end(tname)
106 
107 
108 /* This is a ASN1 type which just embeds a template */
109 
110 /* This pair helps declare a SEQUENCE. We can do:
111  *
112  * ASN1_SEQUENCE(stname) = {
113  * ... SEQUENCE components ...
114  * } ASN1_SEQUENCE_END(stname)
115  *
116  * This will produce an ASN1_ITEM called stname_it
117  * for a structure called stname.
118  *
119  * If you want the same structure but a different
120  * name then use:
121  *
122  * ASN1_SEQUENCE(itname) = {
123  * ... SEQUENCE components ...
124  * } ASN1_SEQUENCE_END_name(stname, itname)
125  *
126  * This will create an item called itname_it using
127  * a structure called stname.
128  */
129 
130 #define ASN1_SEQUENCE(tname) \
131  static const ASN1_TEMPLATE tname##_seq_tt[]
132 
133 #define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
134 
135 #define ASN1_SEQUENCE_END_name(stname, tname) \
136  ;\
137  ASN1_ITEM_start(tname) \
138  ASN1_ITYPE_SEQUENCE,\
139  V_ASN1_SEQUENCE,\
140  tname##_seq_tt,\
141  sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
142  NULL,\
143  sizeof(stname),\
144  #stname \
145  ASN1_ITEM_end(tname)
146 
147 #define ASN1_SEQUENCE_cb(tname, cb) \
148  static const ASN1_AUX tname##_aux = {NULL, 0, 0, cb, 0}; \
149  ASN1_SEQUENCE(tname)
150 
151 #define ASN1_SEQUENCE_ref(tname, cb) \
152  static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), cb, 0}; \
153  ASN1_SEQUENCE(tname)
154 
155 #define ASN1_SEQUENCE_enc(tname, enc, cb) \
156  static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, cb, offsetof(tname, enc)}; \
157  ASN1_SEQUENCE(tname)
158 
159 #define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
160 
161 #define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
162 
163 #define ASN1_SEQUENCE_END_ref(stname, tname) \
164  ;\
165  ASN1_ITEM_start(tname) \
166  ASN1_ITYPE_SEQUENCE,\
167  V_ASN1_SEQUENCE,\
168  tname##_seq_tt,\
169  sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
170  &tname##_aux,\
171  sizeof(stname),\
172  #stname \
173  ASN1_ITEM_end(tname)
174 
175 
176 /* This pair helps declare a CHOICE type. We can do:
177  *
178  * ASN1_CHOICE(chname) = {
179  * ... CHOICE options ...
180  * ASN1_CHOICE_END(chname)
181  *
182  * This will produce an ASN1_ITEM called chname_it
183  * for a structure called chname. The structure
184  * definition must look like this:
185  * typedef struct {
186  * int type;
187  * union {
188  * ASN1_SOMETHING *opt1;
189  * ASN1_SOMEOTHER *opt2;
190  * } value;
191  * } chname;
192  *
193  * the name of the selector must be 'type'.
194  * to use an alternative selector name use the
195  * ASN1_CHOICE_END_selector() version.
196  */
197 
198 #define ASN1_CHOICE(tname) \
199  static const ASN1_TEMPLATE tname##_ch_tt[]
200 
201 #define ASN1_CHOICE_cb(tname, cb) \
202  static const ASN1_AUX tname##_aux = {NULL, 0, 0, cb, 0}; \
203  ASN1_CHOICE(tname)
204 
205 #define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
206 
207 #define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)
208 
209 #define ASN1_CHOICE_END_selector(stname, tname, selname) \
210  ;\
211  ASN1_ITEM_start(tname) \
212  ASN1_ITYPE_CHOICE,\
213  offsetof(stname,selname) ,\
214  tname##_ch_tt,\
215  sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
216  NULL,\
217  sizeof(stname),\
218  #stname \
219  ASN1_ITEM_end(tname)
220 
221 #define ASN1_CHOICE_END_cb(stname, tname, selname) \
222  ;\
223  ASN1_ITEM_start(tname) \
224  ASN1_ITYPE_CHOICE,\
225  offsetof(stname,selname) ,\
226  tname##_ch_tt,\
227  sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
228  &tname##_aux,\
229  sizeof(stname),\
230  #stname \
231  ASN1_ITEM_end(tname)
232 
233 /* This helps with the template wrapper form of ASN1_ITEM */
234 
235 #define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \
236  (flags), (tag), 0,\
237  #name, ASN1_ITEM_ref(type) }
238 
239 /* These help with SEQUENCE or CHOICE components */
240 
241 /* used to declare other types */
242 
243 #define ASN1_EX_TYPE(flags, tag, stname, field, type) { \
244  (flags), (tag), offsetof(stname, field),\
245  #field, ASN1_ITEM_ref(type) }
246 
247 /* used when the structure is combined with the parent */
248 
249 #define ASN1_EX_COMBINE(flags, tag, type) { \
250  (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) }
251 
252 /* implicit and explicit helper macros */
253 
254 #define ASN1_IMP_EX(stname, field, type, tag, ex) \
255  ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)
256 
257 #define ASN1_EXP_EX(stname, field, type, tag, ex) \
258  ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)
259 
260 /* Any defined by macros: the field used is in the table itself */
261 
262 #define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
263 #define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
264 /* Plain simple type */
265 #define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)
266 
267 /* OPTIONAL simple type */
268 #define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)
269 
270 /* IMPLICIT tagged simple type */
271 #define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)
272 
273 /* IMPLICIT tagged OPTIONAL simple type */
274 #define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
275 
276 /* Same as above but EXPLICIT */
277 
278 #define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)
279 #define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
280 
281 /* SEQUENCE OF type */
282 #define ASN1_SEQUENCE_OF(stname, field, type) \
283  ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)
284 
285 /* OPTIONAL SEQUENCE OF */
286 #define ASN1_SEQUENCE_OF_OPT(stname, field, type) \
287  ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
288 
289 /* Same as above but for SET OF */
290 
291 #define ASN1_SET_OF(stname, field, type) \
292  ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)
293 
294 #define ASN1_SET_OF_OPT(stname, field, type) \
295  ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
296 
297 /* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */
298 
299 #define ASN1_IMP_SET_OF(stname, field, type, tag) \
300  ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
301 
302 #define ASN1_EXP_SET_OF(stname, field, type, tag) \
303  ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
304 
305 #define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \
306  ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
307 
308 #define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \
309  ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
310 
311 #define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \
312  ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
313 
314 #define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \
315  ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
316 
317 #define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \
318  ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
319 
320 #define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
321  ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
322 
323 /* Macros for the ASN1_ADB structure */
324 
325 #define ASN1_ADB(name) \
326  static const ASN1_ADB_TABLE name##_adbtbl[]
327 
328 #define ASN1_ADB_END(name, flags, field, app_table, def, none) \
329  ;\
330  static const ASN1_ADB name##_adb = {\
331  flags,\
332  offsetof(name, field),\
333  app_table,\
334  name##_adbtbl,\
335  sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
336  def,\
337  none\
338  }
339 
340 #define ADB_ENTRY(val, template) {val, template}
341 
342 #define ASN1_ADB_TEMPLATE(name) \
343  static const ASN1_TEMPLATE name##_tt
344 
345 /* This is the ASN1 template structure that defines
346  * a wrapper round the actual type. It determines the
347  * actual position of the field in the value structure,
348  * various flags such as OPTIONAL and the field name.
349  */
350 
352 unsigned long flags; /* Various flags */
353 long tag; /* tag, not used if no tagging */
354 unsigned long offset; /* Offset of this field in structure */
355 const char *field_name; /* Field name */
356 ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */
357 };
358 
359 /* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */
360 
361 #define ASN1_TEMPLATE_item(t) (t->item_ptr)
362 #define ASN1_TEMPLATE_adb(t) (t->item_ptr)
363 
365 typedef struct ASN1_ADB_st ASN1_ADB;
366 
367 typedef struct asn1_must_be_null_st ASN1_MUST_BE_NULL;
368 
369 struct ASN1_ADB_st {
370  unsigned long flags; /* Various flags */
371  unsigned long offset; /* Offset of selector field */
373  const ASN1_ADB_TABLE *tbl; /* Table of possible types */
374  long tblcount; /* Number of entries in tbl */
375  const ASN1_TEMPLATE *default_tt; /* Type to use if no match */
376  const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */
377 };
378 
380  long value; /* NID for an object or value for an int */
381  const ASN1_TEMPLATE tt; /* item for this value */
382 };
383 
384 /* template flags */
385 
386 /* Field is optional */
387 #define ASN1_TFLG_OPTIONAL (0x1)
388 
389 /* Field is a SET OF */
390 #define ASN1_TFLG_SET_OF (0x1 << 1)
391 
392 /* Field is a SEQUENCE OF */
393 #define ASN1_TFLG_SEQUENCE_OF (0x2 << 1)
394 
395 /* Mask for SET OF or SEQUENCE OF */
396 #define ASN1_TFLG_SK_MASK (0x3 << 1)
397 
398 /* These flags mean the tag should be taken from the
399  * tag field. If EXPLICIT then the underlying type
400  * is used for the inner tag.
401  */
402 
403 /* IMPLICIT tagging */
404 #define ASN1_TFLG_IMPTAG (0x1 << 3)
405 
406 
407 /* EXPLICIT tagging, inner tag from underlying type */
408 #define ASN1_TFLG_EXPTAG (0x2 << 3)
409 
410 #define ASN1_TFLG_TAG_MASK (0x3 << 3)
411 
412 /* context specific IMPLICIT */
413 #define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT
414 
415 /* context specific EXPLICIT */
416 #define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT
417 
418 /* If tagging is in force these determine the
419  * type of tag to use. Otherwise the tag is
420  * determined by the underlying type. These
421  * values reflect the actual octet format.
422  */
423 
424 /* Universal tag */
425 #define ASN1_TFLG_UNIVERSAL (0x0<<6)
426 /* Application tag */
427 #define ASN1_TFLG_APPLICATION (0x1<<6)
428 /* Context specific tag */
429 #define ASN1_TFLG_CONTEXT (0x2<<6)
430 /* Private tag */
431 #define ASN1_TFLG_PRIVATE (0x3<<6)
432 
433 #define ASN1_TFLG_TAG_CLASS (0x3<<6)
434 
435 /* These are for ANY DEFINED BY type. In this case
436  * the 'item' field points to an ASN1_ADB structure
437  * which contains a table of values to decode the
438  * relevant type
439  */
440 
441 #define ASN1_TFLG_ADB_MASK (0x3<<8)
442 
443 #define ASN1_TFLG_ADB_OID (0x1<<8)
444 
445 #define ASN1_TFLG_ADB_INT (0x1<<9)
446 
447 /* This flag means a parent structure is passed
448  * instead of the field: this is useful is a
449  * SEQUENCE is being combined with a CHOICE for
450  * example. Since this means the structure and
451  * item name will differ we need to use the
452  * ASN1_CHOICE_END_name() macro for example.
453  */
454 
455 #define ASN1_TFLG_COMBINE (0x1<<10)
456 
457 /* This is the actual ASN1 item itself */
458 
459 struct ASN1_ITEM_st {
460 char itype; /* The item type, primitive, SEQUENCE, CHOICE or extern */
461 long utype; /* underlying type */
462 const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains the contents */
463 long tcount; /* Number of templates if SEQUENCE or CHOICE */
464 const void *funcs; /* functions that handle this type */
465 long size; /* Structure size (usually)*/
466 const char *sname; /* Structure name */
467 };
468 
469 /* These are values for the itype field and
470  * determine how the type is interpreted.
471  *
472  * For PRIMITIVE types the underlying type
473  * determines the behaviour if items is NULL.
474  *
475  * Otherwise templates must contain a single
476  * template and the type is treated in the
477  * same way as the type specified in the template.
478  *
479  * For SEQUENCE types the templates field points
480  * to the members, the size field is the
481  * structure size.
482  *
483  * For CHOICE types the templates field points
484  * to each possible member (typically a union)
485  * and the 'size' field is the offset of the
486  * selector.
487  *
488  * The 'funcs' field is used for application
489  * specific functions.
490  *
491  * The EXTERN type uses a new style d2i/i2d.
492  * The new style should be used where possible
493  * because it avoids things like the d2i IMPLICIT
494  * hack.
495  *
496  * MSTRING is a multiple string type, it is used
497  * for a CHOICE of character strings where the
498  * actual strings all occupy an ASN1_STRING
499  * structure. In this case the 'utype' field
500  * has a special meaning, it is used as a mask
501  * of acceptable types using the B_ASN1 constants.
502  *
503  */
504 
505 #define ASN1_ITYPE_PRIMITIVE 0x0
506 
507 #define ASN1_ITYPE_SEQUENCE 0x1
508 
509 #define ASN1_ITYPE_CHOICE 0x2
510 
511 #define ASN1_ITYPE_EXTERN 0x4
512 
513 #define ASN1_ITYPE_MSTRING 0x5
514 
515 /* Cache for ASN1 tag and length, so we
516  * don't keep re-reading it for things
517  * like CHOICE
518  */
519 
520 struct ASN1_TLC_st{
521  char valid; /* Values below are valid */
522  int ret; /* return value */
523  long plen; /* length */
524  int ptag; /* class value */
525  int pclass; /* class value */
526  int hdrlen; /* header length */
527 };
528 
529 /* Typedefs for ASN1 function pointers */
530 
531 typedef ASN1_VALUE * ASN1_new_func(void);
532 typedef void ASN1_free_func(ASN1_VALUE *a);
533 typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in, long length);
534 typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in);
535 
536 typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it,
537  int tag, int aclass, char opt, ASN1_TLC *ctx);
538 
539 typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
540 typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
541 typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
542 
543 typedef int ASN1_ex_print_func(BIO *out, ASN1_VALUE **pval,
544  int indent, const char *fname,
545  const ASN1_PCTX *pctx);
546 
547 typedef struct ASN1_EXTERN_FUNCS_st {
548  void *app_data;
554  /* asn1_ex_print is unused. */
557 
558 /* This is the ASN1_AUX structure: it handles various
559  * miscellaneous requirements. For example the use of
560  * reference counts and an informational callback.
561  *
562  * The "informational callback" is called at various
563  * points during the ASN1 encoding and decoding. It can
564  * be used to provide minor customisation of the structures
565  * used. This is most useful where the supplied routines
566  * *almost* do the right thing but need some extra help
567  * at a few points. If the callback returns zero then
568  * it is assumed a fatal error has occurred and the
569  * main operation should be abandoned.
570  *
571  * If major changes in the default behaviour are required
572  * then an external type is more appropriate.
573  */
574 
575 typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it,
576  void *exarg);
577 
578 typedef struct ASN1_AUX_st {
579  void *app_data;
580  int flags;
581  int ref_offset; /* Offset of reference value */
583  int enc_offset; /* Offset of ASN1_ENCODING structure */
584 } ASN1_AUX;
585 
586 /* Flags in ASN1_AUX */
587 
588 /* Use a reference count */
589 #define ASN1_AFLG_REFCOUNT 1
590 /* Save the encoding of structure (useful for signatures) */
591 #define ASN1_AFLG_ENCODING 2
592 
593 /* operation values for asn1_cb */
594 
595 #define ASN1_OP_NEW_PRE 0
596 #define ASN1_OP_NEW_POST 1
597 #define ASN1_OP_FREE_PRE 2
598 #define ASN1_OP_FREE_POST 3
599 #define ASN1_OP_D2I_PRE 4
600 #define ASN1_OP_D2I_POST 5
601 /* ASN1_OP_I2D_PRE and ASN1_OP_I2D_POST are not supported. We leave the
602  * constants undefined so code relying on them does not accidentally compile. */
603 #define ASN1_OP_PRINT_PRE 8
604 #define ASN1_OP_PRINT_POST 9
605 #define ASN1_OP_STREAM_PRE 10
606 #define ASN1_OP_STREAM_POST 11
607 #define ASN1_OP_DETACHED_PRE 12
608 #define ASN1_OP_DETACHED_POST 13
609 
610 /* Macro to implement a primitive type */
611 #define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
612 #define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \
613  ASN1_ITEM_start(itname) \
614  ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \
615  ASN1_ITEM_end(itname)
616 
617 /* Macro to implement a multi string type */
618 #define IMPLEMENT_ASN1_MSTRING(itname, mask) \
619  ASN1_ITEM_start(itname) \
620  ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \
621  ASN1_ITEM_end(itname)
622 
623 #define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \
624  ASN1_ITEM_start(sname) \
625  ASN1_ITYPE_EXTERN, \
626  tag, \
627  NULL, \
628  0, \
629  &fptrs, \
630  0, \
631  #sname \
632  ASN1_ITEM_end(sname)
633 
634 /* Macro to implement standard functions in terms of ASN1_ITEM structures */
635 
636 #define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)
637 
638 #define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)
639 
640 #define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
641  IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
642 
643 #define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \
644  IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname)
645 
646 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \
647  IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)
648 
649 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \
650  pre stname *fname##_new(void) \
651  { \
652  return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
653  } \
654  pre void fname##_free(stname *a) \
655  { \
656  ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
657  }
658 
659 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
660  stname *fname##_new(void) \
661  { \
662  return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
663  } \
664  void fname##_free(stname *a) \
665  { \
666  ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
667  }
668 
669 #define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \
670  IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
671  IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
672 
673 #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
674  stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
675  { \
676  return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
677  } \
678  int i2d_##fname(stname *a, unsigned char **out) \
679  { \
680  return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
681  }
682 
683 /* This includes evil casts to remove const: they will go away when full
684  * ASN1 constification is done.
685  */
686 #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
687  stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
688  { \
689  return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
690  } \
691  int i2d_##fname(const stname *a, unsigned char **out) \
692  { \
693  return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
694  }
695 
696 #define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
697  stname * stname##_dup(stname *x) \
698  { \
699  return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
700  }
701 
702 #define IMPLEMENT_ASN1_FUNCTIONS_const(name) \
703  IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)
704 
705 #define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \
706  IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
707  IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
708 
709 /* external definitions for primitive types */
710 
712 
714 
715 #ifdef __cplusplus
716 }
717 #endif
718 #endif
ASN1_TEMPLATE_st::field_name
const char * field_name
Definition: asn1t.h:355
ASN1_ADB_st::default_tt
const ASN1_TEMPLATE * default_tt
Definition: asn1t.h:375
ASN1_TEMPLATE_st::item
ASN1_ITEM_EXP * item
Definition: asn1t.h:356
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
regen-readme.it
it
Definition: regen-readme.py:15
ASN1_TLC_st
Definition: asn1t.h:520
ctx
Definition: benchmark-async.c:30
ASN1_EXTERN_FUNCS_st::asn1_ex_free
ASN1_ex_free_func * asn1_ex_free
Definition: asn1t.h:550
ASN1_TEMPLATE_st::offset
unsigned long offset
Definition: asn1t.h:354
bio_st
Definition: bio.h:822
ASN1_AUX
struct ASN1_AUX_st ASN1_AUX
ASN1_d2i_func
ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char **in, long length)
Definition: asn1t.h:533
ASN1_ITEM_st::sname
const char * sname
Definition: asn1t.h:466
ASN1_EXTERN_FUNCS_st
Definition: asn1t.h:547
ASN1_ITEM_st::size
long size
Definition: asn1t.h:465
ASN1_TLC_st::ret
int ret
Definition: asn1t.h:522
ASN1_EXTERN_FUNCS_st::asn1_ex_d2i
ASN1_ex_d2i * asn1_ex_d2i
Definition: asn1t.h:552
ASN1_TLC_st::ptag
int ptag
Definition: asn1t.h:524
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
python_utils.upload_rbe_results.indent
indent
Definition: upload_rbe_results.py:183
ASN1_ITEM_st::utype
long utype
Definition: asn1t.h:461
ASN1_EXTERN_FUNCS_st::asn1_ex_new
ASN1_ex_new_func * asn1_ex_new
Definition: asn1t.h:549
base.h
ASN1_AUX_st::enc_offset
int enc_offset
Definition: asn1t.h:583
ASN1_PCTX
struct asn1_pctx_st ASN1_PCTX
Definition: base.h:338
ASN1_EXTERN_FUNCS_st::asn1_ex_i2d
ASN1_ex_i2d * asn1_ex_i2d
Definition: asn1t.h:553
ASN1_AUX_st::asn1_cb
ASN1_aux_cb * asn1_cb
Definition: asn1t.h:582
in
const char * in
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:391
ASN1_ITEM_st
Definition: asn1t.h:459
ASN1_TEMPLATE_st::tag
long tag
Definition: asn1t.h:353
ASN1_ITEM_st::itype
char itype
Definition: asn1t.h:460
ASN1_TLC_st::valid
char valid
Definition: asn1t.h:521
tag
static void * tag(intptr_t t)
Definition: bad_client.cc:318
ASN1_ADB_st::tblcount
long tblcount
Definition: asn1t.h:374
ASN1_EXTERN_FUNCS_st::asn1_ex_clear
ASN1_ex_free_func * asn1_ex_clear
Definition: asn1t.h:551
ASN1_TLC_st::plen
long plen
Definition: asn1t.h:523
ASN1_ex_new_func
int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it)
Definition: asn1t.h:540
ASN1_EXTERN_FUNCS_st::app_data
void * app_data
Definition: asn1t.h:548
ASN1_ex_d2i
int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx)
Definition: asn1t.h:536
ASN1_AUX_st::app_data
void * app_data
Definition: asn1t.h:579
ASN1_ADB_TABLE_st
Definition: asn1t.h:379
ASN1_ADB_TABLE_st::tt
const ASN1_TEMPLATE tt
Definition: asn1t.h:381
ASN1_EXTERN_FUNCS_st::asn1_ex_print
ASN1_ex_print_func * asn1_ex_print
Definition: asn1t.h:555
ASN1_TLC_st::pclass
int pclass
Definition: asn1t.h:525
ASN1_ADB_st::null_tt
const ASN1_TEMPLATE * null_tt
Definition: asn1t.h:376
ASN1_ITEM_st::templates
const ASN1_TEMPLATE * templates
Definition: asn1t.h:462
ASN1_SEQUENCE
#define ASN1_SEQUENCE(tname)
Definition: asn1t.h:130
ASN1_ITEM_EXP
const typedef ASN1_ITEM ASN1_ITEM_EXP
Definition: asn1.h:309
DEFINE_STACK_OF
#define DEFINE_STACK_OF(type)
Definition: stack.h:409
ASN1_ADB_st
Definition: asn1t.h:369
ASN1_TLC_st::hdrlen
int hdrlen
Definition: asn1t.h:526
ASN1_new_func
ASN1_VALUE * ASN1_new_func(void)
Definition: asn1t.h:531
ASN1_ADB_TABLE_st::value
long value
Definition: asn1t.h:380
ASN1_ex_free_func
void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it)
Definition: asn1t.h:541
ASN1_ITEM_st::tcount
long tcount
Definition: asn1t.h:463
ASN1_ADB_st::tbl
const ASN1_ADB_TABLE * tbl
Definition: asn1t.h:373
ASN1_AUX_st::flags
int flags
Definition: asn1t.h:580
ASN1_aux_cb
int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it, void *exarg)
Definition: asn1t.h:575
ASN1_ex_i2d
int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
Definition: asn1t.h:539
ASN1_ADB_st::unused
ASN1_MUST_BE_NULL * unused
Definition: asn1t.h:372
ASN1_ADB_st::offset
unsigned long offset
Definition: asn1t.h:371
ASN1_EXTERN_FUNCS
struct ASN1_EXTERN_FUNCS_st ASN1_EXTERN_FUNCS
ASN1_TEMPLATE_st
Definition: asn1t.h:351
ASN1_ITEM_st::funcs
const void * funcs
Definition: asn1t.h:464
ASN1_VALUE
struct ASN1_VALUE_st ASN1_VALUE
Definition: asn1.h:320
DECLARE_ASN1_ITEM
#define DECLARE_ASN1_ITEM(name)
Definition: asn1.h:299
ASN1_TEMPLATE_st::flags
unsigned long flags
Definition: asn1t.h:352
ASN1_ex_print_func
int ASN1_ex_print_func(BIO *out, ASN1_VALUE **pval, int indent, const char *fname, const ASN1_PCTX *pctx)
Definition: asn1t.h:543
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
ASN1_free_func
void ASN1_free_func(ASN1_VALUE *a)
Definition: asn1t.h:532
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
ASN1_AUX_st::ref_offset
int ref_offset
Definition: asn1t.h:581
ASN1_MUST_BE_NULL
struct asn1_must_be_null_st ASN1_MUST_BE_NULL
Definition: asn1t.h:367
ASN1_AUX_st
Definition: asn1t.h:578
ASN1_ADB_st::flags
unsigned long flags
Definition: asn1t.h:370
ASN1_i2d_func
int ASN1_i2d_func(ASN1_VALUE *a, unsigned char **in)
Definition: asn1t.h:534
asn1.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:34