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 CF_BLOB_H
17 #define CF_BLOB_H
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 #include <stdbool.h>
22 
23 typedef struct CfBlob CfBlob;
24 struct CfBlob {
25     uint32_t size;
26     uint8_t *data;
27 };
28 
29 enum CfEncodingFormat {
30     CF_FORMAT_DER = 0,
31     CF_FORMAT_PEM = 1,
32     CF_FORMAT_PKCS7 = 2,
33 };
34 
35 typedef struct {
36     uint8_t *data;
37     size_t len;
38     enum CfEncodingFormat encodingFormat;
39 } CfEncodingBlob;
40 
41 typedef struct {
42     CfBlob *data;
43     enum CfEncodingFormat format;
44     uint32_t count;
45 } CfArray;
46 
47 typedef struct {
48     CfBlob *data;
49     uint32_t count;
50 } CfBlobArray;
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 void CfBlobFree(CfBlob **blob);
57 void CfBlobDataFree(CfBlob *blob);
58 void CfBlobDataClearAndFree(CfBlob *blob);
59 void CfEncodingBlobDataFree(CfEncodingBlob *encodingBlob);
60 void CfArrayDataClearAndFree(CfArray *array);
61 void FreeCfBlobArray(CfBlob *array, uint32_t arrayLen);
62 bool CfBlobIsStr(const CfBlob *blob);
63 
64 #ifdef __cplusplus
65 }
66 #endif
67 
68 #endif
69