diff options
Diffstat (limited to 'src/lib/libcrypto/cms/cms_io.c')
-rw-r--r-- | src/lib/libcrypto/cms/cms_io.c | 79 |
1 files changed, 36 insertions, 43 deletions
diff --git a/src/lib/libcrypto/cms/cms_io.c b/src/lib/libcrypto/cms/cms_io.c index 30f5ddfe6d..1cb0264cc5 100644 --- a/src/lib/libcrypto/cms/cms_io.c +++ b/src/lib/libcrypto/cms/cms_io.c | |||
@@ -58,6 +58,25 @@ | |||
58 | #include "cms.h" | 58 | #include "cms.h" |
59 | #include "cms_lcl.h" | 59 | #include "cms_lcl.h" |
60 | 60 | ||
61 | int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms) | ||
62 | { | ||
63 | ASN1_OCTET_STRING **pos; | ||
64 | pos = CMS_get0_content(cms); | ||
65 | if (!pos) | ||
66 | return 0; | ||
67 | if (!*pos) | ||
68 | *pos = ASN1_OCTET_STRING_new(); | ||
69 | if (*pos) | ||
70 | { | ||
71 | (*pos)->flags |= ASN1_STRING_FLAG_NDEF; | ||
72 | (*pos)->flags &= ~ASN1_STRING_FLAG_CONT; | ||
73 | *boundary = &(*pos)->data; | ||
74 | return 1; | ||
75 | } | ||
76 | CMSerr(CMS_F_CMS_STREAM, ERR_R_MALLOC_FAILURE); | ||
77 | return 0; | ||
78 | } | ||
79 | |||
61 | CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms) | 80 | CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms) |
62 | { | 81 | { |
63 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms); | 82 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms); |
@@ -70,52 +89,26 @@ int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms) | |||
70 | 89 | ||
71 | IMPLEMENT_PEM_rw_const(CMS, CMS_ContentInfo, PEM_STRING_CMS, CMS_ContentInfo) | 90 | IMPLEMENT_PEM_rw_const(CMS, CMS_ContentInfo, PEM_STRING_CMS, CMS_ContentInfo) |
72 | 91 | ||
73 | /* Callback for int_smime_write_ASN1 */ | 92 | BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms) |
74 | |||
75 | static int cms_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, | ||
76 | const ASN1_ITEM *it) | ||
77 | { | 93 | { |
78 | CMS_ContentInfo *cms = (CMS_ContentInfo *)val; | 94 | return BIO_new_NDEF(out, (ASN1_VALUE *)cms, |
79 | BIO *tmpbio, *cmsbio; | 95 | ASN1_ITEM_rptr(CMS_ContentInfo)); |
80 | int r = 0; | 96 | } |
81 | |||
82 | if (!(flags & SMIME_DETACHED)) | ||
83 | { | ||
84 | SMIME_crlf_copy(data, out, flags); | ||
85 | return 1; | ||
86 | } | ||
87 | |||
88 | /* Let CMS code prepend any needed BIOs */ | ||
89 | |||
90 | cmsbio = CMS_dataInit(cms, out); | ||
91 | |||
92 | if (!cmsbio) | ||
93 | return 0; | ||
94 | |||
95 | /* Copy data across, passing through filter BIOs for processing */ | ||
96 | SMIME_crlf_copy(data, cmsbio, flags); | ||
97 | |||
98 | /* Finalize structure */ | ||
99 | if (CMS_dataFinal(cms, cmsbio) <= 0) | ||
100 | goto err; | ||
101 | |||
102 | r = 1; | ||
103 | |||
104 | err: | ||
105 | |||
106 | /* Now remove any digests prepended to the BIO */ | ||
107 | |||
108 | while (cmsbio != out) | ||
109 | { | ||
110 | tmpbio = BIO_pop(cmsbio); | ||
111 | BIO_free(cmsbio); | ||
112 | cmsbio = tmpbio; | ||
113 | } | ||
114 | 97 | ||
115 | return 1; | 98 | /* CMS wrappers round generalised stream and MIME routines */ |
116 | 99 | ||
100 | int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags) | ||
101 | { | ||
102 | return i2d_ASN1_bio_stream(out, (ASN1_VALUE *)cms, in, flags, | ||
103 | ASN1_ITEM_rptr(CMS_ContentInfo)); | ||
117 | } | 104 | } |
118 | 105 | ||
106 | int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags) | ||
107 | { | ||
108 | return PEM_write_bio_ASN1_stream(out, (ASN1_VALUE *) cms, in, flags, | ||
109 | "CMS", | ||
110 | ASN1_ITEM_rptr(CMS_ContentInfo)); | ||
111 | } | ||
119 | 112 | ||
120 | int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags) | 113 | int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags) |
121 | { | 114 | { |
@@ -127,9 +120,8 @@ int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags) | |||
127 | else | 120 | else |
128 | mdalgs = NULL; | 121 | mdalgs = NULL; |
129 | 122 | ||
130 | return int_smime_write_ASN1(bio, (ASN1_VALUE *)cms, data, flags, | 123 | return SMIME_write_ASN1(bio, (ASN1_VALUE *)cms, data, flags, |
131 | ctype_nid, econt_nid, mdalgs, | 124 | ctype_nid, econt_nid, mdalgs, |
132 | cms_output_data, | ||
133 | ASN1_ITEM_rptr(CMS_ContentInfo)); | 125 | ASN1_ITEM_rptr(CMS_ContentInfo)); |
134 | } | 126 | } |
135 | 127 | ||
@@ -138,3 +130,4 @@ CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont) | |||
138 | return (CMS_ContentInfo *)SMIME_read_ASN1(bio, bcont, | 130 | return (CMS_ContentInfo *)SMIME_read_ASN1(bio, bcont, |
139 | ASN1_ITEM_rptr(CMS_ContentInfo)); | 131 | ASN1_ITEM_rptr(CMS_ContentInfo)); |
140 | } | 132 | } |
133 | |||