1 /*
2  * Copyright (c) 2023-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 CF_X509_CERT_CHAIN_H
17 #define CF_X509_CERT_CHAIN_H
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 #include "cf_blob.h"
23 #include "cf_object_base.h"
24 #include "cf_result.h"
25 #include "x509_cert_chain_validate_params.h"
26 #include "x509_cert_chain_validate_result.h"
27 #include "x509_certificate.h"
28 
29 typedef struct HcfCertChain HcfCertChain;
30 struct HcfCertChain {
31     struct CfObjectBase base;
32 
33     /** Get cert array. */
34     CfResult (*getCertList)(HcfCertChain *self, HcfX509CertificateArray *out);
35 
36     /** Validate Cert Chain. */
37     CfResult (*validate)(
38         HcfCertChain *self, const HcfX509CertChainValidateParams *params, HcfX509CertChainValidateResult *result);
39 
40     /** Get the string of Cert Chain. */
41     CfResult (*toString)(HcfCertChain *self, CfBlob *out);
42 
43     /** Get the hashCode of Cert Chain. */
44     CfResult (*hashCode)(HcfCertChain *self, CfBlob *out);
45 };
46 
47 typedef struct HcfX509CertChainBuildResult HcfX509CertChainBuildResult;
48 struct HcfX509CertChainBuildResult {
49     CfObjectBase base;
50     HcfCertChain *certChain;
51     HcfX509CertChainValidateResult validateResult;
52 };
53 
54 typedef struct HcfX509CertChainBuildParameters HcfX509CertChainBuildParameters;
55 struct HcfX509CertChainBuildParameters {
56     HcfX509CertMatchParams certMatchParameters;
57     int32_t maxlength;
58     HcfX509CertChainValidateParams validateParameters;
59 };
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 /**
66  * @brief Generate cert chain instance.
67  */
68 CfResult HcfCertChainCreate(
69     const CfEncodingBlob *inStream, const HcfX509CertificateArray *inCerts, HcfCertChain **returnObj);
70 
71 CfResult HcfCertChainBuildResultCreate(
72     const HcfX509CertChainBuildParameters *inParams, HcfX509CertChainBuildResult **returnObj);
73 
74 CfResult HcfCreateTrustAnchorWithKeyStore(
75     const CfBlob *keyStore, const CfBlob *pwd, HcfX509TrustAnchorArray **trustAnchorArray);
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #endif // CF_X509_CERT_CHAIN_H
82