/* * Copyright 2008-2020 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */#include"internal/cryptlib.h"#include<openssl/asn1t.h>#include<openssl/pem.h>#include<openssl/x509v3.h>#include<openssl/err.h>#include<openssl/cms.h>#include<openssl/evp.h>#include"crypto/asn1.h"#include"crypto/evp.h"#include"crypto/x509.h"#include"cms_local.h"/* CMS EnvelopedData Utilities */staticvoidcms_env_set_version(CMS_EnvelopedData*env);#define CMS_ENVELOPED_STANDARD 1#define CMS_ENVELOPED_AUTH 2staticintcms_get_enveloped_type(constCMS_ContentInfo*cms){intnid=OBJ_obj2nid(cms->contentType);switch(nid){caseNID_pkcs7_enveloped:returnCMS_ENVELOPED_STANDARD;caseNID_id_smime_ct_authEnvelopedData:returnCMS_ENVELOPED_AUTH;default:CMSerr(0,CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA);return0;}}CMS_EnvelopedData*cms_get0_enveloped(CMS_ContentInfo*cms){if(OBJ_obj2nid(cms->contentType)!=NID_pkcs7_enveloped){CMSerr(CMS_F_CMS_GET0_ENVELOPED,CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA);returnNULL;}returncms->d.envelopedData;}CMS_AuthEnvelopedData*cms_get0_auth_enveloped(CMS_ContentInfo*cms){if(OBJ_obj2nid(cms->contentType)!=NID_id_smime_ct_authEnvelopedData){CMSerr(0,CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA);returnNULL;}returncms->d.authEnvelopedData;}staticCMS_EnvelopedData*cms_enveloped_data_init(CMS_ContentInfo*cms){if(cms->d.other==NULL){cms->d.envelopedData=M_ASN1_new_of(CMS_EnvelopedData);if(cms->d.envelopedData==NULL){CMSerr(CMS_F_CMS_ENVELOPED_DATA_INIT,ERR_R_MALLOC_FAILURE);returnNULL;}