• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 typedef struct {
53     uint32_t size;
54     int64_t *data;
55 } CfInt64Array;
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 void CfBlobFree(CfBlob **blob);
62 void CfBlobDataFree(CfBlob *blob);
63 void CfBlobDataClearAndFree(CfBlob *blob);
64 void CfEncodingBlobDataFree(CfEncodingBlob *encodingBlob);
65 void CfArrayDataClearAndFree(CfArray *array);
66 void FreeCfBlobArray(CfBlob *array, uint32_t arrayLen);
67 bool CfBlobIsStr(const CfBlob *blob);
68 
69 #ifdef __cplusplus
70 }
71 #endif
72 
73 #endif
74