1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CERT_CMS_GENERATOR_H 17 #define CERT_CMS_GENERATOR_H 18 19 #include <stddef.h> 20 #include <stdint.h> 21 #include "cf_blob.h" 22 #include "cf_object_base.h" 23 #include "cf_result.h" 24 #include "cf_type.h" 25 #include "x509_certificate.h" 26 27 typedef struct HcfCmsSignerOptions HcfCmsSignerOptions; 28 struct HcfCmsSignerOptions { 29 char *mdName; 30 bool addCert; 31 bool addAttr; 32 bool addSmimeCapAttr; 33 }; 34 35 typedef struct HcfCmsGeneratorOptions HcfCmsGeneratorOptions; 36 struct HcfCmsGeneratorOptions { 37 HcfCmsContentDataFormat dataFormat; 38 HcfCmsFormat outFormat; 39 bool isDetachedContent; 40 }; 41 42 typedef struct HcfCmsGenerator HcfCmsGenerator; 43 44 struct HcfCmsGenerator { 45 struct CfObjectBase base; 46 47 /** add signer to cms generator. */ 48 CfResult (*addSigner)(HcfCmsGenerator *self, const HcfCertificate *x509Cert, 49 const PrivateKeyInfo *privateKey, const HcfCmsSignerOptions *options); 50 /** add other certificate to cms generator. */ 51 CfResult (*addCert)(HcfCmsGenerator *self, const HcfCertificate *x509Cert); 52 /** do final to cms generator. */ 53 CfResult (*doFinal)(HcfCmsGenerator *self, const CfBlob *content, const HcfCmsGeneratorOptions *options, 54 CfBlob *out); 55 }; 56 57 #ifdef __cplusplus 58 extern "C" { 59 #endif 60 61 /** 62 * @brief Generate Cms generator instance. 63 */ 64 CfResult HcfCreateCmsGenerator(HcfCmsContentType type, HcfCmsGenerator **cmsGenerator); 65 66 #ifdef __cplusplus 67 } 68 #endif 69 70 #endif // CERT_CMS_GENERATOR_H 71