/* * Copyright 2008-2021 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"internal/sizes.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:ERR_raise(ERR_LIB_CMS,CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA);return0;}}CMS_EnvelopedData*ossl_cms_get0_enveloped(CMS_ContentInfo*cms){if(OBJ_obj2nid(cms->contentType)!=NID_pkcs7_enveloped){ERR_raise(ERR_LIB_CMS,CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA);returnNULL;}returncms->d.envelopedData;}CMS_AuthEnvelopedData*ossl_cms_get0_auth_enveloped(CMS_ContentInfo*cms){if(OBJ_obj2nid(cms->contentType)!=NID_id_smime_ct_authEnvelopedData){ERR_raise(ERR_LIB_CMS,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){ERR_raise(ERR_LIB_CMS,ERR_R_MALLOC_FAILURE);