1 /*
2  * Copyright (c) 2023 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_CRL_COLLECTION_H
17 #define CERT_CRL_COLLECTION_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 "x509_cert_match_parameters.h"
25 #include "x509_crl_match_parameters.h"
26 #include "x509_certificate.h"
27 #include "x509_crl.h"
28 
29 #define MAX_LEN_OF_CERT_CRL_ARR 1024
30 
31 typedef struct HcfCertCrlCollection HcfCertCrlCollection;
32 
33 struct HcfCertCrlCollection {
34     struct CfObjectBase base;
35 
36     /** Get certs list which match HcfX509CertMatchParams. */
37     CfResult (*selectCerts)(
38         HcfCertCrlCollection *self, const HcfX509CertMatchParams *matchParams, HcfX509CertificateArray *retCerts);
39 
40     /** Get CRLs list which match HcfX509CrlMatchParams. */
41     CfResult (*selectCRLs)(
42         HcfCertCrlCollection *self, const HcfX509CrlMatchParams *matchParams, HcfX509CrlArray *retCrls);
43 
44     /** Get CRLs list (without clone) in cert crl collection. */
45     CfResult (*getCRLs)(HcfCertCrlCollection *self, HcfX509CrlArray **retCrls);
46 };
47 
48 typedef struct HcfCertCRLCollectionArray HcfCertCRLCollectionArray;
49 struct HcfCertCRLCollectionArray {
50     HcfCertCrlCollection **data;
51     uint32_t count;
52 };
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 /**
59  * @brief Generate cert crl collection instance.
60  */
61 CfResult HcfCertCrlCollectionCreate(
62     const HcfX509CertificateArray *inCerts, const HcfX509CrlArray *inCrls, HcfCertCrlCollection **out);
63 
64 #ifdef __cplusplus
65 }
66 #endif
67 
68 #endif // CERT_CRL_COLLECTION_H
69