diff options
author | tedu <> | 2014-04-18 00:58:49 +0000 |
---|---|---|
committer | tedu <> | 2014-04-18 00:58:49 +0000 |
commit | a1df5b66c7ad477a535e56a504d8da47e1998cfa (patch) | |
tree | b216ca6fba673789f2c494699c4cf41d23337bfa /src/lib/libcrypto/asn1/asn_mime.c | |
parent | 07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d (diff) | |
download | openbsd-a1df5b66c7ad477a535e56a504d8da47e1998cfa.tar.gz openbsd-a1df5b66c7ad477a535e56a504d8da47e1998cfa.tar.bz2 openbsd-a1df5b66c7ad477a535e56a504d8da47e1998cfa.zip |
lob a few more knf grenades in here to soften things up.
Diffstat (limited to 'src/lib/libcrypto/asn1/asn_mime.c')
-rw-r--r-- | src/lib/libcrypto/asn1/asn_mime.c | 56 |
1 files changed, 18 insertions, 38 deletions
diff --git a/src/lib/libcrypto/asn1/asn_mime.c b/src/lib/libcrypto/asn1/asn_mime.c index 011b97ff92..6cde8fd44e 100644 --- a/src/lib/libcrypto/asn1/asn_mime.c +++ b/src/lib/libcrypto/asn1/asn_mime.c | |||
@@ -116,20 +116,17 @@ int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, | |||
116 | const ASN1_ITEM *it) | 116 | const ASN1_ITEM *it) |
117 | { | 117 | { |
118 | /* If streaming create stream BIO and copy all content through it */ | 118 | /* If streaming create stream BIO and copy all content through it */ |
119 | if (flags & SMIME_STREAM) | 119 | if (flags & SMIME_STREAM) { |
120 | { | ||
121 | BIO *bio, *tbio; | 120 | BIO *bio, *tbio; |
122 | bio = BIO_new_NDEF(out, val, it); | 121 | bio = BIO_new_NDEF(out, val, it); |
123 | if (!bio) | 122 | if (!bio) { |
124 | { | ||
125 | ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,ERR_R_MALLOC_FAILURE); | 123 | ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM,ERR_R_MALLOC_FAILURE); |
126 | return 0; | 124 | return 0; |
127 | } | 125 | } |
128 | SMIME_crlf_copy(in, bio, flags); | 126 | SMIME_crlf_copy(in, bio, flags); |
129 | (void)BIO_flush(bio); | 127 | (void)BIO_flush(bio); |
130 | /* Free up successive BIOs until we hit the old output BIO */ | 128 | /* Free up successive BIOs until we hit the old output BIO */ |
131 | do | 129 | do { |
132 | { | ||
133 | tbio = BIO_pop(bio); | 130 | tbio = BIO_pop(bio); |
134 | BIO_free(bio); | 131 | BIO_free(bio); |
135 | bio = tbio; | 132 | bio = tbio; |
@@ -151,8 +148,7 @@ static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags, | |||
151 | BIO *b64; | 148 | BIO *b64; |
152 | int r; | 149 | int r; |
153 | b64 = BIO_new(BIO_f_base64()); | 150 | b64 = BIO_new(BIO_f_base64()); |
154 | if(!b64) | 151 | if(!b64) { |
155 | { | ||
156 | ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE); | 152 | ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE); |
157 | return 0; | 153 | return 0; |
158 | } | 154 | } |
@@ -205,20 +201,17 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) | |||
205 | int i, have_unknown = 0, write_comma, ret = 0, md_nid; | 201 | int i, have_unknown = 0, write_comma, ret = 0, md_nid; |
206 | have_unknown = 0; | 202 | have_unknown = 0; |
207 | write_comma = 0; | 203 | write_comma = 0; |
208 | for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) | 204 | for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) { |
209 | { | ||
210 | if (write_comma) | 205 | if (write_comma) |
211 | BIO_write(out, ",", 1); | 206 | BIO_write(out, ",", 1); |
212 | write_comma = 1; | 207 | write_comma = 1; |
213 | md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm); | 208 | md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm); |
214 | md = EVP_get_digestbynid(md_nid); | 209 | md = EVP_get_digestbynid(md_nid); |
215 | if (md && md->md_ctrl) | 210 | if (md && md->md_ctrl) { |
216 | { | ||
217 | int rv; | 211 | int rv; |
218 | char *micstr; | 212 | char *micstr; |
219 | rv = md->md_ctrl(NULL, EVP_MD_CTRL_MICALG, 0, &micstr); | 213 | rv = md->md_ctrl(NULL, EVP_MD_CTRL_MICALG, 0, &micstr); |
220 | if (rv > 0) | 214 | if (rv > 0) { |
221 | { | ||
222 | BIO_puts(out, micstr); | 215 | BIO_puts(out, micstr); |
223 | free(micstr); | 216 | free(micstr); |
224 | continue; | 217 | continue; |
@@ -226,8 +219,7 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) | |||
226 | if (rv != -2) | 219 | if (rv != -2) |
227 | goto err; | 220 | goto err; |
228 | } | 221 | } |
229 | switch(md_nid) | 222 | switch(md_nid) { |
230 | { | ||
231 | case NID_sha1: | 223 | case NID_sha1: |
232 | BIO_puts(out, "sha1"); | 224 | BIO_puts(out, "sha1"); |
233 | break; | 225 | break; |
@@ -256,8 +248,7 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) | |||
256 | default: | 248 | default: |
257 | if (have_unknown) | 249 | if (have_unknown) |
258 | write_comma = 0; | 250 | write_comma = 0; |
259 | else | 251 | else { |
260 | { | ||
261 | BIO_puts(out, "unknown"); | 252 | BIO_puts(out, "unknown"); |
262 | have_unknown = 1; | 253 | have_unknown = 1; |
263 | } | 254 | } |
@@ -338,17 +329,14 @@ int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, | |||
338 | 329 | ||
339 | if (ctype_nid == NID_pkcs7_enveloped) | 330 | if (ctype_nid == NID_pkcs7_enveloped) |
340 | msg_type = "enveloped-data"; | 331 | msg_type = "enveloped-data"; |
341 | else if (ctype_nid == NID_pkcs7_signed) | 332 | else if (ctype_nid == NID_pkcs7_signed) { |
342 | { | ||
343 | if (econt_nid == NID_id_smime_ct_receipt) | 333 | if (econt_nid == NID_id_smime_ct_receipt) |
344 | msg_type = "signed-receipt"; | 334 | msg_type = "signed-receipt"; |
345 | else if (sk_X509_ALGOR_num(mdalgs) >= 0) | 335 | else if (sk_X509_ALGOR_num(mdalgs) >= 0) |
346 | msg_type = "signed-data"; | 336 | msg_type = "signed-data"; |
347 | else | 337 | else |
348 | msg_type = "certs-only"; | 338 | msg_type = "certs-only"; |
349 | } | 339 | } else if (ctype_nid == NID_id_smime_ct_compressedData) { |
350 | else if (ctype_nid == NID_id_smime_ct_compressedData) | ||
351 | { | ||
352 | msg_type = "compressed-data"; | 340 | msg_type = "compressed-data"; |
353 | cname = "smime.p7z"; | 341 | cname = "smime.p7z"; |
354 | } | 342 | } |
@@ -382,14 +370,12 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, | |||
382 | /* If data is not deteched or resigning then the output BIO is | 370 | /* If data is not deteched or resigning then the output BIO is |
383 | * already set up to finalise when it is written through. | 371 | * already set up to finalise when it is written through. |
384 | */ | 372 | */ |
385 | if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) | 373 | if (!(flags & SMIME_DETACHED) || (flags & PKCS7_REUSE_DIGEST)) { |
386 | { | ||
387 | SMIME_crlf_copy(data, out, flags); | 374 | SMIME_crlf_copy(data, out, flags); |
388 | return 1; | 375 | return 1; |
389 | } | 376 | } |
390 | 377 | ||
391 | if (!aux || !aux->asn1_cb) | 378 | if (!aux || !aux->asn1_cb) { |
392 | { | ||
393 | ASN1err(ASN1_F_ASN1_OUTPUT_DATA, | 379 | ASN1err(ASN1_F_ASN1_OUTPUT_DATA, |
394 | ASN1_R_STREAMING_NOT_SUPPORTED); | 380 | ASN1_R_STREAMING_NOT_SUPPORTED); |
395 | return 0; | 381 | return 0; |
@@ -413,8 +399,7 @@ static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, | |||
413 | 399 | ||
414 | /* Now remove any digests prepended to the BIO */ | 400 | /* Now remove any digests prepended to the BIO */ |
415 | 401 | ||
416 | while (sarg.ndef_bio != out) | 402 | while (sarg.ndef_bio != out) { |
417 | { | ||
418 | tmpbio = BIO_pop(sarg.ndef_bio); | 403 | tmpbio = BIO_pop(sarg.ndef_bio); |
419 | BIO_free(sarg.ndef_bio); | 404 | BIO_free(sarg.ndef_bio); |
420 | sarg.ndef_bio = tmpbio; | 405 | sarg.ndef_bio = tmpbio; |
@@ -547,17 +532,13 @@ int SMIME_crlf_copy(BIO *in, BIO *out, int flags) | |||
547 | if (!bf) | 532 | if (!bf) |
548 | return 0; | 533 | return 0; |
549 | out = BIO_push(bf, out); | 534 | out = BIO_push(bf, out); |
550 | if(flags & SMIME_BINARY) | 535 | if(flags & SMIME_BINARY) { |
551 | { | ||
552 | while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0) | 536 | while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0) |
553 | BIO_write(out, linebuf, len); | 537 | BIO_write(out, linebuf, len); |
554 | } | 538 | } else { |
555 | else | ||
556 | { | ||
557 | if(flags & SMIME_TEXT) | 539 | if(flags & SMIME_TEXT) |
558 | BIO_printf(out, "Content-Type: text/plain\r\n\r\n"); | 540 | BIO_printf(out, "Content-Type: text/plain\r\n\r\n"); |
559 | while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) | 541 | while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) { |
560 | { | ||
561 | eol = strip_eol(linebuf, &len); | 542 | eol = strip_eol(linebuf, &len); |
562 | if (len) | 543 | if (len) |
563 | BIO_write(out, linebuf, len); | 544 | BIO_write(out, linebuf, len); |
@@ -944,8 +925,7 @@ static int strip_eol(char *linebuf, int *plen) | |||
944 | char *p, c; | 925 | char *p, c; |
945 | int is_eol = 0; | 926 | int is_eol = 0; |
946 | p = linebuf + len - 1; | 927 | p = linebuf + len - 1; |
947 | for (p = linebuf + len - 1; len > 0; len--, p--) | 928 | for (p = linebuf + len - 1; len > 0; len--, p--) { |
948 | { | ||
949 | c = *p; | 929 | c = *p; |
950 | if (c == '\n') | 930 | if (c == '\n') |
951 | is_eol = 1; | 931 | is_eol = 1; |