]>
Commit | Line | Data |
---|---|---|
0f113f3e | 1 | /* |
b1322259 | 2 | * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved. |
8931b30d | 3 | * |
08ddd302 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
b1322259 RS |
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 | |
8931b30d DSH |
8 | */ |
9 | ||
b39fc560 | 10 | #include "internal/cryptlib.h" |
8931b30d DSH |
11 | #include <openssl/asn1t.h> |
12 | #include <openssl/pem.h> | |
13 | #include <openssl/x509v3.h> | |
14 | #include <openssl/err.h> | |
15 | #include <openssl/cms.h> | |
16 | #include <openssl/bio.h> | |
3c27208f | 17 | #include <openssl/comp.h> |
8931b30d | 18 | #include "cms_lcl.h" |
8931b30d | 19 | |
8931b30d DSH |
20 | #ifdef ZLIB |
21 | ||
22 | /* CMS CompressedData Utilities */ | |
23 | ||
24 | CMS_ContentInfo *cms_CompressedData_create(int comp_nid) | |
0f113f3e MC |
25 | { |
26 | CMS_ContentInfo *cms; | |
27 | CMS_CompressedData *cd; | |
28 | /* | |
29 | * Will need something cleverer if there is ever more than one | |
30 | * compression algorithm or parameters have some meaning... | |
31 | */ | |
32 | if (comp_nid != NID_zlib_compression) { | |
33 | CMSerr(CMS_F_CMS_COMPRESSEDDATA_CREATE, | |
34 | CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); | |
35 | return NULL; | |
36 | } | |
37 | cms = CMS_ContentInfo_new(); | |
90945fa3 | 38 | if (cms == NULL) |
0f113f3e | 39 | return NULL; |
8931b30d | 40 | |
0f113f3e | 41 | cd = M_ASN1_new_of(CMS_CompressedData); |
8931b30d | 42 | |
90945fa3 | 43 | if (cd == NULL) |
0f113f3e | 44 | goto err; |
8931b30d | 45 | |
0f113f3e MC |
46 | cms->contentType = OBJ_nid2obj(NID_id_smime_ct_compressedData); |
47 | cms->d.compressedData = cd; | |
8931b30d | 48 | |
0f113f3e | 49 | cd->version = 0; |
8931b30d | 50 | |
0f113f3e MC |
51 | X509_ALGOR_set0(cd->compressionAlgorithm, |
52 | OBJ_nid2obj(NID_zlib_compression), V_ASN1_UNDEF, NULL); | |
8931b30d | 53 | |
0f113f3e | 54 | cd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data); |
8931b30d | 55 | |
0f113f3e | 56 | return cms; |
8931b30d | 57 | |
0f113f3e | 58 | err: |
25aaa98a | 59 | CMS_ContentInfo_free(cms); |
0f113f3e MC |
60 | return NULL; |
61 | } | |
8931b30d | 62 | |
0fc4d00a | 63 | BIO *cms_CompressedData_init_bio(const CMS_ContentInfo *cms) |
0f113f3e MC |
64 | { |
65 | CMS_CompressedData *cd; | |
5dfd0381 | 66 | const ASN1_OBJECT *compoid; |
0f113f3e MC |
67 | if (OBJ_obj2nid(cms->contentType) != NID_id_smime_ct_compressedData) { |
68 | CMSerr(CMS_F_CMS_COMPRESSEDDATA_INIT_BIO, | |
69 | CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA); | |
70 | return NULL; | |
71 | } | |
72 | cd = cms->d.compressedData; | |
73 | X509_ALGOR_get0(&compoid, NULL, NULL, cd->compressionAlgorithm); | |
74 | if (OBJ_obj2nid(compoid) != NID_zlib_compression) { | |
75 | CMSerr(CMS_F_CMS_COMPRESSEDDATA_INIT_BIO, | |
76 | CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); | |
77 | return NULL; | |
78 | } | |
79 | return BIO_new(BIO_f_zlib()); | |
80 | } | |
8931b30d DSH |
81 | |
82 | #endif |