jpayne@69: /* jpayne@69: * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. jpayne@69: * jpayne@69: * Licensed under the OpenSSL license (the "License"). You may not use jpayne@69: * this file except in compliance with the License. You can obtain a copy jpayne@69: * in the file LICENSE in the source distribution or at jpayne@69: * https://www.openssl.org/source/license.html jpayne@69: */ jpayne@69: jpayne@69: #ifndef HEADER_ASN1T_H jpayne@69: # define HEADER_ASN1T_H jpayne@69: jpayne@69: # include jpayne@69: # include jpayne@69: # include jpayne@69: jpayne@69: # ifdef OPENSSL_BUILD_SHLIBCRYPTO jpayne@69: # undef OPENSSL_EXTERN jpayne@69: # define OPENSSL_EXTERN OPENSSL_EXPORT jpayne@69: # endif jpayne@69: jpayne@69: /* ASN1 template defines, structures and functions */ jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: # ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION jpayne@69: jpayne@69: /* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ jpayne@69: # define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr)) jpayne@69: jpayne@69: /* Macros for start and end of ASN1_ITEM definition */ jpayne@69: jpayne@69: # define ASN1_ITEM_start(itname) \ jpayne@69: const ASN1_ITEM itname##_it = { jpayne@69: jpayne@69: # define static_ASN1_ITEM_start(itname) \ jpayne@69: static const ASN1_ITEM itname##_it = { jpayne@69: jpayne@69: # define ASN1_ITEM_end(itname) \ jpayne@69: }; jpayne@69: jpayne@69: # else jpayne@69: jpayne@69: /* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ jpayne@69: # define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)((iptr)())) jpayne@69: jpayne@69: /* Macros for start and end of ASN1_ITEM definition */ jpayne@69: jpayne@69: # define ASN1_ITEM_start(itname) \ jpayne@69: const ASN1_ITEM * itname##_it(void) \ jpayne@69: { \ jpayne@69: static const ASN1_ITEM local_it = { jpayne@69: jpayne@69: # define static_ASN1_ITEM_start(itname) \ jpayne@69: static ASN1_ITEM_start(itname) jpayne@69: jpayne@69: # define ASN1_ITEM_end(itname) \ jpayne@69: }; \ jpayne@69: return &local_it; \ jpayne@69: } jpayne@69: jpayne@69: # endif jpayne@69: jpayne@69: /* Macros to aid ASN1 template writing */ jpayne@69: jpayne@69: # define ASN1_ITEM_TEMPLATE(tname) \ jpayne@69: static const ASN1_TEMPLATE tname##_item_tt jpayne@69: jpayne@69: # define ASN1_ITEM_TEMPLATE_END(tname) \ jpayne@69: ;\ jpayne@69: ASN1_ITEM_start(tname) \ jpayne@69: ASN1_ITYPE_PRIMITIVE,\ jpayne@69: -1,\ jpayne@69: &tname##_item_tt,\ jpayne@69: 0,\ jpayne@69: NULL,\ jpayne@69: 0,\ jpayne@69: #tname \ jpayne@69: ASN1_ITEM_end(tname) jpayne@69: # define static_ASN1_ITEM_TEMPLATE_END(tname) \ jpayne@69: ;\ jpayne@69: static_ASN1_ITEM_start(tname) \ jpayne@69: ASN1_ITYPE_PRIMITIVE,\ jpayne@69: -1,\ jpayne@69: &tname##_item_tt,\ jpayne@69: 0,\ jpayne@69: NULL,\ jpayne@69: 0,\ jpayne@69: #tname \ jpayne@69: ASN1_ITEM_end(tname) jpayne@69: jpayne@69: /* This is a ASN1 type which just embeds a template */ jpayne@69: jpayne@69: /*- jpayne@69: * This pair helps declare a SEQUENCE. We can do: jpayne@69: * jpayne@69: * ASN1_SEQUENCE(stname) = { jpayne@69: * ... SEQUENCE components ... jpayne@69: * } ASN1_SEQUENCE_END(stname) jpayne@69: * jpayne@69: * This will produce an ASN1_ITEM called stname_it jpayne@69: * for a structure called stname. jpayne@69: * jpayne@69: * If you want the same structure but a different jpayne@69: * name then use: jpayne@69: * jpayne@69: * ASN1_SEQUENCE(itname) = { jpayne@69: * ... SEQUENCE components ... jpayne@69: * } ASN1_SEQUENCE_END_name(stname, itname) jpayne@69: * jpayne@69: * This will create an item called itname_it using jpayne@69: * a structure called stname. jpayne@69: */ jpayne@69: jpayne@69: # define ASN1_SEQUENCE(tname) \ jpayne@69: static const ASN1_TEMPLATE tname##_seq_tt[] jpayne@69: jpayne@69: # define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname) jpayne@69: jpayne@69: # define static_ASN1_SEQUENCE_END(stname) static_ASN1_SEQUENCE_END_name(stname, stname) jpayne@69: jpayne@69: # define ASN1_SEQUENCE_END_name(stname, tname) \ jpayne@69: ;\ jpayne@69: ASN1_ITEM_start(tname) \ jpayne@69: ASN1_ITYPE_SEQUENCE,\ jpayne@69: V_ASN1_SEQUENCE,\ jpayne@69: tname##_seq_tt,\ jpayne@69: sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ jpayne@69: NULL,\ jpayne@69: sizeof(stname),\ jpayne@69: #tname \ jpayne@69: ASN1_ITEM_end(tname) jpayne@69: jpayne@69: # define static_ASN1_SEQUENCE_END_name(stname, tname) \ jpayne@69: ;\ jpayne@69: static_ASN1_ITEM_start(tname) \ jpayne@69: ASN1_ITYPE_SEQUENCE,\ jpayne@69: V_ASN1_SEQUENCE,\ jpayne@69: tname##_seq_tt,\ jpayne@69: sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ jpayne@69: NULL,\ jpayne@69: sizeof(stname),\ jpayne@69: #stname \ jpayne@69: ASN1_ITEM_end(tname) jpayne@69: jpayne@69: # define ASN1_NDEF_SEQUENCE(tname) \ jpayne@69: ASN1_SEQUENCE(tname) jpayne@69: jpayne@69: # define ASN1_NDEF_SEQUENCE_cb(tname, cb) \ jpayne@69: ASN1_SEQUENCE_cb(tname, cb) jpayne@69: jpayne@69: # define ASN1_SEQUENCE_cb(tname, cb) \ jpayne@69: static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ jpayne@69: ASN1_SEQUENCE(tname) jpayne@69: jpayne@69: # define ASN1_BROKEN_SEQUENCE(tname) \ jpayne@69: static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \ jpayne@69: ASN1_SEQUENCE(tname) jpayne@69: jpayne@69: # define ASN1_SEQUENCE_ref(tname, cb) \ jpayne@69: static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), offsetof(tname, lock), cb, 0}; \ jpayne@69: ASN1_SEQUENCE(tname) jpayne@69: jpayne@69: # define ASN1_SEQUENCE_enc(tname, enc, cb) \ jpayne@69: static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \ jpayne@69: ASN1_SEQUENCE(tname) jpayne@69: jpayne@69: # define ASN1_NDEF_SEQUENCE_END(tname) \ jpayne@69: ;\ jpayne@69: ASN1_ITEM_start(tname) \ jpayne@69: ASN1_ITYPE_NDEF_SEQUENCE,\ jpayne@69: V_ASN1_SEQUENCE,\ jpayne@69: tname##_seq_tt,\ jpayne@69: sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ jpayne@69: NULL,\ jpayne@69: sizeof(tname),\ jpayne@69: #tname \ jpayne@69: ASN1_ITEM_end(tname) jpayne@69: # define static_ASN1_NDEF_SEQUENCE_END(tname) \ jpayne@69: ;\ jpayne@69: static_ASN1_ITEM_start(tname) \ jpayne@69: ASN1_ITYPE_NDEF_SEQUENCE,\ jpayne@69: V_ASN1_SEQUENCE,\ jpayne@69: tname##_seq_tt,\ jpayne@69: sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ jpayne@69: NULL,\ jpayne@69: sizeof(tname),\ jpayne@69: #tname \ jpayne@69: ASN1_ITEM_end(tname) jpayne@69: jpayne@69: # define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname) jpayne@69: # define static_ASN1_BROKEN_SEQUENCE_END(stname) \ jpayne@69: static_ASN1_SEQUENCE_END_ref(stname, stname) jpayne@69: jpayne@69: # define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) jpayne@69: jpayne@69: # define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) jpayne@69: # define static_ASN1_SEQUENCE_END_cb(stname, tname) static_ASN1_SEQUENCE_END_ref(stname, tname) jpayne@69: jpayne@69: # define ASN1_SEQUENCE_END_ref(stname, tname) \ jpayne@69: ;\ jpayne@69: ASN1_ITEM_start(tname) \ jpayne@69: ASN1_ITYPE_SEQUENCE,\ jpayne@69: V_ASN1_SEQUENCE,\ jpayne@69: tname##_seq_tt,\ jpayne@69: sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ jpayne@69: &tname##_aux,\ jpayne@69: sizeof(stname),\ jpayne@69: #tname \ jpayne@69: ASN1_ITEM_end(tname) jpayne@69: # define static_ASN1_SEQUENCE_END_ref(stname, tname) \ jpayne@69: ;\ jpayne@69: static_ASN1_ITEM_start(tname) \ jpayne@69: ASN1_ITYPE_SEQUENCE,\ jpayne@69: V_ASN1_SEQUENCE,\ jpayne@69: tname##_seq_tt,\ jpayne@69: sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ jpayne@69: &tname##_aux,\ jpayne@69: sizeof(stname),\ jpayne@69: #stname \ jpayne@69: ASN1_ITEM_end(tname) jpayne@69: jpayne@69: # define ASN1_NDEF_SEQUENCE_END_cb(stname, tname) \ jpayne@69: ;\ jpayne@69: ASN1_ITEM_start(tname) \ jpayne@69: ASN1_ITYPE_NDEF_SEQUENCE,\ jpayne@69: V_ASN1_SEQUENCE,\ jpayne@69: tname##_seq_tt,\ jpayne@69: sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ jpayne@69: &tname##_aux,\ jpayne@69: sizeof(stname),\ jpayne@69: #stname \ jpayne@69: ASN1_ITEM_end(tname) jpayne@69: jpayne@69: /*- jpayne@69: * This pair helps declare a CHOICE type. We can do: jpayne@69: * jpayne@69: * ASN1_CHOICE(chname) = { jpayne@69: * ... CHOICE options ... jpayne@69: * ASN1_CHOICE_END(chname) jpayne@69: * jpayne@69: * This will produce an ASN1_ITEM called chname_it jpayne@69: * for a structure called chname. The structure jpayne@69: * definition must look like this: jpayne@69: * typedef struct { jpayne@69: * int type; jpayne@69: * union { jpayne@69: * ASN1_SOMETHING *opt1; jpayne@69: * ASN1_SOMEOTHER *opt2; jpayne@69: * } value; jpayne@69: * } chname; jpayne@69: * jpayne@69: * the name of the selector must be 'type'. jpayne@69: * to use an alternative selector name use the jpayne@69: * ASN1_CHOICE_END_selector() version. jpayne@69: */ jpayne@69: jpayne@69: # define ASN1_CHOICE(tname) \ jpayne@69: static const ASN1_TEMPLATE tname##_ch_tt[] jpayne@69: jpayne@69: # define ASN1_CHOICE_cb(tname, cb) \ jpayne@69: static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ jpayne@69: ASN1_CHOICE(tname) jpayne@69: jpayne@69: # define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname) jpayne@69: jpayne@69: # define static_ASN1_CHOICE_END(stname) static_ASN1_CHOICE_END_name(stname, stname) jpayne@69: jpayne@69: # define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type) jpayne@69: jpayne@69: # define static_ASN1_CHOICE_END_name(stname, tname) static_ASN1_CHOICE_END_selector(stname, tname, type) jpayne@69: jpayne@69: # define ASN1_CHOICE_END_selector(stname, tname, selname) \ jpayne@69: ;\ jpayne@69: ASN1_ITEM_start(tname) \ jpayne@69: ASN1_ITYPE_CHOICE,\ jpayne@69: offsetof(stname,selname) ,\ jpayne@69: tname##_ch_tt,\ jpayne@69: sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ jpayne@69: NULL,\ jpayne@69: sizeof(stname),\ jpayne@69: #stname \ jpayne@69: ASN1_ITEM_end(tname) jpayne@69: jpayne@69: # define static_ASN1_CHOICE_END_selector(stname, tname, selname) \ jpayne@69: ;\ jpayne@69: static_ASN1_ITEM_start(tname) \ jpayne@69: ASN1_ITYPE_CHOICE,\ jpayne@69: offsetof(stname,selname) ,\ jpayne@69: tname##_ch_tt,\ jpayne@69: sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ jpayne@69: NULL,\ jpayne@69: sizeof(stname),\ jpayne@69: #stname \ jpayne@69: ASN1_ITEM_end(tname) jpayne@69: jpayne@69: # define ASN1_CHOICE_END_cb(stname, tname, selname) \ jpayne@69: ;\ jpayne@69: ASN1_ITEM_start(tname) \ jpayne@69: ASN1_ITYPE_CHOICE,\ jpayne@69: offsetof(stname,selname) ,\ jpayne@69: tname##_ch_tt,\ jpayne@69: sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ jpayne@69: &tname##_aux,\ jpayne@69: sizeof(stname),\ jpayne@69: #stname \ jpayne@69: ASN1_ITEM_end(tname) jpayne@69: jpayne@69: /* This helps with the template wrapper form of ASN1_ITEM */ jpayne@69: jpayne@69: # define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \ jpayne@69: (flags), (tag), 0,\ jpayne@69: #name, ASN1_ITEM_ref(type) } jpayne@69: jpayne@69: /* These help with SEQUENCE or CHOICE components */ jpayne@69: jpayne@69: /* used to declare other types */ jpayne@69: jpayne@69: # define ASN1_EX_TYPE(flags, tag, stname, field, type) { \ jpayne@69: (flags), (tag), offsetof(stname, field),\ jpayne@69: #field, ASN1_ITEM_ref(type) } jpayne@69: jpayne@69: /* implicit and explicit helper macros */ jpayne@69: jpayne@69: # define ASN1_IMP_EX(stname, field, type, tag, ex) \ jpayne@69: ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | (ex), tag, stname, field, type) jpayne@69: jpayne@69: # define ASN1_EXP_EX(stname, field, type, tag, ex) \ jpayne@69: ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | (ex), tag, stname, field, type) jpayne@69: jpayne@69: /* Any defined by macros: the field used is in the table itself */ jpayne@69: jpayne@69: # ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION jpayne@69: # define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } jpayne@69: # define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } jpayne@69: # else jpayne@69: # define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb } jpayne@69: # define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb } jpayne@69: # endif jpayne@69: /* Plain simple type */ jpayne@69: # define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type) jpayne@69: /* Embedded simple type */ jpayne@69: # define ASN1_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_EMBED,0, stname, field, type) jpayne@69: jpayne@69: /* OPTIONAL simple type */ jpayne@69: # define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type) jpayne@69: # define ASN1_OPT_EMBED(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL|ASN1_TFLG_EMBED, 0, stname, field, type) jpayne@69: jpayne@69: /* IMPLICIT tagged simple type */ jpayne@69: # define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0) jpayne@69: # define ASN1_IMP_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_EMBED) jpayne@69: jpayne@69: /* IMPLICIT tagged OPTIONAL simple type */ jpayne@69: # define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) jpayne@69: # define ASN1_IMP_OPT_EMBED(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_EMBED) jpayne@69: jpayne@69: /* Same as above but EXPLICIT */ jpayne@69: jpayne@69: # define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0) jpayne@69: # define ASN1_EXP_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_EMBED) jpayne@69: # define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) jpayne@69: # define ASN1_EXP_OPT_EMBED(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_EMBED) jpayne@69: jpayne@69: /* SEQUENCE OF type */ jpayne@69: # define ASN1_SEQUENCE_OF(stname, field, type) \ jpayne@69: ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type) jpayne@69: jpayne@69: /* OPTIONAL SEQUENCE OF */ jpayne@69: # define ASN1_SEQUENCE_OF_OPT(stname, field, type) \ jpayne@69: ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) jpayne@69: jpayne@69: /* Same as above but for SET OF */ jpayne@69: jpayne@69: # define ASN1_SET_OF(stname, field, type) \ jpayne@69: ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type) jpayne@69: jpayne@69: # define ASN1_SET_OF_OPT(stname, field, type) \ jpayne@69: ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) jpayne@69: jpayne@69: /* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */ jpayne@69: jpayne@69: # define ASN1_IMP_SET_OF(stname, field, type, tag) \ jpayne@69: ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) jpayne@69: jpayne@69: # define ASN1_EXP_SET_OF(stname, field, type, tag) \ jpayne@69: ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) jpayne@69: jpayne@69: # define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \ jpayne@69: ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) jpayne@69: jpayne@69: # define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \ jpayne@69: ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) jpayne@69: jpayne@69: # define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \ jpayne@69: ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) jpayne@69: jpayne@69: # define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \ jpayne@69: ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) jpayne@69: jpayne@69: # define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \ jpayne@69: ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) jpayne@69: jpayne@69: # define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \ jpayne@69: ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) jpayne@69: jpayne@69: /* EXPLICIT using indefinite length constructed form */ jpayne@69: # define ASN1_NDEF_EXP(stname, field, type, tag) \ jpayne@69: ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF) jpayne@69: jpayne@69: /* EXPLICIT OPTIONAL using indefinite length constructed form */ jpayne@69: # define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \ jpayne@69: ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF) jpayne@69: jpayne@69: /* Macros for the ASN1_ADB structure */ jpayne@69: jpayne@69: # define ASN1_ADB(name) \ jpayne@69: static const ASN1_ADB_TABLE name##_adbtbl[] jpayne@69: jpayne@69: # ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION jpayne@69: jpayne@69: # define ASN1_ADB_END(name, flags, field, adb_cb, def, none) \ jpayne@69: ;\ jpayne@69: static const ASN1_ADB name##_adb = {\ jpayne@69: flags,\ jpayne@69: offsetof(name, field),\ jpayne@69: adb_cb,\ jpayne@69: name##_adbtbl,\ jpayne@69: sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ jpayne@69: def,\ jpayne@69: none\ jpayne@69: } jpayne@69: jpayne@69: # else jpayne@69: jpayne@69: # define ASN1_ADB_END(name, flags, field, adb_cb, def, none) \ jpayne@69: ;\ jpayne@69: static const ASN1_ITEM *name##_adb(void) \ jpayne@69: { \ jpayne@69: static const ASN1_ADB internal_adb = \ jpayne@69: {\ jpayne@69: flags,\ jpayne@69: offsetof(name, field),\ jpayne@69: adb_cb,\ jpayne@69: name##_adbtbl,\ jpayne@69: sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ jpayne@69: def,\ jpayne@69: none\ jpayne@69: }; \ jpayne@69: return (const ASN1_ITEM *) &internal_adb; \ jpayne@69: } \ jpayne@69: void dummy_function(void) jpayne@69: jpayne@69: # endif jpayne@69: jpayne@69: # define ADB_ENTRY(val, template) {val, template} jpayne@69: jpayne@69: # define ASN1_ADB_TEMPLATE(name) \ jpayne@69: static const ASN1_TEMPLATE name##_tt jpayne@69: jpayne@69: /* jpayne@69: * This is the ASN1 template structure that defines a wrapper round the jpayne@69: * actual type. It determines the actual position of the field in the value jpayne@69: * structure, various flags such as OPTIONAL and the field name. jpayne@69: */ jpayne@69: jpayne@69: struct ASN1_TEMPLATE_st { jpayne@69: unsigned long flags; /* Various flags */ jpayne@69: long tag; /* tag, not used if no tagging */ jpayne@69: unsigned long offset; /* Offset of this field in structure */ jpayne@69: const char *field_name; /* Field name */ jpayne@69: ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */ jpayne@69: }; jpayne@69: jpayne@69: /* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */ jpayne@69: jpayne@69: # define ASN1_TEMPLATE_item(t) (t->item_ptr) jpayne@69: # define ASN1_TEMPLATE_adb(t) (t->item_ptr) jpayne@69: jpayne@69: typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE; jpayne@69: typedef struct ASN1_ADB_st ASN1_ADB; jpayne@69: jpayne@69: struct ASN1_ADB_st { jpayne@69: unsigned long flags; /* Various flags */ jpayne@69: unsigned long offset; /* Offset of selector field */ jpayne@69: int (*adb_cb)(long *psel); /* Application callback */ jpayne@69: const ASN1_ADB_TABLE *tbl; /* Table of possible types */ jpayne@69: long tblcount; /* Number of entries in tbl */ jpayne@69: const ASN1_TEMPLATE *default_tt; /* Type to use if no match */ jpayne@69: const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */ jpayne@69: }; jpayne@69: jpayne@69: struct ASN1_ADB_TABLE_st { jpayne@69: long value; /* NID for an object or value for an int */ jpayne@69: const ASN1_TEMPLATE tt; /* item for this value */ jpayne@69: }; jpayne@69: jpayne@69: /* template flags */ jpayne@69: jpayne@69: /* Field is optional */ jpayne@69: # define ASN1_TFLG_OPTIONAL (0x1) jpayne@69: jpayne@69: /* Field is a SET OF */ jpayne@69: # define ASN1_TFLG_SET_OF (0x1 << 1) jpayne@69: jpayne@69: /* Field is a SEQUENCE OF */ jpayne@69: # define ASN1_TFLG_SEQUENCE_OF (0x2 << 1) jpayne@69: jpayne@69: /* jpayne@69: * Special case: this refers to a SET OF that will be sorted into DER order jpayne@69: * when encoded *and* the corresponding STACK will be modified to match the jpayne@69: * new order. jpayne@69: */ jpayne@69: # define ASN1_TFLG_SET_ORDER (0x3 << 1) jpayne@69: jpayne@69: /* Mask for SET OF or SEQUENCE OF */ jpayne@69: # define ASN1_TFLG_SK_MASK (0x3 << 1) jpayne@69: jpayne@69: /* jpayne@69: * These flags mean the tag should be taken from the tag field. If EXPLICIT jpayne@69: * then the underlying type is used for the inner tag. jpayne@69: */ jpayne@69: jpayne@69: /* IMPLICIT tagging */ jpayne@69: # define ASN1_TFLG_IMPTAG (0x1 << 3) jpayne@69: jpayne@69: /* EXPLICIT tagging, inner tag from underlying type */ jpayne@69: # define ASN1_TFLG_EXPTAG (0x2 << 3) jpayne@69: jpayne@69: # define ASN1_TFLG_TAG_MASK (0x3 << 3) jpayne@69: jpayne@69: /* context specific IMPLICIT */ jpayne@69: # define ASN1_TFLG_IMPLICIT (ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT) jpayne@69: jpayne@69: /* context specific EXPLICIT */ jpayne@69: # define ASN1_TFLG_EXPLICIT (ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT) jpayne@69: jpayne@69: /* jpayne@69: * If tagging is in force these determine the type of tag to use. Otherwise jpayne@69: * the tag is determined by the underlying type. These values reflect the jpayne@69: * actual octet format. jpayne@69: */ jpayne@69: jpayne@69: /* Universal tag */ jpayne@69: # define ASN1_TFLG_UNIVERSAL (0x0<<6) jpayne@69: /* Application tag */ jpayne@69: # define ASN1_TFLG_APPLICATION (0x1<<6) jpayne@69: /* Context specific tag */ jpayne@69: # define ASN1_TFLG_CONTEXT (0x2<<6) jpayne@69: /* Private tag */ jpayne@69: # define ASN1_TFLG_PRIVATE (0x3<<6) jpayne@69: jpayne@69: # define ASN1_TFLG_TAG_CLASS (0x3<<6) jpayne@69: jpayne@69: /* jpayne@69: * These are for ANY DEFINED BY type. In this case the 'item' field points to jpayne@69: * an ASN1_ADB structure which contains a table of values to decode the jpayne@69: * relevant type jpayne@69: */ jpayne@69: jpayne@69: # define ASN1_TFLG_ADB_MASK (0x3<<8) jpayne@69: jpayne@69: # define ASN1_TFLG_ADB_OID (0x1<<8) jpayne@69: jpayne@69: # define ASN1_TFLG_ADB_INT (0x1<<9) jpayne@69: jpayne@69: /* jpayne@69: * This flag when present in a SEQUENCE OF, SET OF or EXPLICIT causes jpayne@69: * indefinite length constructed encoding to be used if required. jpayne@69: */ jpayne@69: jpayne@69: # define ASN1_TFLG_NDEF (0x1<<11) jpayne@69: jpayne@69: /* Field is embedded and not a pointer */ jpayne@69: # define ASN1_TFLG_EMBED (0x1 << 12) jpayne@69: jpayne@69: /* This is the actual ASN1 item itself */ jpayne@69: jpayne@69: struct ASN1_ITEM_st { jpayne@69: char itype; /* The item type, primitive, SEQUENCE, CHOICE jpayne@69: * or extern */ jpayne@69: long utype; /* underlying type */ jpayne@69: const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains jpayne@69: * the contents */ jpayne@69: long tcount; /* Number of templates if SEQUENCE or CHOICE */ jpayne@69: const void *funcs; /* functions that handle this type */ jpayne@69: long size; /* Structure size (usually) */ jpayne@69: const char *sname; /* Structure name */ jpayne@69: }; jpayne@69: jpayne@69: /*- jpayne@69: * These are values for the itype field and jpayne@69: * determine how the type is interpreted. jpayne@69: * jpayne@69: * For PRIMITIVE types the underlying type jpayne@69: * determines the behaviour if items is NULL. jpayne@69: * jpayne@69: * Otherwise templates must contain a single jpayne@69: * template and the type is treated in the jpayne@69: * same way as the type specified in the template. jpayne@69: * jpayne@69: * For SEQUENCE types the templates field points jpayne@69: * to the members, the size field is the jpayne@69: * structure size. jpayne@69: * jpayne@69: * For CHOICE types the templates field points jpayne@69: * to each possible member (typically a union) jpayne@69: * and the 'size' field is the offset of the jpayne@69: * selector. jpayne@69: * jpayne@69: * The 'funcs' field is used for application jpayne@69: * specific functions. jpayne@69: * jpayne@69: * The EXTERN type uses a new style d2i/i2d. jpayne@69: * The new style should be used where possible jpayne@69: * because it avoids things like the d2i IMPLICIT jpayne@69: * hack. jpayne@69: * jpayne@69: * MSTRING is a multiple string type, it is used jpayne@69: * for a CHOICE of character strings where the jpayne@69: * actual strings all occupy an ASN1_STRING jpayne@69: * structure. In this case the 'utype' field jpayne@69: * has a special meaning, it is used as a mask jpayne@69: * of acceptable types using the B_ASN1 constants. jpayne@69: * jpayne@69: * NDEF_SEQUENCE is the same as SEQUENCE except jpayne@69: * that it will use indefinite length constructed jpayne@69: * encoding if requested. jpayne@69: * jpayne@69: */ jpayne@69: jpayne@69: # define ASN1_ITYPE_PRIMITIVE 0x0 jpayne@69: jpayne@69: # define ASN1_ITYPE_SEQUENCE 0x1 jpayne@69: jpayne@69: # define ASN1_ITYPE_CHOICE 0x2 jpayne@69: jpayne@69: # define ASN1_ITYPE_EXTERN 0x4 jpayne@69: jpayne@69: # define ASN1_ITYPE_MSTRING 0x5 jpayne@69: jpayne@69: # define ASN1_ITYPE_NDEF_SEQUENCE 0x6 jpayne@69: jpayne@69: /* jpayne@69: * Cache for ASN1 tag and length, so we don't keep re-reading it for things jpayne@69: * like CHOICE jpayne@69: */ jpayne@69: jpayne@69: struct ASN1_TLC_st { jpayne@69: char valid; /* Values below are valid */ jpayne@69: int ret; /* return value */ jpayne@69: long plen; /* length */ jpayne@69: int ptag; /* class value */ jpayne@69: int pclass; /* class value */ jpayne@69: int hdrlen; /* header length */ jpayne@69: }; jpayne@69: jpayne@69: /* Typedefs for ASN1 function pointers */ jpayne@69: typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, jpayne@69: const ASN1_ITEM *it, int tag, int aclass, char opt, jpayne@69: ASN1_TLC *ctx); jpayne@69: jpayne@69: typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, jpayne@69: const ASN1_ITEM *it, int tag, int aclass); jpayne@69: typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it); jpayne@69: typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); jpayne@69: jpayne@69: typedef int ASN1_ex_print_func(BIO *out, ASN1_VALUE **pval, jpayne@69: int indent, const char *fname, jpayne@69: const ASN1_PCTX *pctx); jpayne@69: jpayne@69: typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, jpayne@69: int *putype, const ASN1_ITEM *it); jpayne@69: typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, jpayne@69: int len, int utype, char *free_cont, jpayne@69: const ASN1_ITEM *it); jpayne@69: typedef int ASN1_primitive_print(BIO *out, ASN1_VALUE **pval, jpayne@69: const ASN1_ITEM *it, int indent, jpayne@69: const ASN1_PCTX *pctx); jpayne@69: jpayne@69: typedef struct ASN1_EXTERN_FUNCS_st { jpayne@69: void *app_data; jpayne@69: ASN1_ex_new_func *asn1_ex_new; jpayne@69: ASN1_ex_free_func *asn1_ex_free; jpayne@69: ASN1_ex_free_func *asn1_ex_clear; jpayne@69: ASN1_ex_d2i *asn1_ex_d2i; jpayne@69: ASN1_ex_i2d *asn1_ex_i2d; jpayne@69: ASN1_ex_print_func *asn1_ex_print; jpayne@69: } ASN1_EXTERN_FUNCS; jpayne@69: jpayne@69: typedef struct ASN1_PRIMITIVE_FUNCS_st { jpayne@69: void *app_data; jpayne@69: unsigned long flags; jpayne@69: ASN1_ex_new_func *prim_new; jpayne@69: ASN1_ex_free_func *prim_free; jpayne@69: ASN1_ex_free_func *prim_clear; jpayne@69: ASN1_primitive_c2i *prim_c2i; jpayne@69: ASN1_primitive_i2c *prim_i2c; jpayne@69: ASN1_primitive_print *prim_print; jpayne@69: } ASN1_PRIMITIVE_FUNCS; jpayne@69: jpayne@69: /* jpayne@69: * This is the ASN1_AUX structure: it handles various miscellaneous jpayne@69: * requirements. For example the use of reference counts and an informational jpayne@69: * callback. The "informational callback" is called at various points during jpayne@69: * the ASN1 encoding and decoding. It can be used to provide minor jpayne@69: * customisation of the structures used. This is most useful where the jpayne@69: * supplied routines *almost* do the right thing but need some extra help at jpayne@69: * a few points. If the callback returns zero then it is assumed a fatal jpayne@69: * error has occurred and the main operation should be abandoned. If major jpayne@69: * changes in the default behaviour are required then an external type is jpayne@69: * more appropriate. jpayne@69: */ jpayne@69: jpayne@69: typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it, jpayne@69: void *exarg); jpayne@69: jpayne@69: typedef struct ASN1_AUX_st { jpayne@69: void *app_data; jpayne@69: int flags; jpayne@69: int ref_offset; /* Offset of reference value */ jpayne@69: int ref_lock; /* Lock type to use */ jpayne@69: ASN1_aux_cb *asn1_cb; jpayne@69: int enc_offset; /* Offset of ASN1_ENCODING structure */ jpayne@69: } ASN1_AUX; jpayne@69: jpayne@69: /* For print related callbacks exarg points to this structure */ jpayne@69: typedef struct ASN1_PRINT_ARG_st { jpayne@69: BIO *out; jpayne@69: int indent; jpayne@69: const ASN1_PCTX *pctx; jpayne@69: } ASN1_PRINT_ARG; jpayne@69: jpayne@69: /* For streaming related callbacks exarg points to this structure */ jpayne@69: typedef struct ASN1_STREAM_ARG_st { jpayne@69: /* BIO to stream through */ jpayne@69: BIO *out; jpayne@69: /* BIO with filters appended */ jpayne@69: BIO *ndef_bio; jpayne@69: /* Streaming I/O boundary */ jpayne@69: unsigned char **boundary; jpayne@69: } ASN1_STREAM_ARG; jpayne@69: jpayne@69: /* Flags in ASN1_AUX */ jpayne@69: jpayne@69: /* Use a reference count */ jpayne@69: # define ASN1_AFLG_REFCOUNT 1 jpayne@69: /* Save the encoding of structure (useful for signatures) */ jpayne@69: # define ASN1_AFLG_ENCODING 2 jpayne@69: /* The Sequence length is invalid */ jpayne@69: # define ASN1_AFLG_BROKEN 4 jpayne@69: jpayne@69: /* operation values for asn1_cb */ jpayne@69: jpayne@69: # define ASN1_OP_NEW_PRE 0 jpayne@69: # define ASN1_OP_NEW_POST 1 jpayne@69: # define ASN1_OP_FREE_PRE 2 jpayne@69: # define ASN1_OP_FREE_POST 3 jpayne@69: # define ASN1_OP_D2I_PRE 4 jpayne@69: # define ASN1_OP_D2I_POST 5 jpayne@69: # define ASN1_OP_I2D_PRE 6 jpayne@69: # define ASN1_OP_I2D_POST 7 jpayne@69: # define ASN1_OP_PRINT_PRE 8 jpayne@69: # define ASN1_OP_PRINT_POST 9 jpayne@69: # define ASN1_OP_STREAM_PRE 10 jpayne@69: # define ASN1_OP_STREAM_POST 11 jpayne@69: # define ASN1_OP_DETACHED_PRE 12 jpayne@69: # define ASN1_OP_DETACHED_POST 13 jpayne@69: jpayne@69: /* Macro to implement a primitive type */ jpayne@69: # define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0) jpayne@69: # define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \ jpayne@69: ASN1_ITEM_start(itname) \ jpayne@69: ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \ jpayne@69: ASN1_ITEM_end(itname) jpayne@69: jpayne@69: /* Macro to implement a multi string type */ jpayne@69: # define IMPLEMENT_ASN1_MSTRING(itname, mask) \ jpayne@69: ASN1_ITEM_start(itname) \ jpayne@69: ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \ jpayne@69: ASN1_ITEM_end(itname) jpayne@69: jpayne@69: # define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \ jpayne@69: ASN1_ITEM_start(sname) \ jpayne@69: ASN1_ITYPE_EXTERN, \ jpayne@69: tag, \ jpayne@69: NULL, \ jpayne@69: 0, \ jpayne@69: &fptrs, \ jpayne@69: 0, \ jpayne@69: #sname \ jpayne@69: ASN1_ITEM_end(sname) jpayne@69: jpayne@69: /* Macro to implement standard functions in terms of ASN1_ITEM structures */ jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname) jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname) jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ jpayne@69: IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname) jpayne@69: jpayne@69: # define IMPLEMENT_STATIC_ASN1_ALLOC_FUNCTIONS(stname) \ jpayne@69: IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(static, stname, stname, stname) jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \ jpayne@69: IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname) jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_pfname(pre, stname, itname, fname) \ jpayne@69: pre stname *fname##_new(void) \ jpayne@69: { \ jpayne@69: return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ jpayne@69: } \ jpayne@69: pre void fname##_free(stname *a) \ jpayne@69: { \ jpayne@69: ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ jpayne@69: } jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ jpayne@69: stname *fname##_new(void) \ jpayne@69: { \ jpayne@69: return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ jpayne@69: } \ jpayne@69: void fname##_free(stname *a) \ jpayne@69: { \ jpayne@69: ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ jpayne@69: } jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \ jpayne@69: IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ jpayne@69: IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ jpayne@69: stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ jpayne@69: { \ jpayne@69: return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ jpayne@69: } \ jpayne@69: int i2d_##fname(stname *a, unsigned char **out) \ jpayne@69: { \ jpayne@69: return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ jpayne@69: } jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \ jpayne@69: int i2d_##stname##_NDEF(stname *a, unsigned char **out) \ jpayne@69: { \ jpayne@69: return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\ jpayne@69: } jpayne@69: jpayne@69: # define IMPLEMENT_STATIC_ASN1_ENCODE_FUNCTIONS(stname) \ jpayne@69: static stname *d2i_##stname(stname **a, \ jpayne@69: const unsigned char **in, long len) \ jpayne@69: { \ jpayne@69: return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, \ jpayne@69: ASN1_ITEM_rptr(stname)); \ jpayne@69: } \ jpayne@69: static int i2d_##stname(stname *a, unsigned char **out) \ jpayne@69: { \ jpayne@69: return ASN1_item_i2d((ASN1_VALUE *)a, out, \ jpayne@69: ASN1_ITEM_rptr(stname)); \ jpayne@69: } jpayne@69: jpayne@69: /* jpayne@69: * This includes evil casts to remove const: they will go away when full ASN1 jpayne@69: * constification is done. jpayne@69: */ jpayne@69: # define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ jpayne@69: stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ jpayne@69: { \ jpayne@69: return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ jpayne@69: } \ jpayne@69: int i2d_##fname(const stname *a, unsigned char **out) \ jpayne@69: { \ jpayne@69: return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ jpayne@69: } jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ jpayne@69: stname * stname##_dup(stname *x) \ jpayne@69: { \ jpayne@69: return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \ jpayne@69: } jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \ jpayne@69: IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname) jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \ jpayne@69: int fname##_print_ctx(BIO *out, stname *x, int indent, \ jpayne@69: const ASN1_PCTX *pctx) \ jpayne@69: { \ jpayne@69: return ASN1_item_print(out, (ASN1_VALUE *)x, indent, \ jpayne@69: ASN1_ITEM_rptr(itname), pctx); \ jpayne@69: } jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_FUNCTIONS_const(name) \ jpayne@69: IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name) jpayne@69: jpayne@69: # define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \ jpayne@69: IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ jpayne@69: IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) jpayne@69: jpayne@69: /* external definitions for primitive types */ jpayne@69: jpayne@69: DECLARE_ASN1_ITEM(ASN1_BOOLEAN) jpayne@69: DECLARE_ASN1_ITEM(ASN1_TBOOLEAN) jpayne@69: DECLARE_ASN1_ITEM(ASN1_FBOOLEAN) jpayne@69: DECLARE_ASN1_ITEM(ASN1_SEQUENCE) jpayne@69: DECLARE_ASN1_ITEM(CBIGNUM) jpayne@69: DECLARE_ASN1_ITEM(BIGNUM) jpayne@69: DECLARE_ASN1_ITEM(INT32) jpayne@69: DECLARE_ASN1_ITEM(ZINT32) jpayne@69: DECLARE_ASN1_ITEM(UINT32) jpayne@69: DECLARE_ASN1_ITEM(ZUINT32) jpayne@69: DECLARE_ASN1_ITEM(INT64) jpayne@69: DECLARE_ASN1_ITEM(ZINT64) jpayne@69: DECLARE_ASN1_ITEM(UINT64) jpayne@69: DECLARE_ASN1_ITEM(ZUINT64) jpayne@69: jpayne@69: # if OPENSSL_API_COMPAT < 0x10200000L jpayne@69: /* jpayne@69: * LONG and ZLONG are strongly discouraged for use as stored data, as the jpayne@69: * underlying C type (long) differs in size depending on the architecture. jpayne@69: * They are designed with 32-bit longs in mind. jpayne@69: */ jpayne@69: DECLARE_ASN1_ITEM(LONG) jpayne@69: DECLARE_ASN1_ITEM(ZLONG) jpayne@69: # endif jpayne@69: jpayne@69: DEFINE_STACK_OF(ASN1_VALUE) jpayne@69: jpayne@69: /* Functions used internally by the ASN1 code */ jpayne@69: jpayne@69: int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it); jpayne@69: void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it); jpayne@69: jpayne@69: int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, jpayne@69: const ASN1_ITEM *it, int tag, int aclass, char opt, jpayne@69: ASN1_TLC *ctx); jpayne@69: jpayne@69: int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, jpayne@69: const ASN1_ITEM *it, int tag, int aclass); jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } jpayne@69: #endif jpayne@69: #endif