📄 asn1t.h
字号:
/* asn1t.h *//* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL * project 2000. *//* ==================================================================== * Copyright (c) 2000 The OpenSSL Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" * * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * licensing@OpenSSL.org. * * 5. Products derived from this software may not be called "OpenSSL" * nor may "OpenSSL" appear in their names without prior written * permission of the OpenSSL Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" * * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This product includes cryptographic software written by Eric Young * (eay@cryptsoft.com). This product includes software written by Tim * Hudson (tjh@cryptsoft.com). * */#ifndef HEADER_ASN1T_H#define HEADER_ASN1T_H#include <stddef.h>#include <openssl/e_os2.h>#include <openssl/asn1.h>#ifdef OPENSSL_BUILD_SHLIBCRYPTO# undef OPENSSL_EXTERN# define OPENSSL_EXTERN OPENSSL_EXPORT#endif/* ASN1 template defines, structures and functions */#ifdef __cplusplusextern "C" {#endif#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr))/* Macros for start and end of ASN1_ITEM definition */#define ASN1_ITEM_start(itname) \ OPENSSL_GLOBAL const ASN1_ITEM itname##_it = {#define ASN1_ITEM_end(itname) \ };#else/* Macro to obtain ASN1_ADB pointer from a type (only used internally) */#define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr()))/* Macros for start and end of ASN1_ITEM definition */#define ASN1_ITEM_start(itname) \ const ASN1_ITEM * itname##_it(void) \ { \ static const ASN1_ITEM local_it = { \#define ASN1_ITEM_end(itname) \ }; \ return &local_it; \ }#endif/* Macros to aid ASN1 template writing */#define ASN1_ITEM_TEMPLATE(tname) \ const static ASN1_TEMPLATE tname##_item_tt #define ASN1_ITEM_TEMPLATE_END(tname) \ ;\ ASN1_ITEM_start(tname) \ ASN1_ITYPE_PRIMITIVE,\ -1,\ &tname##_item_tt,\ 0,\ NULL,\ 0,\ #tname \ ASN1_ITEM_end(tname)/* This is a ASN1 type which just embeds a template */ /* This pair helps declare a SEQUENCE. We can do: * * ASN1_SEQUENCE(stname) = { * ... SEQUENCE components ... * } ASN1_SEQUENCE_END(stname) * * This will produce an ASN1_ITEM called stname_it * for a structure called stname. * * If you want the same structure but a different * name then use: * * ASN1_SEQUENCE(itname) = { * ... SEQUENCE components ... * } ASN1_SEQUENCE_END_name(stname, itname) * * This will create an item called itname_it using * a structure called stname. */#define ASN1_SEQUENCE(tname) \ const static ASN1_TEMPLATE tname##_seq_tt[] #define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)#define ASN1_SEQUENCE_END_name(stname, tname) \ ;\ ASN1_ITEM_start(tname) \ ASN1_ITYPE_SEQUENCE,\ V_ASN1_SEQUENCE,\ tname##_seq_tt,\ sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ NULL,\ sizeof(stname),\ #stname \ ASN1_ITEM_end(tname)#define ASN1_SEQUENCE_cb(tname, cb) \ const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ ASN1_SEQUENCE(tname)#define ASN1_BROKEN_SEQUENCE(tname) \ const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \ ASN1_SEQUENCE(tname)#define ASN1_SEQUENCE_ref(tname, cb, lck) \ const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \ ASN1_SEQUENCE(tname)#define ASN1_SEQUENCE_enc(tname, enc, cb) \ const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \ ASN1_SEQUENCE(tname)#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)#define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)#define ASN1_SEQUENCE_END_ref(stname, tname) \ ;\ ASN1_ITEM_start(tname) \ ASN1_ITYPE_SEQUENCE,\ V_ASN1_SEQUENCE,\ tname##_seq_tt,\ sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ &tname##_aux,\ sizeof(stname),\ #stname \ ASN1_ITEM_end(tname)/* This pair helps declare a CHOICE type. We can do: * * ASN1_CHOICE(chname) = { * ... CHOICE options ... * ASN1_CHOICE_END(chname) * * This will produce an ASN1_ITEM called chname_it * for a structure called chname. The structure * definition must look like this: * typedef struct { * int type; * union { * ASN1_SOMETHING *opt1; * ASN1_SOMEOTHER *opt2; * } value; * } chname; * * the name of the selector must be 'type'. * to use an alternative selector name use the * ASN1_CHOICE_END_selector() version. */#define ASN1_CHOICE(tname) \ const static ASN1_TEMPLATE tname##_ch_tt[] #define ASN1_CHOICE_cb(tname, cb) \ const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ ASN1_CHOICE(tname)#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)#define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type)#define ASN1_CHOICE_END_selector(stname, tname, selname) \ ;\ ASN1_ITEM_start(tname) \ ASN1_ITYPE_CHOICE,\ offsetof(stname,selname) ,\ tname##_ch_tt,\ sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ NULL,\ sizeof(stname),\ #stname \ ASN1_ITEM_end(tname)#define ASN1_CHOICE_END_cb(stname, tname, selname) \ ;\ ASN1_ITEM_start(tname) \ ASN1_ITYPE_CHOICE,\ offsetof(stname,selname) ,\ tname##_ch_tt,\ sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ &tname##_aux,\ sizeof(stname),\ #stname \ ASN1_ITEM_end(tname)/* This helps with the template wrapper form of ASN1_ITEM */#define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \ (flags), (tag), 0,\ #name, ASN1_ITEM_ref(type) }/* These help with SEQUENCE or CHOICE components *//* used to declare other types */#define ASN1_EX_TYPE(flags, tag, stname, field, type) { \ (flags), (tag), offsetof(stname, field),\ #field, ASN1_ITEM_ref(type) }/* used when the structure is combined with the parent */#define ASN1_EX_COMBINE(flags, tag, type) { \ (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) }/* implicit and explicit helper macros */#define ASN1_IMP_EX(stname, field, type, tag, ex) \ ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type)#define ASN1_EXP_EX(stname, field, type, tag, ex) \ ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type)/* Any defined by macros: the field used is in the table itself */#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }#else#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb }#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb }#endif/* Plain simple type */#define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)/* OPTIONAL simple type */#define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type)/* IMPLICIT tagged simple type */#define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0)/* IMPLICIT tagged OPTIONAL simple type */#define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)/* Same as above but EXPLICIT */#define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0)#define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL)/* SEQUENCE OF type */#define ASN1_SEQUENCE_OF(stname, field, type) \ ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type)/* OPTIONAL SEQUENCE OF */#define ASN1_SEQUENCE_OF_OPT(stname, field, type) \ ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)/* Same as above but for SET OF */#define ASN1_SET_OF(stname, field, type) \ ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type)#define ASN1_SET_OF_OPT(stname, field, type) \ ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type)/* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */#define ASN1_IMP_SET_OF(stname, field, type, tag) \ ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)#define ASN1_EXP_SET_OF(stname, field, type, tag) \ ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF)#define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \ ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)#define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \ ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL)#define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \ ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)#define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \ ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)#define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \ ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF)#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \ ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)/* Macros for the ASN1_ADB structure */#define ASN1_ADB(name) \ const static ASN1_ADB_TABLE name##_adbtbl[] #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION#define ASN1_ADB_END(name, flags, field, app_table, def, none) \ ;\ const static ASN1_ADB name##_adb = {\ flags,\ offsetof(name, field),\ app_table,\ name##_adbtbl,\ sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ def,\ none\ }#else#define ASN1_ADB_END(name, flags, field, app_table, def, none) \ ;\ const static ASN1_ITEM *name##_adb(void) \ { \ const static ASN1_ADB internal_adb = \ {\ flags,\ offsetof(name, field),\ app_table,\ name##_adbtbl,\ sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ def,\ none\ }; \ return (const ASN1_ITEM *) &internal_adb; \ } \ void dummy_function(void)#endif#define ADB_ENTRY(val, template) {val, template}#define ASN1_ADB_TEMPLATE(name) \ const static ASN1_TEMPLATE name##_tt /* This is the ASN1 template structure that defines * a wrapper round the actual type. It determines the * actual position of the field in the value structure, * various flags such as OPTIONAL and the field name. */struct ASN1_TEMPLATE_st {unsigned long flags; /* Various flags */long tag; /* tag, not used if no tagging */unsigned long offset; /* Offset of this field in structure */#ifndef NO_ASN1_FIELD_NAMESchar *field_name; /* Field name */#endifASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */};/* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */#define ASN1_TEMPLATE_item(t) (t->item_ptr)#define ASN1_TEMPLATE_adb(t) (t->item_ptr)typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;typedef struct ASN1_ADB_st ASN1_ADB;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -