• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_x500_distinguished_name.h"
19 
FfiCertCjX500DistinguishedNameNewInstance(const CfBlob * blob,bool bString,CjX500DistinguishedName * returnObj)20 int32_t FfiCertCjX500DistinguishedNameNewInstance(const CfBlob *blob, bool bString, CjX500DistinguishedName *returnObj)
21 {
22     auto name = static_cast<HcfX509DistinguishedName *>(malloc(sizeof(HcfX509DistinguishedName)));
23     if (name == nullptr) {
24         return CF_ERR_MALLOC;
25     }
26     const auto errCode = HcfX509DistinguishedNameCreate(blob, bString, &name);
27     if (errCode != CF_SUCCESS) {
28         free(name);
29         return errCode;
30     }
31     returnObj->name = name;
32     return CF_SUCCESS;
33 }
34 
FfiCertCjX500DistinguishedNameDeleteInstance(CjX500DistinguishedName self)35 void FfiCertCjX500DistinguishedNameDeleteInstance(CjX500DistinguishedName self)
36 {
37     CfObjDestroy(self.name);
38 }
39 
FfiCertCjX500DistinguishedNameGetEncoded(const CjX500DistinguishedName self,CfEncodingBlob * out)40 CfResult FfiCertCjX500DistinguishedNameGetEncoded(const CjX500DistinguishedName self, CfEncodingBlob *out)
41 {
42     return self.name->getEncode(self.name, out);
43 }
44 
FfiCertCjX500DistinguishedNameGetName(const CjX500DistinguishedName self,CfBlob * type,CfBlob * out,CfArray * outArr)45 CfResult FfiCertCjX500DistinguishedNameGetName(const CjX500DistinguishedName self, CfBlob *type, CfBlob *out,
46                                                CfArray *outArr)
47 {
48     return self.name->getName(self.name, type, out, outArr);
49 }
50