More stack.
authorBen Laurie <ben@openssl.org>
Mon, 31 May 1999 11:57:32 +0000 (11:57 +0000)
committerBen Laurie <ben@openssl.org>
Mon, 31 May 1999 11:57:32 +0000 (11:57 +0000)
crypto/asn1/p7_signi.c
crypto/pkcs7/pk7_doit.c
crypto/pkcs7/pkcs7.h

index 056c5d3065d40396e16a27ccd8a9538e58196cd3..0f863333a1c08f53db8be76e41dcf057014f0abf 100644 (file)
@@ -68,20 +68,24 @@ int i2d_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO *a, unsigned char **pp)
        M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER);
        M_ASN1_I2D_len(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL);
        M_ASN1_I2D_len(a->digest_alg,i2d_X509_ALGOR);
-       M_ASN1_I2D_len_IMP_SET_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0);
+       M_ASN1_I2D_len_IMP_SET_opt_type(X509_ATTRIBUTE,a->auth_attr,
+                                       i2d_X509_ATTRIBUTE,0);
        M_ASN1_I2D_len(a->digest_enc_alg,i2d_X509_ALGOR);
        M_ASN1_I2D_len(a->enc_digest,i2d_ASN1_OCTET_STRING);
-       M_ASN1_I2D_len_IMP_SET_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1);
+       M_ASN1_I2D_len_IMP_SET_opt_type(X509_ATTRIBUTE,a->unauth_attr,
+                                       i2d_X509_ATTRIBUTE,1);
 
        M_ASN1_I2D_seq_total();
 
        M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER);
        M_ASN1_I2D_put(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL);
        M_ASN1_I2D_put(a->digest_alg,i2d_X509_ALGOR);
-       M_ASN1_I2D_put_IMP_SET_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0);
+       M_ASN1_I2D_put_IMP_SET_opt_type(X509_ATTRIBUTE,a->auth_attr,
+                                       i2d_X509_ATTRIBUTE,0);
        M_ASN1_I2D_put(a->digest_enc_alg,i2d_X509_ALGOR);
        M_ASN1_I2D_put(a->enc_digest,i2d_ASN1_OCTET_STRING);
-       M_ASN1_I2D_put_IMP_SET_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1);
+       M_ASN1_I2D_put_IMP_SET_opt_type(X509_ATTRIBUTE,a->unauth_attr,
+                                       i2d_X509_ATTRIBUTE,1);
 
        M_ASN1_I2D_finish();
        }
@@ -96,12 +100,14 @@ PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO **a,
        M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
        M_ASN1_D2I_get(ret->issuer_and_serial,d2i_PKCS7_ISSUER_AND_SERIAL);
        M_ASN1_D2I_get(ret->digest_alg,d2i_X509_ALGOR);
-       M_ASN1_D2I_get_IMP_set_opt(ret->auth_attr,d2i_X509_ATTRIBUTE,
-               X509_ATTRIBUTE_free,0);
+       M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE,ret->auth_attr,
+                                       d2i_X509_ATTRIBUTE,X509_ATTRIBUTE_free,
+                                       0);
        M_ASN1_D2I_get(ret->digest_enc_alg,d2i_X509_ALGOR);
        M_ASN1_D2I_get(ret->enc_digest,d2i_ASN1_OCTET_STRING);
-       M_ASN1_D2I_get_IMP_set_opt(ret->unauth_attr,d2i_X509_ATTRIBUTE,
-               X509_ATTRIBUTE_free,1);
+       M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE,ret->unauth_attr,
+                                       d2i_X509_ATTRIBUTE,
+                                       X509_ATTRIBUTE_free,1);
 
        M_ASN1_D2I_Finish(a,PKCS7_SIGNER_INFO_free,
                ASN1_F_D2I_PKCS7_SIGNER_INFO);
@@ -131,10 +137,10 @@ void PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO *a)
        ASN1_INTEGER_free(a->version);
        PKCS7_ISSUER_AND_SERIAL_free(a->issuer_and_serial);
        X509_ALGOR_free(a->digest_alg);
-       sk_pop_free(a->auth_attr,X509_ATTRIBUTE_free);
+       sk_X509_ATTRIBUTE_pop_free(a->auth_attr,X509_ATTRIBUTE_free);
        X509_ALGOR_free(a->digest_enc_alg);
        ASN1_OCTET_STRING_free(a->enc_digest);
-       sk_pop_free(a->unauth_attr,X509_ATTRIBUTE_free);
+       sk_X509_ATTRIBUTE_pop_free(a->unauth_attr,X509_ATTRIBUTE_free);
        if (a->pkey != NULL)
                EVP_PKEY_free(a->pkey);
        Free((char *)a);
index 47855bdb68cf3713ea0e8f120056047960db33f3..4222173e36b9360bbc4092c4c55896faad60b963 100644 (file)
@@ -62,8 +62,9 @@
 #include <openssl/objects.h>
 #include <openssl/x509.h>
 
-static int add_attribute(STACK **sk, int nid, int atrtype, void *value);
-static ASN1_TYPE *get_attribute(STACK *sk, int nid);
+static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
+                        void *value);
+static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid);
 
 BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
        {
@@ -462,7 +463,8 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
        BUF_MEM *buf=NULL;
        PKCS7_SIGNER_INFO *si;
        EVP_MD_CTX *mdc,ctx_tmp;
-       STACK *sk,*si_sk=NULL;
+       STACK_OF(X509_ATTRIBUTE) *sk;
+       STACK *si_sk=NULL;
        unsigned char *p,*pp=NULL;
        int x;
        ASN1_OCTET_STRING *os=NULL;
@@ -543,7 +545,7 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
 
                        /* If there are attributes, we add the digest
                         * attribute and only sign the attributes */
-                       if ((sk != NULL) && (sk_num(sk) != 0))
+                       if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
                                {
                                unsigned char md_data[EVP_MAX_MD_SIZE];
                                unsigned int md_len;
@@ -568,12 +570,14 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
 
                                /* Now sign the mess */
                                EVP_SignInit(&ctx_tmp,md_tmp);
-                               x=i2d_ASN1_SET(sk,NULL,i2d_X509_ATTRIBUTE,
-                                       V_ASN1_SET,V_ASN1_UNIVERSAL, IS_SET);
+                               x=i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,NULL,
+                                          i2d_X509_ATTRIBUTE,
+                                          V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
                                pp=(unsigned char *)Malloc(x);
                                p=pp;
-                               i2d_ASN1_SET(sk,&p,i2d_X509_ATTRIBUTE,
-                                       V_ASN1_SET,V_ASN1_UNIVERSAL, IS_SET);
+                               i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,&p,
+                                          i2d_X509_ATTRIBUTE,
+                                          V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
                                EVP_SignUpdate(&ctx_tmp,pp,x);
                                Free(pp);
                                pp=NULL;
@@ -628,7 +632,7 @@ int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
        PKCS7_ISSUER_AND_SERIAL *ias;
        int ret=0,i;
        int md_type;
-       STACK *sk;
+       STACK_OF(X509_ATTRIBUTE) *sk;
        STACK_OF(X509) *cert;
        BIO *btmp;
        X509 *x509;
@@ -697,7 +701,7 @@ int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
        memcpy(&mdc_tmp,mdc,sizeof(mdc_tmp));
 
        sk=si->auth_attr;
-       if ((sk != NULL) && (sk_num(sk) != 0))
+       if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
                {
                unsigned char md_dat[EVP_MAX_MD_SIZE];
                 unsigned int md_len;
@@ -731,11 +735,11 @@ for (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\n");
                 * shouldn't reorder them or this will break the signature.
                 * This is done by using the IS_SEQUENCE flag.
                 */
-               i=i2d_ASN1_SET(sk,NULL,i2d_X509_ATTRIBUTE,
+               i=i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,NULL,i2d_X509_ATTRIBUTE,
                        V_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE);
-               pp=(unsigned char *)Malloc(i);
+               pp=Malloc(i);
                p=pp;
-               i2d_ASN1_SET(sk,&p,i2d_X509_ATTRIBUTE,
+               i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,&p,i2d_X509_ATTRIBUTE,
                        V_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE);
                EVP_VerifyUpdate(&mdc_tmp,pp,i);
 
@@ -785,7 +789,7 @@ ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid)
        return(get_attribute(si->unauth_attr,nid));
        }
 
-static ASN1_TYPE *get_attribute(STACK *sk, int nid)
+static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid)
        {
        int i;
        X509_ATTRIBUTE *xa;
@@ -793,9 +797,9 @@ static ASN1_TYPE *get_attribute(STACK *sk, int nid)
 
        o=OBJ_nid2obj(nid);
        if (!o || !sk) return(NULL);
-       for (i=0; i<sk_num(sk); i++)
+       for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
                {
-               xa=(X509_ATTRIBUTE *)sk_value(sk,i);
+               xa=sk_X509_ATTRIBUTE_value(sk,i);
                if (OBJ_cmp(xa->object,o) == 0)
                        {
                        if (xa->set && sk_ASN1_TYPE_num(xa->value.set))
@@ -807,40 +811,44 @@ static ASN1_TYPE *get_attribute(STACK *sk, int nid)
        return(NULL);
        }
 
-ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK *sk)
+ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk)
 {
        ASN1_TYPE *astype;
        if(!(astype = get_attribute(sk, NID_pkcs9_messageDigest))) return NULL;
        return astype->value.octet_string;
 }
 
-int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si, STACK *sk)
+int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
+                               STACK_OF(X509_ATTRIBUTE) *sk)
        {
        int i;
 
        if (p7si->auth_attr != NULL)
-               sk_pop_free(p7si->auth_attr,X509_ATTRIBUTE_free);
-       p7si->auth_attr=sk_dup(sk);
-       for (i=0; i<sk_num(sk); i++)
+               sk_X509_ATTRIBUTE_pop_free(p7si->auth_attr,X509_ATTRIBUTE_free);
+       p7si->auth_attr=sk_X509_ATTRIBUTE_dup(sk);
+       for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
                {
-               if ((sk_set(p7si->auth_attr,i,(char *)X509_ATTRIBUTE_dup(
-                       (X509_ATTRIBUTE *)sk_value(sk,i)))) == NULL)
+               if ((sk_X509_ATTRIBUTE_set(p7si->auth_attr,i,
+                       X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
+                   == NULL)
                        return(0);
                }
        return(1);
        }
 
-int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, STACK *sk)
+int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, STACK_OF(X509_ATTRIBUTE) *sk)
        {
        int i;
 
        if (p7si->unauth_attr != NULL)
-               sk_pop_free(p7si->unauth_attr,X509_ATTRIBUTE_free);
-       p7si->unauth_attr=sk_dup(sk);
-       for (i=0; i<sk_num(sk); i++)
+               sk_X509_ATTRIBUTE_pop_free(p7si->unauth_attr,
+                                          X509_ATTRIBUTE_free);
+       p7si->unauth_attr=sk_X509_ATTRIBUTE_dup(sk);
+       for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
                {
-               if ((sk_set(p7si->unauth_attr,i,(char *)X509_ATTRIBUTE_dup(
-                       (X509_ATTRIBUTE *)sk_value(sk,i)))) == NULL)
+               if ((sk_X509_ATTRIBUTE_set(p7si->unauth_attr,i,
+                        X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
+                   == NULL)
                        return(0);
                }
        return(1);
@@ -858,29 +866,30 @@ int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
        return(add_attribute(&(p7si->unauth_attr),nid,atrtype,value));
        }
 
-static int add_attribute(STACK **sk, int nid, int atrtype, void *value)
+static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
+                        void *value)
        {
        X509_ATTRIBUTE *attr=NULL;
 
        if (*sk == NULL)
                {
-               *sk = sk_new(NULL);
+               *sk = sk_X509_ATTRIBUTE_new(NULL);
 new_attrib:
                attr=X509_ATTRIBUTE_create(nid,atrtype,value);
-               sk_push(*sk,(char *)attr);
+               sk_X509_ATTRIBUTE_push(*sk,attr);
                }
        else
                {
                int i;
 
-               for (i=0; i<sk_num(*sk); i++)
+               for (i=0; i<sk_X509_ATTRIBUTE_num(*sk); i++)
                        {
-                       attr=(X509_ATTRIBUTE *)sk_value(*sk,i);
+                       attr=sk_X509_ATTRIBUTE_value(*sk,i);
                        if (OBJ_obj2nid(attr->object) == nid)
                                {
                                X509_ATTRIBUTE_free(attr);
                                attr=X509_ATTRIBUTE_create(nid,atrtype,value);
-                               sk_set(*sk,i,(char *)attr);
+                               sk_X509_ATTRIBUTE_set(*sk,i,attr);
                                goto end;
                                }
                        }
index 197b257725ccdf616c552bdce007ce26195a5a7e..733d4e87d3f026dc9d877aa9ba122a33ad2a3b5c 100644 (file)
@@ -89,10 +89,10 @@ typedef struct pkcs7_signer_info_st
        ASN1_INTEGER                    *version;       /* version 1 */
        PKCS7_ISSUER_AND_SERIAL         *issuer_and_serial;
        X509_ALGOR                      *digest_alg;
-       STACK /* X509_ATTRIBUTE */      *auth_attr;     /* [ 0 ] */
+       STACK_OF(X509_ATTRIBUTE)        *auth_attr;     /* [ 0 ] */
        X509_ALGOR                      *digest_enc_alg;
        ASN1_OCTET_STRING               *enc_digest;
-       STACK /* X509_ATTRIBUTE */      *unauth_attr;   /* [ 1 ] */
+       STACK_OF(X509_ATTRIBUTE)        *unauth_attr;   /* [ 1 ] */
 
        /* The private key to sign with */
        EVP_PKEY                        *pkey;
@@ -344,15 +344,16 @@ int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);
 int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher);
 
 PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx);
-ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK *sk);
+ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk);
 int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si,int nid,int type,
        void *data);
 int PKCS7_add_attribute (PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
        void *value);
 ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid);
 ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid);
-int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si, STACK *sk);
-int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, STACK *sk);
+int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
+                               STACK_OF(X509_ATTRIBUTE) *sk);
+int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk);