2 * Copyright (C) 2015 Austin English
3 * Copyright (C) 2020 Vijay Kiran Kamuju
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 typedef char ASN1char_t
;
29 typedef signed char ASN1int8_t
;
30 typedef unsigned char ASN1uint8_t
;
31 typedef unsigned short ASN1uint16_t
;
32 typedef signed short ASN1int16_t
;
33 typedef ULONG ASN1uint32_t
;
34 typedef LONG ASN1int32_t
;
36 typedef ASN1uint16_t ASN1char16_t
;
37 typedef ASN1uint32_t ASN1char32_t
;
39 typedef ASN1char_t
*ASN1ztcharstring_t
;
40 typedef ASN1char16_t
*ASN1ztchar16string_t
;
41 typedef ASN1char32_t
*ASN1ztchar32string_t
;
42 typedef ASN1int32_t ASN1enum_t
;
43 typedef ASN1uint8_t ASN1octet_t
;
44 typedef ASN1uint8_t ASN1bool_t
;
45 typedef ASN1uint16_t ASN1choice_t
;
46 typedef ASN1uint32_t ASN1magic_t
;
47 typedef ASN1ztcharstring_t ASN1objectdescriptor_t
;
49 #define ASN1_MAKE_VERSION(major,minor) (((major) << 16) | (minor))
50 #define ASN1_THIS_VERSION ASN1_MAKE_VERSION(1,0)
52 #define ASN1DECFREE_NON_PDU_ID ((ASN1uint32_t)-1)
54 typedef void (WINAPI
*ASN1FreeFun_t
)(void *data
);
55 typedef void (WINAPI
*ASN1GenericFun_t
)(void);
57 typedef struct ASN1encoding_s
*ASN1encoding_t
;
58 typedef struct ASN1decoding_s
*ASN1decoding_t
;
59 typedef ASN1int32_t (WINAPI
*ASN1PerEncFun_t
)(ASN1encoding_t enc
,void *data
);
60 typedef ASN1int32_t (WINAPI
*ASN1PerDecFun_t
)(ASN1decoding_t enc
,void *data
);
62 typedef struct tagASN1PerFunArr_t
{
63 const ASN1PerEncFun_t
*apfnEncoder
;
64 const ASN1PerDecFun_t
*apfnDecoder
;
67 typedef ASN1int32_t (WINAPI
*ASN1BerEncFun_t
)(ASN1encoding_t enc
,ASN1uint32_t tag
,void *data
);
68 typedef ASN1int32_t (WINAPI
*ASN1BerDecFun_t
)(ASN1decoding_t enc
,ASN1uint32_t tag
,void *data
);
70 typedef struct tagASN1BerFunArr_t
{
71 const ASN1BerEncFun_t
*apfnEncoder
;
72 const ASN1BerDecFun_t
*apfnDecoder
;
77 ASN1FLAGS_NONE
= 0x00000000,
78 ASN1FLAGS_NOASSERT
= 0x00001000
83 ASN1ENCODE_APPEND
= 0x00000001,
84 ASN1ENCODE_REUSEBUFFER
= 0x00000004,
85 ASN1ENCODE_SETBUFFER
= 0x00000008,
86 ASN1ENCODE_ALLOCATEBUFFER
= 0x00000010,
87 ASN1ENCODE_NOASSERT
= ASN1FLAGS_NOASSERT
92 ASN1DECODE_APPENDED
= 0x00000001,
93 ASN1DECODE_REWINDBUFFER
= 0x00000004,
94 ASN1DECODE_SETBUFFER
= 0x00000008,
95 ASN1DECODE_AUTOFREEBUFFER
= 0x00000010,
96 ASN1DECODE_NOASSERT
= ASN1FLAGS_NOASSERT
99 typedef struct tagASN1bitstring_t
105 typedef enum tagASN1blocktype_e
107 ASN1_DER_SET_OF_BLOCK
,
110 typedef struct tagASN1charstring_t
116 typedef struct tagASN1char16string_t
120 } ASN1char16string_t
;
122 typedef struct tagASN1char32string_t
126 } ASN1char32string_t
;
128 typedef struct tagASN1encodedOID_t
135 ASN1_PER_RULE_ALIGNED
= 0x0001,ASN1_PER_RULE_UNALIGNED
= 0x0002,ASN1_PER_RULE
= ASN1_PER_RULE_ALIGNED
| ASN1_PER_RULE_UNALIGNED
,
136 ASN1_BER_RULE_BER
= 0x0100,ASN1_BER_RULE_CER
= 0x0200,ASN1_BER_RULE_DER
= 0x0400,
137 ASN1_BER_RULE
= ASN1_BER_RULE_BER
| ASN1_BER_RULE_CER
| ASN1_BER_RULE_DER
138 } ASN1encodingrule_e
;
140 typedef enum tagASN1error_e
143 ASN1_ERR_INTERNAL
= -1001,
144 ASN1_ERR_EOD
= -1002,
145 ASN1_ERR_CORRUPT
= -1003,
146 ASN1_ERR_LARGE
= -1004,
147 ASN1_ERR_CONSTRAINT
= -1005,
148 ASN1_ERR_MEMORY
= -1006,
149 ASN1_ERR_OVERFLOW
= -1007,
150 ASN1_ERR_BADPDU
= -1008,
151 ASN1_ERR_BADARGS
= -1009,
152 ASN1_ERR_BADREAL
= -1010,
153 ASN1_ERR_BADTAG
= -1011,
154 ASN1_ERR_CHOICE
= -1012,
155 ASN1_ERR_RULE
= -1013,
156 ASN1_ERR_UTF8
= -1014,
157 ASN1_ERR_PDU_TYPE
= -1051,
158 ASN1_ERR_NYI
= -1052,
159 ASN1_WRN_EXTENDED
= 1001,
160 ASN1_WRN_NOEOD
= 1002,
165 ASN1_CHOICE_BASE
= 1,
166 ASN1_CHOICE_INVALID
= -1,
167 ASN1_CHOICE_EXTENSION
= 0
170 #define ASN1_SUCCEEDED(ret) (((int)(ret)) >= 0)
171 #define ASN1_FAILED(ret) (((int)(ret)) < 0)
173 typedef struct tagASN1generalizedtime_t
181 ASN1uint16_t millisecond
;
182 ASN1bool_t universal
;
184 } ASN1generalizedtime_t
;
186 typedef struct tagASN1intx_t
192 typedef struct tagASN1module_t
194 ASN1magic_t nModuleName
;
195 ASN1encodingrule_e eRule
;
196 ASN1uint32_t dwFlags
;
198 const ASN1FreeFun_t
*apfnFreeMemory
;
199 const ASN1uint32_t
*acbStructSize
;
207 struct ASN1encoding_s
210 ASN1uint32_t version
;
218 ASN1uint32_t cbExtraHeader
;
219 ASN1encodingrule_e eRule
;
220 ASN1uint32_t dwFlags
;
223 struct ASN1decoding_s
226 ASN1uint32_t version
;
234 ASN1encodingrule_e eRule
;
235 ASN1uint32_t dwFlags
;
238 typedef struct ASN1objectidentifier_s
240 struct ASN1objectidentifier_s
*next
;
242 } *ASN1objectidentifier_t
;
244 typedef struct tagASN1objectidentifier2_t
247 ASN1uint32_t value
[16];
248 } ASN1objectidentifier2_t
;
250 typedef struct tagASN1octetstring_t
256 typedef struct tagASN1open_t
266 typedef enum tagASN1option_e
268 ASN1OPT_CHANGE_RULE
= 0x101,
269 ASN1OPT_GET_RULE
= 0x201,
270 ASN1OPT_NOT_REUSE_BUFFER
= 0x301,
271 ASN1OPT_REWIND_BUFFER
= 0x302,
272 ASN1OPT_SET_DECODED_BUFFER
= 0x501,
273 ASN1OPT_DEL_DECODED_BUFFER
= 0x502,
274 ASN1OPT_GET_DECODED_BUFFER_SIZE
= 0x601,
277 typedef struct tagASN1optionparam_t
{
278 ASN1option_e eOption
;
281 ASN1encodingrule_e eRule
;
282 ASN1uint32_t cbRequiredDecodedBufSize
;
286 ASN1uint32_t cbBufSize
;
289 } ASN1optionparam_t
, ASN1optionparam_s
;
291 typedef struct tagASN1utctime_t
299 ASN1bool_t universal
;
303 typedef struct tagASN1wstring_t
309 void WINAPI
ASN1_CloseDecoder(ASN1decoding_t
);
310 void WINAPI
ASN1_CloseEncoder(ASN1encoding_t
);
311 void WINAPI
ASN1_CloseEncoder2(ASN1encoding_t
);
312 void WINAPI
ASN1_CloseModule(ASN1module_t
);
313 ASN1error_e WINAPI
ASN1_CreateDecoder(ASN1module_t
, ASN1decoding_t
*,ASN1octet_t
*, ASN1uint32_t
, ASN1decoding_t
);
314 ASN1error_e WINAPI
ASN1_CreateDecoderEx(ASN1module_t
, ASN1decoding_t
*,ASN1octet_t
*, ASN1uint32_t
, ASN1decoding_t
, ASN1uint32_t
);
315 ASN1error_e WINAPI
ASN1_CreateEncoder(ASN1module_t
, ASN1encoding_t
*, ASN1octet_t
*, ASN1uint32_t
, ASN1encoding_t
);
316 ASN1module_t WINAPI
ASN1_CreateModule(ASN1uint32_t
,ASN1encodingrule_e
,ASN1uint32_t
,ASN1uint32_t
,const ASN1GenericFun_t
[],const ASN1GenericFun_t
[],const ASN1FreeFun_t
[],const ASN1uint32_t
[],ASN1magic_t
);
317 ASN1error_e WINAPI
ASN1_Decode(ASN1decoding_t
, void** , ASN1uint32_t
, ASN1uint32_t
, ASN1octet_t
*, ASN1uint32_t
);
318 ASN1error_e WINAPI
ASN1_Encode(ASN1encoding_t
, void*, ASN1uint32_t
, ASN1uint32_t
, ASN1octet_t
*, ASN1uint32_t
);
319 void WINAPI
ASN1_FreeDecoded(ASN1decoding_t
, void*, ASN1uint32_t
);
320 void WINAPI
ASN1_FreeEncoded(ASN1encoding_t
, void*);
321 ASN1error_e WINAPI
ASN1_GetDecoderOption(ASN1decoding_t
, ASN1optionparam_t
*);
322 ASN1error_e WINAPI
ASN1_GetEncoderOption(ASN1encoding_t
, ASN1optionparam_t
*);
323 ASN1error_e WINAPI
ASN1_SetDecoderOption(ASN1decoding_t
, ASN1optionparam_t
*);
324 ASN1error_e WINAPI
ASN1_SetEncoderOption(ASN1encoding_t
, ASN1optionparam_t
*);
325 int WINAPI
ASN1bitstring_cmp(ASN1bitstring_t
*,ASN1bitstring_t
*);
326 void WINAPI
ASN1bitstring_free(ASN1bitstring_t
*);
327 int WINAPI
ASN1char16string_cmp(ASN1char16string_t
*,ASN1char16string_t
*);
328 void WINAPI
ASN1char16string_free(ASN1char16string_t
*);
329 int WINAPI
ASN1char32string_cmp(ASN1char32string_t
*,ASN1char32string_t
*);
330 void WINAPI
ASN1char32string_free(ASN1char32string_t
*);
331 int WINAPI
ASN1charstring_cmp(ASN1charstring_t
*,ASN1charstring_t
*);
332 void WINAPI
ASN1charstring_free(ASN1charstring_t
*);
333 LPVOID WINAPI
ASN1DecAlloc(ASN1decoding_t
,ASN1uint32_t
);
334 LPVOID WINAPI
ASN1DecRealloc(ASN1decoding_t
,LPVOID
,ASN1uint32_t
);
335 ASN1error_e WINAPI
ASN1DecSetError(ASN1decoding_t
,ASN1error_e
);
336 ASN1error_e WINAPI
ASN1EncSetError(ASN1encoding_t
,ASN1error_e
);
337 void WINAPI
ASN1Free(LPVOID
);
338 int WINAPI
ASN1generalizedtime_cmp(ASN1generalizedtime_t
*,ASN1generalizedtime_t
*);
339 int WINAPI
ASN1intx_cmp(ASN1intx_t
*,ASN1intx_t
*);
340 void WINAPI
ASN1intx_free(ASN1intx_t
*);
341 void WINAPI
ASN1intx_setuint32(ASN1intx_t
*,ASN1uint32_t
);
342 ASN1uint32_t WINAPI
ASN1intx_uoctets(ASN1intx_t
*);
343 ASN1int32_t WINAPI
ASN1intx2int32(ASN1intx_t
*);
344 ASN1uint32_t WINAPI
ASN1intx2uint32(ASN1intx_t
*);
345 int WINAPI
ASN1intxisuint32(ASN1intx_t
*);
346 int WINAPI
ASN1objectidentifier_cmp(ASN1objectidentifier_t
*,ASN1objectidentifier_t
*);
347 void WINAPI
ASN1objectidentifier_free(ASN1objectidentifier_t
*);
348 int WINAPI
ASN1objectidentifier2_cmp(ASN1objectidentifier2_t
*,ASN1objectidentifier2_t
*);
349 int WINAPI
ASN1octetstring_cmp(ASN1octetstring_t
*,ASN1octetstring_t
*);
350 void WINAPI
ASN1octetstring_free(ASN1octetstring_t
*);
351 int WINAPI
ASN1open_cmp(ASN1open_t
*,ASN1open_t
*);
352 void WINAPI
ASN1open_free(ASN1open_t
*);
353 ASN1uint32_t WINAPI
ASN1uint32_uoctets(ASN1uint32_t
);
354 void WINAPI
ASN1utf8string_free(ASN1wstring_t
*);
355 int WINAPI
ASN1utctime_cmp(ASN1utctime_t
*,ASN1utctime_t
*);
356 int WINAPI
ASN1ztchar16string_cmp(ASN1ztchar16string_t
*,ASN1ztchar16string_t
*);
357 void WINAPI
ASN1ztchar16string_free(ASN1ztchar16string_t
*);
358 void WINAPI
ASN1ztchar32string_free(ASN1ztchar32string_t
*);
359 int WINAPI
ASN1ztcharstring_cmp(ASN1ztcharstring_t
*,ASN1ztcharstring_t
*);
360 void WINAPI
ASN1ztcharstring_free(ASN1charstring_t
*);
368 #endif /* __MS_ASN1_H__ */