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 #include <cstdlib>
17
18 #include "cj_certchain_validator.h"
19
FfiCertCjCertChainValidatorNewInstance(const char * algorithm,CjCertChainValidator * returnObj)20 int32_t FfiCertCjCertChainValidatorNewInstance(const char *algorithm, CjCertChainValidator *returnObj)
21 {
22 auto validator = static_cast<HcfCertChainValidator *>(malloc(sizeof(HcfCertChainValidator)));
23 if (validator == nullptr) {
24 return CF_ERR_MALLOC;
25 }
26 const auto errCode = HcfCertChainValidatorCreate(algorithm, &validator);
27 if (errCode != CF_SUCCESS) {
28 free(validator);
29 return errCode;
30 }
31 returnObj->validator = validator;
32 return CF_SUCCESS;
33 }
34
FfiCertCjCertChainValidatorDeleteInstance(CjCertChainValidator self)35 void FfiCertCjCertChainValidatorDeleteInstance(CjCertChainValidator self)
36 {
37 CfObjDestroy(self.validator);
38 }
39
FfiCertCjCertChainValidatorValidate(const CjCertChainValidator self,const HcfCertChainData * certChainData)40 CfResult FfiCertCjCertChainValidatorValidate(const CjCertChainValidator self,
41 const HcfCertChainData *certChainData)
42 {
43 return self.validator->validate(self.validator, certChainData);
44 }
45