]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/cms/cms_cd.c
Convert all {NAME}err() in crypto/ to their corresponding ERR_raise() call
[thirdparty/openssl.git] / crypto / cms / cms_cd.c
CommitLineData
0f113f3e 1/*
eec0ad10 2 * Copyright 2008-2020 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>
706457b7 18#include "cms_local.h"
8931b30d 19
8931b30d
DSH
20#ifdef ZLIB
21
22/* CMS CompressedData Utilities */
23
b4250010 24CMS_ContentInfo *cms_CompressedData_create(int comp_nid, OSSL_LIB_CTX *libctx,
c1669f41 25 const char *propq)
0f113f3e
MC
26{
27 CMS_ContentInfo *cms;
28 CMS_CompressedData *cd;
c1669f41 29
0f113f3e
MC
30 /*
31 * Will need something cleverer if there is ever more than one
32 * compression algorithm or parameters have some meaning...
33 */
34 if (comp_nid != NID_zlib_compression) {
9311d0c4 35 ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
0f113f3e
MC
36 return NULL;
37 }
d8652be0 38 cms = CMS_ContentInfo_new_ex(libctx, propq);
90945fa3 39 if (cms == NULL)
0f113f3e 40 return NULL;
8931b30d 41
0f113f3e 42 cd = M_ASN1_new_of(CMS_CompressedData);
8931b30d 43
90945fa3 44 if (cd == NULL)
0f113f3e 45 goto err;
8931b30d 46
0f113f3e
MC
47 cms->contentType = OBJ_nid2obj(NID_id_smime_ct_compressedData);
48 cms->d.compressedData = cd;
8931b30d 49
0f113f3e 50 cd->version = 0;
8931b30d 51
0f113f3e
MC
52 X509_ALGOR_set0(cd->compressionAlgorithm,
53 OBJ_nid2obj(NID_zlib_compression), V_ASN1_UNDEF, NULL);
8931b30d 54
0f113f3e 55 cd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data);
8931b30d 56
0f113f3e 57 return cms;
8931b30d 58
0f113f3e 59 err:
25aaa98a 60 CMS_ContentInfo_free(cms);
0f113f3e
MC
61 return NULL;
62}
8931b30d 63
0fc4d00a 64BIO *cms_CompressedData_init_bio(const CMS_ContentInfo *cms)
0f113f3e
MC
65{
66 CMS_CompressedData *cd;
5dfd0381 67 const ASN1_OBJECT *compoid;
c1669f41 68
0f113f3e 69 if (OBJ_obj2nid(cms->contentType) != NID_id_smime_ct_compressedData) {
9311d0c4 70 ERR_raise(ERR_LIB_CMS, CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA);
0f113f3e
MC
71 return NULL;
72 }
73 cd = cms->d.compressedData;
74 X509_ALGOR_get0(&compoid, NULL, NULL, cd->compressionAlgorithm);
75 if (OBJ_obj2nid(compoid) != NID_zlib_compression) {
9311d0c4 76 ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
0f113f3e
MC
77 return NULL;
78 }
79 return BIO_new(BIO_f_zlib());
80}
8931b30d
DSH
81
82#endif