X-Git-Url: https://git.openssl.org/gitweb/?a=blobdiff_plain;f=crypto%2Fasn1%2Fp7_lib.c;h=b1196ef581ceac7562fbdb1a7859b95ccbcc96b1;hb=d096b524afbdc371032d96d22f1686d88bfba0e9;hp=9effc28622bacc0a30a9c64663e54da9ac6d3d42;hpb=5de603abc8fe6fedca529ce58d3741b50ff99592;p=openssl.git diff --git a/crypto/asn1/p7_lib.c b/crypto/asn1/p7_lib.c index 9effc28622..b1196ef581 100644 --- a/crypto/asn1/p7_lib.c +++ b/crypto/asn1/p7_lib.c @@ -62,6 +62,8 @@ #include #include +#ifdef PKCS7_INDEFINITE_ENCODING + int i2d_PKCS7(PKCS7 *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -102,6 +104,7 @@ int i2d_PKCS7(PKCS7 *a, unsigned char **pp) M_ASN1_I2D_len(a->d.encrypted,i2d_PKCS7_ENCRYPT); break; default: + M_ASN1_I2D_len(a->d.other,i2d_ASN1_TYPE); break; } } @@ -136,6 +139,7 @@ int i2d_PKCS7(PKCS7 *a, unsigned char **pp) M_ASN1_I2D_put(a->d.encrypted,i2d_PKCS7_ENCRYPT); break; default: + M_ASN1_I2D_put(a->d.other,i2d_ASN1_TYPE); break; } M_ASN1_I2D_INF_seq_end(); @@ -144,6 +148,98 @@ int i2d_PKCS7(PKCS7 *a, unsigned char **pp) M_ASN1_I2D_finish(); } +#else + +int i2d_PKCS7(PKCS7 *a, unsigned char **pp) + { + int explen = 0; + M_ASN1_I2D_vars(a); + + if (a->asn1 != NULL) + { + if (pp == NULL) + return((int)a->length); + memcpy(*pp,a->asn1,(int)a->length); + *pp+=a->length; + return((int)a->length); + } + + M_ASN1_I2D_len(a->type,i2d_ASN1_OBJECT); + if (a->d.ptr != NULL) + { + /* Save current length */ + r = ret; + switch (OBJ_obj2nid(a->type)) + { + case NID_pkcs7_data: + M_ASN1_I2D_len(a->d.data,i2d_ASN1_OCTET_STRING); + break; + case NID_pkcs7_signed: + M_ASN1_I2D_len(a->d.sign,i2d_PKCS7_SIGNED); + break; + case NID_pkcs7_enveloped: + M_ASN1_I2D_len(a->d.enveloped,i2d_PKCS7_ENVELOPE); + break; + case NID_pkcs7_signedAndEnveloped: + M_ASN1_I2D_len(a->d.signed_and_enveloped, + i2d_PKCS7_SIGN_ENVELOPE); + break; + case NID_pkcs7_digest: + M_ASN1_I2D_len(a->d.digest,i2d_PKCS7_DIGEST); + break; + case NID_pkcs7_encrypted: + M_ASN1_I2D_len(a->d.encrypted,i2d_PKCS7_ENCRYPT); + break; + default: + M_ASN1_I2D_len(a->d.other,i2d_ASN1_TYPE); + break; + } + /* Work out explicit tag content size */ + explen = ret - r; + /* Work out explicit tag size: Note: ASN1_object_size + * includes the content length. + */ + ret = r + ASN1_object_size(1, explen, 0); + } + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put(a->type,i2d_ASN1_OBJECT); + + if (a->d.ptr != NULL) + { + ASN1_put_object(&p, 1, explen, 0, V_ASN1_CONTEXT_SPECIFIC); + switch (OBJ_obj2nid(a->type)) + { + case NID_pkcs7_data: + M_ASN1_I2D_put(a->d.data,i2d_ASN1_OCTET_STRING); + break; + case NID_pkcs7_signed: + M_ASN1_I2D_put(a->d.sign,i2d_PKCS7_SIGNED); + break; + case NID_pkcs7_enveloped: + M_ASN1_I2D_put(a->d.enveloped,i2d_PKCS7_ENVELOPE); + break; + case NID_pkcs7_signedAndEnveloped: + M_ASN1_I2D_put(a->d.signed_and_enveloped, + i2d_PKCS7_SIGN_ENVELOPE); + break; + case NID_pkcs7_digest: + M_ASN1_I2D_put(a->d.digest,i2d_PKCS7_DIGEST); + break; + case NID_pkcs7_encrypted: + M_ASN1_I2D_put(a->d.encrypted,i2d_PKCS7_ENCRYPT); + break; + default: + M_ASN1_I2D_put(a->d.other,i2d_ASN1_TYPE); + break; + } + } + M_ASN1_I2D_finish(); + } + +#endif + PKCS7 *d2i_PKCS7(PKCS7 **a, unsigned char **pp, long length) { M_ASN1_D2I_vars(a,PKCS7 *,PKCS7_new); @@ -152,7 +248,7 @@ PKCS7 *d2i_PKCS7(PKCS7 **a, unsigned char **pp, long length) { if ((*a)->asn1 != NULL) { - Free((*a)->asn1); + OPENSSL_free((*a)->asn1); (*a)->asn1=NULL; } (*a)->length=0; @@ -206,10 +302,8 @@ PKCS7 *d2i_PKCS7(PKCS7 **a, unsigned char **pp, long length) M_ASN1_D2I_get(ret->d.encrypted,d2i_PKCS7_ENCRYPT); break; default: - c.error=ASN1_R_BAD_PKCS7_TYPE; - c.line=__LINE__; - goto err; - /* break; */ + M_ASN1_D2I_get(ret->d.other,d2i_ASN1_TYPE); + break; } if (Tinf == (1|V_ASN1_CONSTRUCTED)) { @@ -251,7 +345,7 @@ void PKCS7_free(PKCS7 *a) { ASN1_OBJECT_free(a->type); } - Free(a); + OPENSSL_free(a); } void PKCS7_content_free(PKCS7 *a) @@ -259,7 +353,7 @@ void PKCS7_content_free(PKCS7 *a) if(a == NULL) return; - if (a->asn1 != NULL) Free(a->asn1); + if (a->asn1 != NULL) OPENSSL_free(a->asn1); if (a->d.ptr != NULL) { @@ -286,7 +380,7 @@ void PKCS7_content_free(PKCS7 *a) PKCS7_ENCRYPT_free(a->d.encrypted); break; default: - /* MEMORY LEAK */ + ASN1_TYPE_free(a->d.other); break; } }