8 #ifndef ARC_VOMSATTRIBUTE_H 
    9 #define ARC_VOMSATTRIBUTE_H 
   11 #include <openssl/opensslv.h> 
   13 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L) 
   15 #include <openssl/safestack.h> 
   16 #undef SKM_ASN1_SET_OF_d2i 
   17 #define SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ 
   18   (STACK_OF(type) *)d2i_ASN1_SET((STACK_OF(OPENSSL_BLOCK) **)CHECKED_PTR_OF(STACK_OF(type)*, st), \ 
   20                                 CHECKED_D2I_OF(type, d2i_func), \ 
   21                                 CHECKED_SK_FREE_FUNC(type, free_func), \ 
   23 #undef SKM_ASN1_SET_OF_i2d 
   24 #define SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \ 
   25   i2d_ASN1_SET((STACK_OF(OPENSSL_BLOCK) *)CHECKED_STACK_OF(type, st), pp, \ 
   26                                 CHECKED_I2D_OF(type, i2d_func), \ 
   27                                 ex_tag, ex_class, is_set) 
   30 #include <openssl/evp.h> 
   31 #include <openssl/asn1_mac.h> 
   32 #include <openssl/x509.h> 
   33 #include <openssl/x509v3.h> 
   34 #include <openssl/stack.h> 
   35 #include <openssl/safestack.h> 
   36 #include <openssl/err.h> 
   38 #define VOMS_AC_HEADER "-----BEGIN VOMS AC-----" 
   39 #define VOMS_AC_TRAILER "-----END VOMS AC-----" 
   41 namespace ArcCredential {
 
   43 #define ASN1_F_D2I_AC_ATTR          5000 
   44 #define AC_F_ATTR_New               5001 
   45 #define ASN1_F_D2I_AC_ROLE          5002 
   46 #define AC_F_ROLE_New               5003 
   47 #define ASN1_F_D2I_AC_IETFATTR      5004 
   48 #define AC_F_IETFATTR_New           5005 
   49 #define ASN1_F_D2I_AC_IETFATTRVAL   5006 
   50 #define ASN1_F_D2I_AC_DIGEST        5007 
   51 #define AC_F_DIGEST_New             5008 
   52 #define ASN1_F_D2I_AC_IS            5009 
   53 #define AC_F_AC_IS_New              5010 
   54 #define ASN1_F_D2I_AC_FORM          5011 
   55 #define AC_F_AC_FORM_New            5012 
   56 #define ASN1_F_D2I_AC_ACI           5013 
   57 #define ASN1_F_AC_ACI_New           5014 
   58 #define ASN1_F_D2I_AC_HOLDER        5015 
   59 #define ASN1_F_AC_HOLDER_New        5016 
   60 #define ASN1_F_AC_VAL_New           5017 
   61 #define AC_F_AC_INFO_NEW            5018 
   62 #define AC_F_D2I_AC                 5019 
   63 #define AC_F_AC_New                 5020 
   64 #define ASN1_F_I2D_AC_IETFATTRVAL   5021 
   65 #define AC_F_D2I_AC_DIGEST          5022 
   66 #define AC_F_AC_DIGEST_New          5023 
   67 #define AC_F_D2I_AC_IS              5024 
   68 #define AC_ERR_UNSET                5025 
   69 #define AC_ERR_SET                  5026 
   70 #define AC_ERR_SIGNATURE            5027 
   71 #define AC_ERR_VERSION              5028 
   72 #define AC_ERR_HOLDER_SERIAL        5029 
   73 #define AC_ERR_HOLDER               5030 
   74 #define AC_ERR_UID_MISMATCH         5031 
   75 #define AC_ERR_ISSUER_NAME          5032 
   76 #define AC_ERR_SERIAL               5033 
   77 #define AC_ERR_DATES                5034 
   78 #define AC_ERR_ATTRIBS              5035 
   79 #define AC_F_AC_TARGET_New          5036 
   80 #define ASN1_F_D2I_AC_TARGET        5037 
   81 #define AC_F_AC_TARGETS_New         5036 
   82 #define ASN1_F_D2I_AC_TARGETS       5037 
   83 #define ASN1_F_D2I_AC_SEQ           5038 
   84 #define AC_F_AC_SEQ_new             5039 
   85 #define AC_ERR_ATTRIB_URI           5040 
   86 #define AC_ERR_ATTRIB_FQAN          5041 
   87 #define AC_ERR_EXTS_ABSENT          5042 
   88 #define AC_ERR_MEMORY               5043 
   89 #define AC_ERR_EXT_CRIT             5044 
   90 #define AC_ERR_EXT_TARGET           5045 
   91 #define AC_ERR_EXT_KEY              5046 
   92 #define AC_ERR_UNKNOWN              5047 
   94 #define AC_ERR_PARAMETERS           5048 
   95 #define X509_ERR_ISSUER_NAME        5049 
   96 #define X509_ERR_HOLDER_NAME        5050 
   97 #define AC_ERR_NO_EXTENSION         5051 
   99 #define ASN1_F_D2I_AC_CERTS         5052 
  100 #define AC_F_X509_New               5053 
  102 #define AC_F_D2I_AC_ATTRIBUTE       5054 
  103 #define AC_F_ATTRIBUTE_New          5055 
  104 #define ASN1_F_D2I_AC_ATT_HOLDER    5056 
  105 #define AC_F_AC_ATT_HOLDER_New      5057 
  106 #define ASN1_F_D2I_AC_FULL_ATTRIBUTES 5058 
  107 #define AC_F_AC_FULL_ATTRIBUTES_New 5059 
  108 #define ASN1_F_D2I_AC_ATTRIBUTEVAL  5060 
  109 #define ASN1_F_I2D_AC_ATTRIBUTEVAL  5061 
  110 #define AC_F_AC_ATTRIBUTEVAL_New    5062 
  111 #define AC_ERR_ATTRIB               5063 
  113 typedef struct ACDIGEST {
 
  114   ASN1_ENUMERATED *type;
 
  117   ASN1_BIT_STRING *digest;
 
  120 typedef struct ACIS {
 
  121   STACK_OF(GENERAL_NAME) *issuer;
 
  122   ASN1_INTEGER  *serial;
 
  123   ASN1_BIT_STRING *uid;
 
  126 typedef struct ACFORM {
 
  127   STACK_OF(GENERAL_NAME) *names;
 
  132 typedef struct ACACI {
 
  133   STACK_OF(GENERAL_NAME) *names;
 
  137 typedef struct ACHOLDER {
 
  139   STACK_OF(GENERAL_NAME) *name;
 
  143 typedef struct ACVAL {
 
  144   ASN1_GENERALIZEDTIME *notBefore;
 
  145   ASN1_GENERALIZEDTIME *notAfter;
 
  148 typedef struct asn1_string_st AC_IETFATTRVAL;
 
  150 typedef struct ACIETFATTR {
 
  151   STACK_OF(GENERAL_NAME)   *names;
 
  152   STACK_OF(AC_IETFATTRVAL) *values;
 
  155 typedef struct ACTARGET {
 
  161 typedef struct ACTARGETS {
 
  162   STACK_OF(AC_TARGET) *targets;
 
  165 typedef struct ACATTR {
 
  168   STACK_OF(AC_IETFATTR) *ietfattr;
 
  169   STACK_OF(AC_FULL_ATTRIBUTES) *fullattributes;
 
  171 #define GET_TYPE_FQAN 1 
  172 #define GET_TYPE_ATTRIBUTES 2 
  174 typedef struct ACINFO {
 
  175   ASN1_INTEGER             *version;
 
  179   ASN1_INTEGER             *serial;
 
  181   STACK_OF(AC_ATTR)        *attrib;
 
  183   STACK_OF(X509_EXTENSION) *exts;
 
  189   ASN1_BIT_STRING *signature;
 
  192 typedef struct ACSEQ {
 
  196 typedef struct ACCERTS {
 
  197   STACK_OF(X509) *stackcert;
 
  200 typedef struct ACATTRIBUTE {
 
  201   ASN1_OCTET_STRING *name;
 
  202   ASN1_OCTET_STRING *qualifier;
 
  203   ASN1_OCTET_STRING *value;
 
  206 typedef struct ACATTHOLDER {
 
  207   STACK_OF(GENERAL_NAME) *grantor;
 
  208   STACK_OF(AC_ATTRIBUTE) *attributes;
 
  211 typedef struct ACFULLATTRIBUTES {
 
  212   STACK_OF(AC_ATT_HOLDER) *providers;
 
  213 } AC_FULL_ATTRIBUTES;
 
  215 #if (OPENSSL_VERSION_NUMBER >= 0x10000000L) 
  216 #define IMPL_STACK(type)                                                \ 
  217   DECLARE_STACK_OF(type)                                                \ 
  218   STACK_OF(type) *sk_##type##_new (int (*cmp)(const type * const *,     \ 
  219                                               const type * const *))    \ 
  220     { return (STACK_OF(type) *)sk_new(CHECKED_SK_CMP_FUNC(type, cmp));}                 \ 
  221   STACK_OF(type) *sk_##type##_new_null () { return (STACK_OF(type) *)sk_new_null(); }   \ 
  222   void   sk_##type##_free (STACK_OF(type) *st) { sk_free(CHECKED_STACK_OF(type, st)); } \ 
  223   int    sk_##type##_num (const STACK_OF(type) *st) { return sk_num(CHECKED_STACK_OF(type, st)); } \ 
  224   type  *sk_##type##_value (const STACK_OF(type) *st, int i) { return (type *)sk_value(CHECKED_STACK_OF(type, st), i); } \ 
  225   type  *sk_##type##_set (STACK_OF(type) *st, int i, type *val) { return (type *)sk_set(CHECKED_STACK_OF(type, st), i, CHECKED_PTR_OF(type, val)); } \ 
  226   void   sk_##type##_zero (STACK_OF(type) *st) { sk_zero(CHECKED_STACK_OF(type, st)); } \ 
  227   int    sk_##type##_push (STACK_OF(type) *st, type *val) { return sk_push(CHECKED_STACK_OF(type, st), CHECKED_PTR_OF(type, val)); } \ 
  228   int    sk_##type##_unshift (STACK_OF(type) *st, type *val) { return sk_unshift(CHECKED_STACK_OF(type, st), CHECKED_PTR_OF(type, val)); } \ 
  229   int    sk_##type##_find (STACK_OF(type) *st, type *val) { return sk_find(CHECKED_STACK_OF(type, st), CHECKED_PTR_OF(type, val)); } \ 
  230   type  *sk_##type##_delete (STACK_OF(type) *st, int i) { return (type *)sk_delete(CHECKED_STACK_OF(type, st), i); } \ 
  231   type  *sk_##type##_delete_ptr (STACK_OF(type) *st, type *ptr) { return (type *)sk_delete_ptr(CHECKED_STACK_OF(type, st), CHECKED_PTR_OF(type, ptr)); } \ 
  232   int    sk_##type##_insert (STACK_OF(type) *st, type *val, int i) { return sk_insert(CHECKED_STACK_OF(type, st), CHECKED_PTR_OF(type, val), i); } \ 
  233   int (*sk_##type##_set_cmp_func (STACK_OF(type) *st, int (*cmp)(const type * const *, const type * const *)))(const type * const *, const type * const *) \ 
  234     { return (int ((*)(const type * const *, const type * const *)))sk_set_cmp_func(CHECKED_STACK_OF(type, st), CHECKED_SK_CMP_FUNC(type, cmp)); } \ 
  235   STACK_OF(type) *sk_##type##_dup (STACK_OF(type) *st) { return (STACK_OF(type) *)sk_dup(CHECKED_STACK_OF(type, st)); } \ 
  236   void   sk_##type##_pop_free (STACK_OF(type) *st, void (*func)(type *)) { sk_pop_free(CHECKED_STACK_OF(type, st), CHECKED_SK_FREE_FUNC(type, func)); } \ 
  237   type  *sk_##type##_shift (STACK_OF(type) *st) { return (type *)sk_shift(CHECKED_STACK_OF(type, st)); } \ 
  238   type  *sk_##type##_pop (STACK_OF(type) *st) { return (type *)sk_pop(CHECKED_STACK_OF(type, st)); } \ 
  239   void   sk_##type##_sort (STACK_OF(type) *st) { sk_sort(CHECKED_STACK_OF(type, st)); }         \ 
  240   STACK_OF(type) *d2i_ASN1_SET_OF_##type (STACK_OF(type) **st, const unsigned char **pp, long length, type *(*d2ifunc)(type**, const unsigned char**, long), void (*freefunc)(type *), int ex_tag, int ex_class) \ 
  241     { return (STACK_OF(type) *)d2i_ASN1_SET((STACK_OF(OPENSSL_BLOCK)**)CHECKED_PTR_OF(STACK_OF(type)*, st), \ 
  243                                 CHECKED_D2I_OF(type, d2ifunc), \ 
  244                                 CHECKED_SK_FREE_FUNC(type, freefunc), \ 
  245                                 ex_tag, ex_class); } \ 
  246   int i2d_ASN1_SET_OF_##type (STACK_OF(type) *st, unsigned char **pp, int (*i2dfunc)(type*, unsigned char**), int ex_tag, int ex_class, int is_set) \ 
  247   { return i2d_ASN1_SET((STACK_OF(OPENSSL_BLOCK)*)CHECKED_STACK_OF(type, st), pp, \ 
  248                                 CHECKED_I2D_OF(type, i2dfunc), \ 
  249                                 ex_tag, ex_class, is_set); }    \ 
  250   unsigned char *ASN1_seq_pack_##type (STACK_OF(type) *st, int (*i2dfunc)(type*, unsigned char**), unsigned char **buf, int *len) { return ASN1_seq_pack((STACK_OF(OPENSSL_BLOCK)*)CHECKED_PTR_OF(STACK_OF(type), st), \ 
  251                         CHECKED_I2D_OF(type, i2dfunc), buf, len); } \ 
  252   STACK_OF(type) *ASN1_seq_unpack_##type (unsigned char *buf, int len, type *(*d2ifunc)(type**, const unsigned char**, long), void (*freefunc)(type *)) \ 
  253        { return (STACK_OF(type) *)ASN1_seq_unpack(buf, len, CHECKED_D2I_OF(type, d2ifunc), CHECKED_SK_FREE_FUNC(type, freefunc)); } 
  255 #define DECL_STACK(type)  \ 
  256    PREDECLARE_STACK_OF(type) \ 
  257    STACK_OF(type) *sk_##type##_new (int (*)(const type * const *, const type * const *)); \ 
  258    STACK_OF(type) *sk_##type##_new_null (); \ 
  259    void   sk_##type##_free (STACK_OF(type) *); \ 
  260    int    sk_##type##_num (const STACK_OF(type) *); \ 
  261    type  *sk_##type##_value (const STACK_OF(type) *, int); \ 
  262    type  *sk_##type##_set (STACK_OF(type) *, int, type *); \ 
  263    void   sk_##type##_zero (STACK_OF(type) *); \ 
  264    int    sk_##type##_push (STACK_OF(type) *, type *); \ 
  265    int    sk_##type##_unshift (STACK_OF(type) *, type *); \ 
  266    int    sk_##type##_find (STACK_OF(type) *, type *); \ 
  267    type  *sk_##type##_delete (STACK_OF(type) *, int); \ 
  268    type  *sk_##type##_delete_ptr (STACK_OF(type) *, type *); \ 
  269    int    sk_##type##_insert (STACK_OF(type) *, type *, int); \ 
  270    int (*sk_##type##_set_cmp_func (STACK_OF(type) *, int (*)(const type * const *, const type * const *)))(const type * const *, const type * const *); \ 
  271    STACK_OF(type) *sk_##type##_dup (STACK_OF(type) *); \ 
  272    void   sk_##type##_pop_free (STACK_OF(type) *, void (*)(type *)); \ 
  273    type  *sk_##type##_shift (STACK_OF(type) *); \ 
  274    type  *sk_##type##_pop (STACK_OF(type) *); \ 
  275    void   sk_##type##_sort (STACK_OF(type) *); \ 
  276    STACK_OF(type) *d2i_ASN1_SET_OF_##type (STACK_OF(type) **, const unsigned char **, long, type *(*)(type**, const unsigned char **, long), void (*)(type *), int, int); \ 
  277    int i2d_ASN1_SET_OF_##type (STACK_OF(type) *, unsigned char **, int (*)(type*, unsigned char**), int, int, int); \ 
  278    unsigned char *ASN1_seq_pack_##type (STACK_OF(type) *, int (*)(type*, unsigned char**), unsigned char **, int *); \ 
  279    STACK_OF(type) *ASN1_seq_unpack_##type (unsigned char *, int, type *(*)(), void (*)(type *)) ; 
  281 #elif (OPENSSL_VERSION_NUMBER >= 0x0090800fL) 
  282 #define IMPL_STACK(type) \ 
  283    DECLARE_STACK_OF(type) \ 
  284    STACK_OF(type) *sk_##type##_new (int (*cmp)(const type * const *, const type * const *)) \ 
  285        { return sk_new ( (int (*)(const char * const *, const char * const *))cmp);} \ 
  286    STACK_OF(type) *sk_##type##_new_null () { return sk_new_null(); } \ 
  287    void   sk_##type##_free (STACK_OF(type) *st) { sk_free(st); } \ 
  288    int    sk_##type##_num (const STACK_OF(type) *st) { return sk_num(st); } \ 
  289    type  *sk_##type##_value (const STACK_OF(type) *st, int i) { return (type *)sk_value(st, i); } \ 
  290    type  *sk_##type##_set (STACK_OF(type) *st, int i, type *val) { return ((type *)sk_set(st, i, (char *)val)); } \ 
  291    void   sk_##type##_zero (STACK_OF(type) *st) { sk_zero(st);} \ 
  292    int    sk_##type##_push (STACK_OF(type) *st, type *val) { return sk_push(st, (char *)val); } \ 
  293    int    sk_##type##_unshift (STACK_OF(type) *st, type *val) { return sk_unshift(st, (char *)val); } \ 
  294    int    sk_##type##_find (STACK_OF(type) *st, type *val) { return sk_find(st, (char *)val); } \ 
  295    type  *sk_##type##_delete (STACK_OF(type) *st, int i) { return (type *)sk_delete(st, i); } \ 
  296    type  *sk_##type##_delete_ptr (STACK_OF(type) *st, type *ptr) { return (type *)sk_delete_ptr(st, (char *)ptr); } \ 
  297    int    sk_##type##_insert (STACK_OF(type) *st, type *val, int i) { return sk_insert(st, (char *)val, i); } \ 
  298    int (*sk_##type##_set_cmp_func (STACK_OF(type) *st, int (*cmp)(const type * const *, const type * const *)))(const type * const *, const type * const *) \ 
  299        { return (int ((*)(const type * const *, const type * const *)))sk_set_cmp_func (st, (int (*)(const char * const *, const char * const *))cmp); } \ 
  300    STACK_OF(type) *sk_##type##_dup (STACK_OF(type) *st) { return sk_dup(st); } \ 
  301    void   sk_##type##_pop_free (STACK_OF(type) *st, void (*func)(type *)) { sk_pop_free(st, (void (*)(void *))func); } \ 
  302    type  *sk_##type##_shift (STACK_OF(type) *st) { return (type *)sk_shift(st); } \ 
  303    type  *sk_##type##_pop (STACK_OF(type) *st) { return (type *)sk_pop(st); } \ 
  304    void   sk_##type##_sort (STACK_OF(type) *st) { sk_sort(st); } \ 
  305    STACK_OF(type) *d2i_ASN1_SET_OF_##type (STACK_OF(type) **st, const unsigned char **pp, long length, type *(*d2ifunc)(), void (*freefunc)(type *), int ex_tag, int ex_class) \ 
  306        { return d2i_ASN1_SET(st, pp, length, (void*(*)(void**, const unsigned char**, long int))d2ifunc, (void (*)(void *))freefunc, ex_tag, ex_class); } \ 
  307    int i2d_ASN1_SET_OF_##type (STACK_OF(type) *st, unsigned char **pp, int (*i2dfunc)(void*, unsigned char**), int ex_tag, int ex_class, int is_set) \ 
  308        { return i2d_ASN1_SET(st, pp, i2dfunc, ex_tag, ex_class, is_set); }  \ 
  309    unsigned char *ASN1_seq_pack_##type (STACK_OF(type) *st, int (*i2d)(void*, unsigned char**), unsigned char **buf, int *len) { return ASN1_seq_pack(st, i2d, buf, len); } \ 
  310    STACK_OF(type) *ASN1_seq_unpack_##type (unsigned char *buf, int len, type *(*d2i)(), void (*freefunc)(type *)) \ 
  311        { return ASN1_seq_unpack(buf, len, (void*(*)(void**, const unsigned char**, long int))d2i, (void (*)(void *))freefunc); } 
  313 #define DECL_STACK(type) \ 
  314    PREDECLARE_STACK_OF(type) \ 
  315    STACK_OF(type) *sk_##type##_new (int (*)(const type * const *, const type * const *)); \ 
  316    STACK_OF(type) *sk_##type##_new_null (); \ 
  317    void   sk_##type##_free (STACK_OF(type) *); \ 
  318    int    sk_##type##_num (const STACK_OF(type) *); \ 
  319    type  *sk_##type##_value (const STACK_OF(type) *, int); \ 
  320    type  *sk_##type##_set (STACK_OF(type) *, int, type *); \ 
  321    void   sk_##type##_zero (STACK_OF(type) *); \ 
  322    int    sk_##type##_push (STACK_OF(type) *, type *); \ 
  323    int    sk_##type##_unshift (STACK_OF(type) *, type *); \ 
  324    int    sk_##type##_find (STACK_OF(type) *, type *); \ 
  325    type  *sk_##type##_delete (STACK_OF(type) *, int); \ 
  326    type  *sk_##type##_delete_ptr (STACK_OF(type) *, type *); \ 
  327    int    sk_##type##_insert (STACK_OF(type) *, type *, int); \ 
  328    int (*sk_##type##_set_cmp_func (STACK_OF(type) *, int (*)(const type * const *, const type * const *)))(const type * const *, const type * const *); \ 
  329    STACK_OF(type) *sk_##type##_dup (STACK_OF(type) *); \ 
  330    void   sk_##type##_pop_free (STACK_OF(type) *, void (*)(type *)); \ 
  331    type  *sk_##type##_shift (STACK_OF(type) *); \ 
  332    type  *sk_##type##_pop (STACK_OF(type) *); \ 
  333    void   sk_##type##_sort (STACK_OF(type) *); \ 
  334    STACK_OF(type) *d2i_ASN1_SET_OF_##type (STACK_OF(type) **, const unsigned char **, long, type *(*)(), void (*)(type *), int, int); \ 
  335    int i2d_ASN1_SET_OF_##type (STACK_OF(type) *, unsigned char **, int (*)(void*, unsigned char**), int, int, int); \ 
  336    unsigned char *ASN1_seq_pack_##type (STACK_OF(type) *, int (*)(void*, unsigned char**), unsigned char **, int *); \ 
  337    STACK_OF(type) *ASN1_seq_unpack_##type (unsigned char *, int, type *(*)(), void (*)(type *)) ; 
  340 #define IMPL_STACK(type) \ 
  341    DECLARE_STACK_OF(type) \ 
  342    STACK_OF(type) *sk_##type##_new (int (*cmp)(const type * const *, const type * const *)) \ 
  343        { return sk_new ( (int (*)(const char * const *, const char * const *))cmp);} \ 
  344    STACK_OF(type) *sk_##type##_new_null () { return sk_new_null(); } \ 
  345    void   sk_##type##_free (STACK_OF(type) *st) { sk_free(st); } \ 
  346    int    sk_##type##_num (const STACK_OF(type) *st) { return sk_num(st); } \ 
  347    type  *sk_##type##_value (const STACK_OF(type) *st, int i) { return (type *)sk_value(st, i); } \ 
  348    type  *sk_##type##_set (STACK_OF(type) *st, int i, type *val) { return ((type *)sk_set(st, i, (char *)val)); } \ 
  349    void   sk_##type##_zero (STACK_OF(type) *st) { sk_zero(st);} \ 
  350    int    sk_##type##_push (STACK_OF(type) *st, type *val) { return sk_push(st, (char *)val); } \ 
  351    int    sk_##type##_unshift (STACK_OF(type) *st, type *val) { return sk_unshift(st, (char *)val); } \ 
  352    int    sk_##type##_find (STACK_OF(type) *st, type *val) { return sk_find(st, (char *)val); } \ 
  353    type  *sk_##type##_delete (STACK_OF(type) *st, int i) { return (type *)sk_delete(st, i); } \ 
  354    type  *sk_##type##_delete_ptr (STACK_OF(type) *st, type *ptr) { return (type *)sk_delete_ptr(st, (char *)ptr); } \ 
  355    int    sk_##type##_insert (STACK_OF(type) *st, type *val, int i) { return sk_insert(st, (char *)val, i); } \ 
  356    int (*sk_##type##_set_cmp_func (STACK_OF(type) *st, int (*cmp)(const type * const *, const type * const *)))(const type * const *, const type * const *) \ 
  357        { return (int ((*)(const type * const *, const type * const *)))sk_set_cmp_func (st, (int (*)(const char * const *, const char * const *))cmp); } \ 
  358    STACK_OF(type) *sk_##type##_dup (STACK_OF(type) *st) { return sk_dup(st); } \ 
  359    void   sk_##type##_pop_free (STACK_OF(type) *st, void (*func)(type *)) { sk_pop_free(st, (void (*)(void *))func); } \ 
  360    type  *sk_##type##_shift (STACK_OF(type) *st) { return (type *)sk_shift(st); } \ 
  361    type  *sk_##type##_pop (STACK_OF(type) *st) { return (type *)sk_pop(st); } \ 
  362    void   sk_##type##_sort (STACK_OF(type) *st) { sk_sort(st); } \ 
  363    STACK_OF(type) *d2i_ASN1_SET_OF_##type (STACK_OF(type) **st, unsigned char **pp, long length, type *(*d2ifunc)(), void (*freefunc)(type *), int ex_tag, int ex_class) \ 
  364        { return d2i_ASN1_SET(st, pp, length, (char *(*)())d2ifunc, (void (*)(void *))freefunc, ex_tag, ex_class); } \ 
  365    int i2d_ASN1_SET_OF_##type (STACK_OF(type) *st, unsigned char **pp, int (*i2dfunc)(), int ex_tag, int ex_class, int is_set) \ 
  366        { return i2d_ASN1_SET(st, pp, i2dfunc, ex_tag, ex_class, is_set); }  \ 
  367    unsigned char *ASN1_seq_pack_##type (STACK_OF(type) *st, int (*i2d)(), unsigned char **buf, int *len) { return ASN1_seq_pack(st, i2d, buf, len); } \ 
  368    STACK_OF(type) *ASN1_seq_unpack_##type (unsigned char *buf, int len, type *(*d2i)(), void (*freefunc)(type *)) \ 
  369        { return ASN1_seq_unpack(buf, len, (char *(*)())d2i, (void (*)(void *))freefunc); } 
  371 #define DECL_STACK(type) \ 
  372    PREDECLARE_STACK_OF(type) \ 
  373    STACK_OF(type) *sk_##type##_new (int (*)(const type * const *, const type * const *)); \ 
  374    STACK_OF(type) *sk_##type##_new_null (); \ 
  375    void   sk_##type##_free (STACK_OF(type) *); \ 
  376    int    sk_##type##_num (const STACK_OF(type) *); \ 
  377    type  *sk_##type##_value (const STACK_OF(type) *, int); \ 
  378    type  *sk_##type##_set (STACK_OF(type) *, int, type *); \ 
  379    void   sk_##type##_zero (STACK_OF(type) *); \ 
  380    int    sk_##type##_push (STACK_OF(type) *, type *); \ 
  381    int    sk_##type##_unshift (STACK_OF(type) *, type *); \ 
  382    int    sk_##type##_find (STACK_OF(type) *, type *); \ 
  383    type  *sk_##type##_delete (STACK_OF(type) *, int); \ 
  384    type  *sk_##type##_delete_ptr (STACK_OF(type) *, type *); \ 
  385    int    sk_##type##_insert (STACK_OF(type) *, type *, int); \ 
  386    int (*sk_##type##_set_cmp_func (STACK_OF(type) *, int (*)(const type * const *, const type * const *)))(const type * const *, const type * const *); \ 
  387    STACK_OF(type) *sk_##type##_dup (STACK_OF(type) *); \ 
  388    void   sk_##type##_pop_free (STACK_OF(type) *, void (*)(type *)); \ 
  389    type  *sk_##type##_shift (STACK_OF(type) *); \ 
  390    type  *sk_##type##_pop (STACK_OF(type) *); \ 
  391    void   sk_##type##_sort (STACK_OF(type) *); \ 
  392    STACK_OF(type) *d2i_ASN1_SET_OF_##type (STACK_OF(type) **, unsigned char **, long, type *(*)(), void (*)(type *), int, int); \ 
  393    int i2d_ASN1_SET_OF_##type (STACK_OF(type) *, unsigned char **, int (*)(), int, int, int); \ 
  394    unsigned char *ASN1_seq_pack_##type (STACK_OF(type) *, int (*)(), unsigned char **, int *); \ 
  395    STACK_OF(type) *ASN1_seq_unpack_##type (unsigned char *, int, type *(*)(), void (*)(type *)) ; 
  398 DECL_STACK(AC_TARGET)
 
  399 DECL_STACK(AC_TARGETS)
 
  400 DECL_STACK(AC_IETFATTR)
 
  401 DECL_STACK(AC_IETFATTRVAL)
 
  406 DECL_STACK(AC_HOLDER)
 
  410 DECL_STACK(AC_DIGEST)
 
  412 DECL_STACK(AC_ATTRIBUTE)
 
  413 DECL_STACK(AC_ATT_HOLDER)
 
  414 DECL_STACK(AC_FULL_ATTRIBUTES)
 
  416 #if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) 
  417 #define SSLCONST const 
  422 int i2d_AC_ATTR(AC_ATTR *a, 
unsigned char **pp);
 
  423 AC_ATTR *d2i_AC_ATTR(AC_ATTR **a, SSLCONST 
unsigned char **p, 
long length);
 
  424 AC_ATTR *AC_ATTR_new();
 
  425 void AC_ATTR_free(AC_ATTR *a);
 
  427 int i2d_AC_IETFATTR(AC_IETFATTR *a, 
unsigned char **pp);
 
  428 AC_IETFATTR *d2i_AC_IETFATTR(AC_IETFATTR **a, SSLCONST 
unsigned char **p, 
long length);
 
  429 AC_IETFATTR *AC_IETFATTR_new();
 
  430 void AC_IETFATTR_free (AC_IETFATTR *a);
 
  432 int i2d_AC_IETFATTRVAL(AC_IETFATTRVAL *a, 
unsigned char **pp);
 
  433 AC_IETFATTRVAL *d2i_AC_IETFATTRVAL(AC_IETFATTRVAL **a, SSLCONST 
unsigned char **pp, 
long length);
 
  434 AC_IETFATTRVAL *AC_IETFATTRVAL_new();
 
  435 void AC_IETFATTRVAL_free(AC_IETFATTRVAL *a);
 
  437 int i2d_AC_DIGEST(AC_DIGEST *a, 
unsigned char **pp);
 
  438 AC_DIGEST *d2i_AC_DIGEST(AC_DIGEST **a, SSLCONST 
unsigned char **pp, 
long length);
 
  439 AC_DIGEST *AC_DIGEST_new(
void);
 
  440 void AC_DIGEST_free(AC_DIGEST *a);
 
  442 int i2d_AC_IS(AC_IS *a, 
unsigned char **pp);
 
  443 AC_IS *d2i_AC_IS(AC_IS **a, SSLCONST 
unsigned char **pp, 
long length);
 
  444 AC_IS *AC_IS_new(
void);
 
  445 void AC_IS_free(AC_IS *a);
 
  447 int i2d_AC_FORM(AC_FORM *a, 
unsigned char **pp);
 
  448 AC_FORM *d2i_AC_FORM(AC_FORM **a, SSLCONST 
unsigned char **pp, 
long length);
 
  449 AC_FORM *AC_FORM_new(
void);
 
  450 void AC_FORM_free(AC_FORM *a);
 
  452 int i2d_AC_ACI(AC_ACI *a, 
unsigned char **pp);
 
  453 AC_ACI *d2i_AC_ACI(AC_ACI **a, SSLCONST 
unsigned char **pp, 
long length);
 
  454 AC_ACI *AC_ACI_new(
void);
 
  455 void AC_ACI_free(AC_ACI *a);
 
  457 int i2d_AC_HOLDER(AC_HOLDER *a, 
unsigned char **pp);
 
  458 AC_HOLDER *d2i_AC_HOLDER(AC_HOLDER **a, SSLCONST 
unsigned char **pp, 
long length);
 
  459 AC_HOLDER *AC_HOLDER_new(
void);
 
  460 void AC_HOLDER_free(AC_HOLDER *a);
 
  463 int i2d_AC_VAL(AC_VAL *a, 
unsigned char **pp);
 
  464 AC_VAL *d2i_AC_VAL(AC_VAL **a, SSLCONST 
unsigned char **pp, 
long length);
 
  465 AC_VAL *AC_VAL_new(
void);
 
  466 void AC_VAL_free(AC_VAL *a);
 
  469 int i2d_AC_INFO(AC_INFO *a, 
unsigned char **pp);
 
  470 AC_INFO *d2i_AC_INFO(AC_INFO **a, SSLCONST 
unsigned char **p, 
long length);
 
  471 AC_INFO *AC_INFO_new(
void);
 
  472 void AC_INFO_free(AC_INFO *a);
 
  474 int i2d_AC(AC *a, 
unsigned char **pp) ;
 
  475 AC *d2i_AC(AC **a, SSLCONST 
unsigned char **pp, 
long length);
 
  479 int i2d_AC_TARGETS(AC_TARGETS *a, 
unsigned char **pp) ;
 
  480 AC_TARGETS *d2i_AC_TARGETS(AC_TARGETS **a, SSLCONST 
unsigned char **pp, 
long length);
 
  481 AC_TARGETS *AC_TARGETS_new(
void);
 
  482 void AC_TARGETS_free(AC_TARGETS *a);
 
  484 int i2d_AC_TARGET(AC_TARGET *a, 
unsigned char **pp) ;
 
  485 AC_TARGET *d2i_AC_TARGET(AC_TARGET **a, SSLCONST 
unsigned char **pp, 
long length);
 
  486 AC_TARGET *AC_TARGET_new(
void);
 
  487 void AC_TARGET_free(AC_TARGET *a);
 
  489 int i2d_AC_SEQ(AC_SEQ *a, 
unsigned char **pp) ;
 
  490 AC_SEQ *d2i_AC_SEQ(AC_SEQ **a, SSLCONST 
unsigned char **pp, 
long length);
 
  491 AC_SEQ *AC_SEQ_new(
void);
 
  492 void AC_SEQ_free(AC_SEQ *a);
 
  494 int i2d_AC_CERTS(AC_CERTS *a, 
unsigned char **pp) ;
 
  495 AC_CERTS *d2i_AC_CERTS(AC_CERTS **a, SSLCONST 
unsigned char **pp, 
long length);
 
  496 AC_CERTS *AC_CERTS_new(
void);
 
  497 void AC_CERTS_free(AC_CERTS *a);
 
  499 int i2d_AC_ATTRIBUTE(AC_ATTRIBUTE *, 
unsigned char **);
 
  500 AC_ATTRIBUTE *d2i_AC_ATTRIBUTE(AC_ATTRIBUTE **, SSLCONST 
unsigned char **, 
long);
 
  501 AC_ATTRIBUTE *AC_ATTRIBUTE_new();
 
  502 void AC_ATTRIBUTE_free(AC_ATTRIBUTE *);
 
  504 int i2d_AC_ATT_HOLDER(AC_ATT_HOLDER *, 
unsigned char **);
 
  505 AC_ATT_HOLDER *d2i_AC_ATT_HOLDER(AC_ATT_HOLDER **, SSLCONST 
unsigned char **, 
long);
 
  506 AC_ATT_HOLDER *AC_ATT_HOLDER_new();
 
  507 void AC_ATT_HOLDER_free(AC_ATT_HOLDER *);
 
  509 int i2d_AC_FULL_ATTRIBUTES(AC_FULL_ATTRIBUTES *, 
unsigned char **);
 
  510 AC_FULL_ATTRIBUTES *d2i_AC_FULL_ATTRIBUTES(AC_FULL_ATTRIBUTES **, SSLCONST 
unsigned char **, 
long);
 
  511 AC_FULL_ATTRIBUTES *AC_FULL_ATTRIBUTES_new();
 
  512 void AC_FULL_ATTRIBUTES_free(AC_FULL_ATTRIBUTES *);
 
  514 X509V3_EXT_METHOD * VOMSAttribute_auth_x509v3_ext_meth();
 
  515 X509V3_EXT_METHOD * VOMSAttribute_avail_x509v3_ext_meth();
 
  516 X509V3_EXT_METHOD * VOMSAttribute_targets_x509v3_ext_meth();
 
  517 X509V3_EXT_METHOD * VOMSAttribute_acseq_x509v3_ext_meth();
 
  518 X509V3_EXT_METHOD * VOMSAttribute_certseq_x509v3_ext_meth();
 
  519 X509V3_EXT_METHOD * VOMSAttribute_attribs_x509v3_ext_meth();