Index: openssl/crypto/cms/cms_io.c |
=================================================================== |
--- openssl/crypto/cms/cms_io.c (revision 105093) |
+++ openssl/crypto/cms/cms_io.c (working copy) |
@@ -58,6 +58,25 @@ |
#include "cms.h" |
#include "cms_lcl.h" |
+int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms) |
+ { |
+ ASN1_OCTET_STRING **pos; |
+ pos = CMS_get0_content(cms); |
+ if (!pos) |
+ return 0; |
+ if (!*pos) |
+ *pos = ASN1_OCTET_STRING_new(); |
+ if (*pos) |
+ { |
+ (*pos)->flags |= ASN1_STRING_FLAG_NDEF; |
+ (*pos)->flags &= ~ASN1_STRING_FLAG_CONT; |
+ *boundary = &(*pos)->data; |
+ return 1; |
+ } |
+ CMSerr(CMS_F_CMS_STREAM, ERR_R_MALLOC_FAILURE); |
+ return 0; |
+ } |
+ |
CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms) |
{ |
return ASN1_item_d2i_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms); |
@@ -70,53 +89,27 @@ |
IMPLEMENT_PEM_rw_const(CMS, CMS_ContentInfo, PEM_STRING_CMS, CMS_ContentInfo) |
-/* Callback for int_smime_write_ASN1 */ |
- |
-static int cms_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, |
- const ASN1_ITEM *it) |
+BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms) |
{ |
- CMS_ContentInfo *cms = (CMS_ContentInfo *)val; |
- BIO *tmpbio, *cmsbio; |
- int r = 0; |
+ return BIO_new_NDEF(out, (ASN1_VALUE *)cms, |
+ ASN1_ITEM_rptr(CMS_ContentInfo)); |
+ } |
- if (!(flags & SMIME_DETACHED)) |
- { |
- SMIME_crlf_copy(data, out, flags); |
- return 1; |
- } |
+/* CMS wrappers round generalised stream and MIME routines */ |
- /* Let CMS code prepend any needed BIOs */ |
+int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags) |
+ { |
+ return i2d_ASN1_bio_stream(out, (ASN1_VALUE *)cms, in, flags, |
+ ASN1_ITEM_rptr(CMS_ContentInfo)); |
+ } |
- cmsbio = CMS_dataInit(cms, out); |
- |
- if (!cmsbio) |
- return 0; |
- |
- /* Copy data across, passing through filter BIOs for processing */ |
- SMIME_crlf_copy(data, cmsbio, flags); |
- |
- /* Finalize structure */ |
- if (CMS_dataFinal(cms, cmsbio) <= 0) |
- goto err; |
- |
- r = 1; |
- |
- err: |
- |
- /* Now remove any digests prepended to the BIO */ |
- |
- while (cmsbio != out) |
- { |
- tmpbio = BIO_pop(cmsbio); |
- BIO_free(cmsbio); |
- cmsbio = tmpbio; |
- } |
- |
- return 1; |
- |
+int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags) |
+ { |
+ return PEM_write_bio_ASN1_stream(out, (ASN1_VALUE *) cms, in, flags, |
+ "CMS", |
+ ASN1_ITEM_rptr(CMS_ContentInfo)); |
} |
- |
int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags) |
{ |
STACK_OF(X509_ALGOR) *mdalgs; |
@@ -127,9 +120,8 @@ |
else |
mdalgs = NULL; |
- return int_smime_write_ASN1(bio, (ASN1_VALUE *)cms, data, flags, |
+ return SMIME_write_ASN1(bio, (ASN1_VALUE *)cms, data, flags, |
ctype_nid, econt_nid, mdalgs, |
- cms_output_data, |
ASN1_ITEM_rptr(CMS_ContentInfo)); |
} |
@@ -138,3 +130,4 @@ |
return (CMS_ContentInfo *)SMIME_read_ASN1(bio, bcont, |
ASN1_ITEM_rptr(CMS_ContentInfo)); |
} |
+ |