diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2007-04-13 01:06:41 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2007-04-13 01:06:41 +0000 |
commit | 9cfc8a9d5cb95c44251eff88d794482f8e413820 (patch) | |
tree | 8cdc355417d88d86bebc957b5c3e9ed928b682c3 /crypto/pkcs7/bio_pk7.c | |
parent | 18327cd0e455afa1f2590fff9a922cfaf235968d (diff) |
Update smime utility to support streaming for -encrypt and -sign -nodetach
options. Add new streaming i2d (though strictly speaking it is BER format
when streaming) and PEM functions.
These all process content on the fly without storing it all in memory.
Diffstat (limited to 'crypto/pkcs7/bio_pk7.c')
-rw-r--r-- | crypto/pkcs7/bio_pk7.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/crypto/pkcs7/bio_pk7.c b/crypto/pkcs7/bio_pk7.c index 831a4e23b8..533e596a1c 100644 --- a/crypto/pkcs7/bio_pk7.c +++ b/crypto/pkcs7/bio_pk7.c @@ -97,8 +97,9 @@ typedef struct pkcs7_aux_st } PKCS7_SUPPORT; static int pkcs7_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg); -static int pkcs7_psfix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg); +static int pkcs7_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg); static int pkcs7_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg); +static int pkcs7_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg); BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7) { @@ -113,8 +114,8 @@ BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7) out = BIO_push(asn_bio, out); - BIO_asn1_set_prefix(asn_bio, pkcs7_prefix, pkcs7_psfix_free); - BIO_asn1_set_suffix(asn_bio, pkcs7_suffix, pkcs7_psfix_free); + BIO_asn1_set_prefix(asn_bio, pkcs7_prefix, pkcs7_prefix_free); + BIO_asn1_set_suffix(asn_bio, pkcs7_suffix, pkcs7_suffix_free); /* Now initialize BIO for PKCS#7 output */ @@ -132,7 +133,6 @@ BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7) } - static int pkcs7_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) { PKCS7_SUPPORT *p7aux; @@ -150,12 +150,15 @@ static int pkcs7_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg) *pbuf = p; i2d_PKCS7_NDEF(p7aux->p7, &p); + if (!*p7aux->boundary) + return 0; + *plen = *p7aux->boundary - *pbuf; return 1; } -static int pkcs7_psfix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) +static int pkcs7_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) { PKCS7_SUPPORT *p7aux; @@ -173,6 +176,16 @@ static int pkcs7_psfix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) return 1; } +static int pkcs7_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg) + { + PKCS7_SUPPORT **pp7aux = (PKCS7_SUPPORT **)parg; + if (!pkcs7_prefix_free(b, pbuf, plen, parg)) + return 0; + OPENSSL_free(*pp7aux); + *pp7aux = NULL; + return 1; + } + static int pkcs7_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) { PKCS7_SUPPORT *p7aux; @@ -191,6 +204,8 @@ static int pkcs7_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg) p = OPENSSL_malloc(derlen); p7aux->derbuf = p; i2d_PKCS7_NDEF(p7aux->p7, &p); + if (!*p7aux->boundary) + return 0; *pbuf = *p7aux->boundary; *plen = derlen - (*p7aux->boundary - p7aux->derbuf); |