/src/openssl111/crypto/cms/cms_io.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved. | 
| 3 |  |  * | 
| 4 |  |  * Licensed under the OpenSSL license (the "License").  You may not use | 
| 5 |  |  * this file except in compliance with the License.  You can obtain a copy | 
| 6 |  |  * in the file LICENSE in the source distribution or at | 
| 7 |  |  * https://www.openssl.org/source/license.html | 
| 8 |  |  */ | 
| 9 |  |  | 
| 10 |  | #include <openssl/asn1t.h> | 
| 11 |  | #include <openssl/x509.h> | 
| 12 |  | #include <openssl/err.h> | 
| 13 |  | #include <openssl/pem.h> | 
| 14 |  | #include <openssl/cms.h> | 
| 15 |  | #include "cms_local.h" | 
| 16 |  |  | 
| 17 |  | int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms) | 
| 18 | 0 | { | 
| 19 | 0 |     ASN1_OCTET_STRING **pos; | 
| 20 | 0 |     pos = CMS_get0_content(cms); | 
| 21 | 0 |     if (pos == NULL) | 
| 22 | 0 |         return 0; | 
| 23 | 0 |     if (*pos == NULL) | 
| 24 | 0 |         *pos = ASN1_OCTET_STRING_new(); | 
| 25 | 0 |     if (*pos != NULL) { | 
| 26 | 0 |         (*pos)->flags |= ASN1_STRING_FLAG_NDEF; | 
| 27 | 0 |         (*pos)->flags &= ~ASN1_STRING_FLAG_CONT; | 
| 28 | 0 |         *boundary = &(*pos)->data; | 
| 29 | 0 |         return 1; | 
| 30 | 0 |     } | 
| 31 | 0 |     CMSerr(CMS_F_CMS_STREAM, ERR_R_MALLOC_FAILURE); | 
| 32 | 0 |     return 0; | 
| 33 | 0 | } | 
| 34 |  |  | 
| 35 |  | CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms) | 
| 36 | 0 | { | 
| 37 | 0 |     return ASN1_item_d2i_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms); | 
| 38 | 0 | } | 
| 39 |  |  | 
| 40 |  | int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms) | 
| 41 | 0 | { | 
| 42 | 0 |     return ASN1_item_i2d_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms); | 
| 43 | 0 | } | 
| 44 |  |  | 
| 45 |  | IMPLEMENT_PEM_rw_const(CMS, CMS_ContentInfo, PEM_STRING_CMS, CMS_ContentInfo) | 
| 46 |  |  | 
| 47 |  | BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms) | 
| 48 | 0 | { | 
| 49 | 0 |     return BIO_new_NDEF(out, (ASN1_VALUE *)cms, | 
| 50 | 0 |                         ASN1_ITEM_rptr(CMS_ContentInfo)); | 
| 51 | 0 | } | 
| 52 |  |  | 
| 53 |  | /* CMS wrappers round generalised stream and MIME routines */ | 
| 54 |  |  | 
| 55 |  | int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags) | 
| 56 | 0 | { | 
| 57 | 0 |     return i2d_ASN1_bio_stream(out, (ASN1_VALUE *)cms, in, flags, | 
| 58 | 0 |                                ASN1_ITEM_rptr(CMS_ContentInfo)); | 
| 59 | 0 | } | 
| 60 |  |  | 
| 61 |  | int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, | 
| 62 |  |                              int flags) | 
| 63 | 0 | { | 
| 64 | 0 |     return PEM_write_bio_ASN1_stream(out, (ASN1_VALUE *)cms, in, flags, | 
| 65 | 0 |                                      "CMS", ASN1_ITEM_rptr(CMS_ContentInfo)); | 
| 66 | 0 | } | 
| 67 |  |  | 
| 68 |  | int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags) | 
| 69 | 0 | { | 
| 70 | 0 |     STACK_OF(X509_ALGOR) *mdalgs; | 
| 71 | 0 |     int ctype_nid = OBJ_obj2nid(cms->contentType); | 
| 72 | 0 |     int econt_nid = OBJ_obj2nid(CMS_get0_eContentType(cms)); | 
| 73 | 0 |     if (ctype_nid == NID_pkcs7_signed) | 
| 74 | 0 |         mdalgs = cms->d.signedData->digestAlgorithms; | 
| 75 | 0 |     else | 
| 76 | 0 |         mdalgs = NULL; | 
| 77 |  | 
 | 
| 78 | 0 |     return SMIME_write_ASN1(bio, (ASN1_VALUE *)cms, data, flags, | 
| 79 | 0 |                             ctype_nid, econt_nid, mdalgs, | 
| 80 | 0 |                             ASN1_ITEM_rptr(CMS_ContentInfo)); | 
| 81 | 0 | } | 
| 82 |  |  | 
| 83 |  | CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont) | 
| 84 | 0 | { | 
| 85 | 0 |     return (CMS_ContentInfo *)SMIME_read_ASN1(bio, bcont, | 
| 86 | 0 |                                               ASN1_ITEM_rptr | 
| 87 | 0 |                                               (CMS_ContentInfo)); | 
| 88 | 0 | } |