API参考
载入中...
搜索中...
未找到
bsl_asn1.h
1/*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 * http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15
16#ifndef BSL_ASN1_H
17#define BSL_ASN1_H
18
19#include <stdint.h>
20#include "bsl_types.h"
21#include "bsl_list.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#define BSL_ASN1_CLASS_UNIVERSAL 0x0 /* bit8 0, bit7 0 */
28#define BSL_ASN1_CLASS_APPLICATION 0x40 /* bit8 0, bit7 1 */
29#define BSL_ASN1_CLASS_CTX_SPECIFIC 0x80 /* bit8 1, bit7 0 */
30#define BSL_ASN1_CLASS_PRIVATE 0xC0 /* bit8 1, bit7 1 */
31
32#define BSL_ASN1_TAG_CONSTRUCTED 0x20
33
34/* ASN1 tag from x.680 */
35#define BSL_ASN1_TAG_BOOLEAN 0x01
36#define BSL_ASN1_TAG_INTEGER 0x02
37#define BSL_ASN1_TAG_BITSTRING 0x03
38#define BSL_ASN1_TAG_OCTETSTRING 0x04
39#define BSL_ASN1_TAG_NULL 0x05
40#define BSL_ASN1_TAG_OBJECT_ID 0x06
41#define BSL_ASN1_TAG_OBJECT_DESCP 0x07
42#define BSL_ASN1_TAG_INSTANCE_OF 0x08
43#define BSL_ASN1_TAG_REAL 0x09
44#define BSL_ASN1_TAG_ENUMERATED 0x0A
45#define BSL_ASN1_TAG_EMBEDDED_PDV 0x0B
46#define BSL_ASN1_TAG_UTF8STRING 0x0C
47#define BSL_ASN1_TAG_RALATIVE_ID 0x0D
48#define BSL_ASN1_TAG_TIME 0x0E
49#define BSL_ASN1_TAG_SEQUENCE 0x10
50#define BSL_ASN1_TAG_SET 0x11
51#define BSL_ASN1_TAG_PRINTABLESTRING 0x13
52#define BSL_ASN1_TAG_TELETEXSTRING 0x14
53#define BSL_ASN1_TAG_T61STRING BSL_ASN1_TAG_TELETEXSTRING
54#define BSL_ASN1_TAG_IA5STRING 0x16
55
56#define BSL_ASN1_TAG_UTCTIME 0x17
57#define BSL_ASN1_TAG_GENERALIZEDTIME 0x18
58#define BSL_ASN1_TAG_UNIVERSALSTRING 0x1C
59#define BSL_ASN1_TAG_BMPSTRING 0x1E
60
61/* Custom types, use private class to prevent conflicts */
62#define BSL_ASN1_TAG_CHOICE (BSL_ASN1_CLASS_PRIVATE | 1)
63#define BSL_ASN1_TAG_ANY (BSL_ASN1_CLASS_PRIVATE | 2)
64#define BSL_ASN1_TAG_EMPTY 0x00 /* Empty tag, used to indicate that the tag is not encoded */
65
66/* The current value is flags, is used to guide asn1 encoding or decoding */
67#define BSL_ASN1_FLAG_OPTIONAL 1
68/* The current value is default, is used to guide asn1 encoding or decoding */
69#define BSL_ASN1_FLAG_DEFAULT 2
70/* Only parsing or encoding headers, and child nodes are not traversed */
71#define BSL_ASN1_FLAG_HEADERONLY 4
72/* The implied values are of the same type */
73#define BSL_ASN1_FLAG_SAME 8
74
75#define BSL_ASN1_List BslList
76
77typedef struct _BSL_ASN1_TemplateItem {
78 /* exptect tag */
79 uint8_t tag;
80 /* corresponding to the tag flag */
81 uint8_t flags : 5;
82 uint8_t depth : 3;
83} BSL_ASN1_TemplateItem;
84
85typedef struct _BSL_ASN1_Template {
86 BSL_ASN1_TemplateItem *templItems;
87 uint32_t templNum;
88} BSL_ASN1_Template;
89
90typedef struct _BSL_ASN1_Buffer {
91 uint8_t tag;
92 uint32_t len;
93 uint8_t *buff;
94} BSL_ASN1_Buffer;
95
96typedef struct _BSL_ASN1_BitString {
97 uint8_t *buff;
98 uint32_t len;
99 uint8_t unusedBits;
100} BSL_ASN1_BitString;
101
102
112typedef int32_t(*BSL_ASN1_DecTemplCallBack)(int32_t type, uint32_t idx, void *data, void *expVal);
113
123typedef int32_t(*BSL_ASN1_ParseListAsnItem)(uint32_t layer, BSL_ASN1_Buffer *asn, void *cbParam, BSL_ASN1_List *list);
124
126 uint32_t layer;
127 uint8_t *expTag;
128} BSL_ASN1_DecodeListParam;
129
144int32_t BSL_ASN1_DecodeTagLen(uint8_t tag, uint8_t **encode, uint32_t *encLen, uint32_t *valLen);
145
158int32_t BSL_ASN1_DecodeListItem(BSL_ASN1_DecodeListParam *param, BSL_ASN1_Buffer *asn,
159 BSL_ASN1_ParseListAsnItem parseListItemCb, void *cbParam, BSL_ASN1_List *list);
160
174int32_t BSL_ASN1_DecodeTemplate(BSL_ASN1_Template *templ, BSL_ASN1_DecTemplCallBack decTemlCb,
175 uint8_t **encode, uint32_t *encLen, BSL_ASN1_Buffer *asnArr, uint32_t arrNum);
176
196int32_t BSL_ASN1_EncodeTemplate(BSL_ASN1_Template *templ, BSL_ASN1_Buffer *asnArr, uint32_t arrNum,
197 uint8_t **encode, uint32_t *encLen);
198
217int32_t BSL_ASN1_EncodeListItem(uint8_t tag, uint32_t listSize, BSL_ASN1_Template *templ, BSL_ASN1_Buffer *asnArr,
218 uint32_t arrNum, BSL_ASN1_Buffer *out);
219
220#ifdef __cplusplus
221}
222#endif
223
224#endif // BSL_ASN1_H
定义 bsl_asn1.h:96
定义 bsl_asn1.h:90
定义 bsl_asn1.h:125
定义 bsl_asn1.h:77
定义 bsl_asn1.h:85