Go to the documentation of this file.
58 #ifndef HEADER_ASN1T_H
59 #define HEADER_ASN1T_H
65 #ifdef OPENSSL_BUILD_SHLIBCRYPTO
66 # undef OPENSSL_EXTERN
67 # define OPENSSL_EXTERN OPENSSL_EXPORT
77 #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
80 #define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))
85 #define ASN1_ITEM_start(itname) \
86 OPENSSL_GLOBAL const ASN1_ITEM itname##_it = {
88 #define ASN1_ITEM_end(itname) \
94 #define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr()))
99 #define ASN1_ITEM_start(itname) \
100 const ASN1_ITEM * itname##_it(void) \
102 static const ASN1_ITEM local_it = {
104 #define ASN1_ITEM_end(itname) \
114 #define ASN1_ITEM_TEMPLATE(tname) \
115 static const ASN1_TEMPLATE tname##_item_tt
117 #define ASN1_ITEM_TEMPLATE_END(tname) \
119 ASN1_ITEM_start(tname) \
120 ASN1_ITYPE_PRIMITIVE,\
152 #define ASN1_SEQUENCE(tname) \
153 static const ASN1_TEMPLATE tname##_seq_tt[]
155 #define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
157 #define ASN1_SEQUENCE_END_name(stname, tname) \
159 ASN1_ITEM_start(tname) \
160 ASN1_ITYPE_SEQUENCE,\
163 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
169 #define ASN1_NDEF_SEQUENCE(tname) \
172 #define ASN1_NDEF_SEQUENCE_cb(tname, cb) \
173 ASN1_SEQUENCE_cb(tname, cb)
175 #define ASN1_SEQUENCE_cb(tname, cb) \
176 static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
179 #define ASN1_BROKEN_SEQUENCE(tname) \
180 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \
183 #define ASN1_SEQUENCE_ref(tname, cb, lck) \
184 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \
187 #define ASN1_SEQUENCE_enc(tname, enc, cb) \
188 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \
191 #define ASN1_NDEF_SEQUENCE_END(tname) \
193 ASN1_ITEM_start(tname) \
194 ASN1_ITYPE_NDEF_SEQUENCE,\
197 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
203 #define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)
205 #define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
207 #define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
209 #define ASN1_SEQUENCE_END_ref(stname, tname) \
211 ASN1_ITEM_start(tname) \
212 ASN1_ITYPE_SEQUENCE,\
215 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
221 #define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \
223 ASN1_ITEM_start(tname) \
224 ASN1_ITYPE_NDEF_SEQUENCE,\
227 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
256 #define ASN1_CHOICE(tname) \
257 static const ASN1_TEMPLATE tname##_ch_tt[]
259 #define ASN1_CHOICE_cb(tname, cb) \
260 static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
263 #define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
265 #define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)
267 #define ASN1_CHOICE_END_selector(stname, tname, selname) \
269 ASN1_ITEM_start(tname) \
271 offsetof(stname,selname) ,\
273 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
279 #define ASN1_CHOICE_END_cb(stname, tname, selname) \
281 ASN1_ITEM_start(tname) \
283 offsetof(stname,selname) ,\
285 sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\
293 #define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \
295 #name, ASN1_ITEM_ref(type) }
301 #define ASN1_EX_TYPE(flags, tag, stname, field, type) { \
302 (flags), (tag), offsetof(stname, field),\
303 #field, ASN1_ITEM_ref(type) }
307 #define ASN1_EX_COMBINE(flags, tag, type) { \
308 (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) }
312 #define ASN1_IMP_EX(stname, field, type, tag, ex) \
313 ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)
315 #define ASN1_EXP_EX(stname, field, type, tag, ex) \
316 ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)
320 #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
321 #define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
322 #define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
324 #define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb }
325 #define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb }
328 #define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)
331 #define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)
334 #define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)
337 #define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
341 #define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)
342 #define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)
345 #define ASN1_SEQUENCE_OF(stname, field, type) \
346 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)
349 #define ASN1_SEQUENCE_OF_OPT(stname, field, type) \
350 ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
354 #define ASN1_SET_OF(stname, field, type) \
355 ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)
357 #define ASN1_SET_OF_OPT(stname, field, type) \
358 ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)
362 #define ASN1_IMP_SET_OF(stname, field, type, tag) \
363 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
365 #define ASN1_EXP_SET_OF(stname, field, type, tag) \
366 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)
368 #define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \
369 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
371 #define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \
372 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)
374 #define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \
375 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
377 #define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \
378 ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
380 #define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \
381 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)
383 #define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
384 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
387 #define ASN1_NDEF_EXP(stname, field, type, tag) \
388 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF)
391 #define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \
392 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF)
396 #define ASN1_ADB(name) \
397 static const ASN1_ADB_TABLE name##_adbtbl[]
399 #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
401 #define ASN1_ADB_END(name, flags, field, app_table, def, none) \
403 static const ASN1_ADB name##_adb = {\
405 offsetof(name, field),\
408 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
415 #define ASN1_ADB_END(name, flags, field, app_table, def, none) \
417 static const ASN1_ITEM *name##_adb(void) \
419 static const ASN1_ADB internal_adb = \
422 offsetof(name, field),\
425 sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\
429 return (const ASN1_ITEM *) &internal_adb; \
431 void dummy_function(void)
435 #define ADB_ENTRY(val, template) {val, template}
437 #define ASN1_ADB_TEMPLATE(name) \
438 static const ASN1_TEMPLATE name##_tt
450 #ifndef NO_ASN1_FIELD_NAMES
458 #define ASN1_TEMPLATE_item(t) (t->item_ptr)
459 #define ASN1_TEMPLATE_adb(t) (t->item_ptr)
482 #define ASN1_TFLG_OPTIONAL (0x1)
485 #define ASN1_TFLG_SET_OF (0x1 << 1)
488 #define ASN1_TFLG_SEQUENCE_OF (0x2 << 1)
495 #define ASN1_TFLG_SET_ORDER (0x3 << 1)
498 #define ASN1_TFLG_SK_MASK (0x3 << 1)
506 #define ASN1_TFLG_IMPTAG (0x1 << 3)
510 #define ASN1_TFLG_EXPTAG (0x2 << 3)
512 #define ASN1_TFLG_TAG_MASK (0x3 << 3)
515 #define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT
518 #define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT
527 #define ASN1_TFLG_UNIVERSAL (0x0<<6)
529 #define ASN1_TFLG_APPLICATION (0x1<<6)
531 #define ASN1_TFLG_CONTEXT (0x2<<6)
533 #define ASN1_TFLG_PRIVATE (0x3<<6)
535 #define ASN1_TFLG_TAG_CLASS (0x3<<6)
543 #define ASN1_TFLG_ADB_MASK (0x3<<8)
545 #define ASN1_TFLG_ADB_OID (0x1<<8)
547 #define ASN1_TFLG_ADB_INT (0x1<<9)
557 #define ASN1_TFLG_COMBINE (0x1<<10)
564 #define ASN1_TFLG_NDEF (0x1<<11)
575 #ifndef NO_ASN1_FIELD_NAMES
624 #define ASN1_ITYPE_PRIMITIVE 0x0
626 #define ASN1_ITYPE_SEQUENCE 0x1
628 #define ASN1_ITYPE_CHOICE 0x2
630 #define ASN1_ITYPE_COMPAT 0x3
632 #define ASN1_ITYPE_EXTERN 0x4
634 #define ASN1_ITYPE_MSTRING 0x5
636 #define ASN1_ITYPE_NDEF_SEQUENCE 0x6
660 int tag,
int aclass,
char opt,
ASN1_TLC *ctx);
667 int indent,
const char *fname,
751 #define ASN1_AFLG_REFCOUNT 1
753 #define ASN1_AFLG_ENCODING 2
755 #define ASN1_AFLG_BROKEN 4
759 #define ASN1_OP_NEW_PRE 0
760 #define ASN1_OP_NEW_POST 1
761 #define ASN1_OP_FREE_PRE 2
762 #define ASN1_OP_FREE_POST 3
763 #define ASN1_OP_D2I_PRE 4
764 #define ASN1_OP_D2I_POST 5
765 #define ASN1_OP_I2D_PRE 6
766 #define ASN1_OP_I2D_POST 7
767 #define ASN1_OP_PRINT_PRE 8
768 #define ASN1_OP_PRINT_POST 9
769 #define ASN1_OP_STREAM_PRE 10
770 #define ASN1_OP_STREAM_POST 11
771 #define ASN1_OP_DETACHED_PRE 12
772 #define ASN1_OP_DETACHED_POST 13
775 #define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0)
776 #define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \
777 ASN1_ITEM_start(itname) \
778 ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \
779 ASN1_ITEM_end(itname)
782 #define IMPLEMENT_ASN1_MSTRING(itname, mask) \
783 ASN1_ITEM_start(itname) \
784 ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \
785 ASN1_ITEM_end(itname)
789 #define IMPLEMENT_COMPAT_ASN1(sname) IMPLEMENT_COMPAT_ASN1_type(sname, V_ASN1_SEQUENCE)
791 #define IMPLEMENT_COMPAT_ASN1_type(sname, tag) \
792 static const ASN1_COMPAT_FUNCS sname##_ff = { \
793 (ASN1_new_func *)sname##_new, \
794 (ASN1_free_func *)sname##_free, \
795 (ASN1_d2i_func *)d2i_##sname, \
796 (ASN1_i2d_func *)i2d_##sname, \
798 ASN1_ITEM_start(sname) \
808 #define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \
809 ASN1_ITEM_start(sname) \
821 #define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname)
823 #define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname)
825 #define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
826 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
828 #define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \
829 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname)
831 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \
832 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)
834 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \
835 pre stname *fname##_new(void) \
837 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
839 pre void fname##_free(stname *a) \
841 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
844 #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
845 stname *fname##_new(void) \
847 return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \
849 void fname##_free(stname *a) \
851 ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \
854 #define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \
855 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
856 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
858 #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
859 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
861 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
863 int i2d_##fname(stname *a, unsigned char **out) \
865 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
868 #define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \
869 int i2d_##stname##_NDEF(stname *a, unsigned char **out) \
871 return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\
877 #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
878 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
880 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
882 int i2d_##fname(const stname *a, unsigned char **out) \
884 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
887 #define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \
888 stname * stname##_dup(stname *x) \
890 return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
893 #define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \
894 IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname)
896 #define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \
897 int fname##_print_ctx(BIO *out, stname *x, int indent, \
898 const ASN1_PCTX *pctx) \
900 return ASN1_item_print(out, (ASN1_VALUE *)x, indent, \
901 ASN1_ITEM_rptr(itname), pctx); \
904 #define IMPLEMENT_ASN1_FUNCTIONS_const(name) \
905 IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)
907 #define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \
908 IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
909 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
934 int tag,
int aclass,
char opt,
ASN1_TLC *ctx);