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_PUBLIC DECLSPEC_IMPORT
50 #define ASN1API __stdcall
51 #define ASN1CALL __stdcall
53 #define ASN1_MAKE_VERSION(major,minor) (((major) << 16) | (minor))
54 #define ASN1_THIS_VERSION ASN1_MAKE_VERSION(1,0)
56 #define ASN1DECFREE_NON_PDU_ID ((ASN1uint32_t)-1)
58 typedef void (WINAPI
*ASN1FreeFun_t
)(void *data
);
59 typedef void (WINAPI
*ASN1GenericFun_t
)(void);
61 typedef struct ASN1encoding_s
*ASN1encoding_t
;
62 typedef struct ASN1decoding_s
*ASN1decoding_t
;
63 typedef ASN1int32_t (WINAPI
*ASN1PerEncFun_t
)(ASN1encoding_t enc
,void *data
);
64 typedef ASN1int32_t (WINAPI
*ASN1PerDecFun_t
)(ASN1decoding_t enc
,void *data
);
66 typedef struct tagASN1PerFunArr_t
{
67 const ASN1PerEncFun_t
*apfnEncoder
;
68 const ASN1PerDecFun_t
*apfnDecoder
;
71 typedef ASN1int32_t (WINAPI
*ASN1BerEncFun_t
)(ASN1encoding_t enc
,ASN1uint32_t tag
,void *data
);
72 typedef ASN1int32_t (WINAPI
*ASN1BerDecFun_t
)(ASN1decoding_t enc
,ASN1uint32_t tag
,void *data
);
74 typedef struct tagASN1BerFunArr_t
{
75 const ASN1BerEncFun_t
*apfnEncoder
;
76 const ASN1BerDecFun_t
*apfnDecoder
;
81 ASN1FLAGS_NONE
= 0x00000000,
82 ASN1FLAGS_NOASSERT
= 0x00001000
87 ASN1ENCODE_APPEND
= 0x00000001,
88 ASN1ENCODE_REUSEBUFFER
= 0x00000004,
89 ASN1ENCODE_SETBUFFER
= 0x00000008,
90 ASN1ENCODE_ALLOCATEBUFFER
= 0x00000010,
91 ASN1ENCODE_NOASSERT
= ASN1FLAGS_NOASSERT
96 ASN1DECODE_APPENDED
= 0x00000001,
97 ASN1DECODE_REWINDBUFFER
= 0x00000004,
98 ASN1DECODE_SETBUFFER
= 0x00000008,
99 ASN1DECODE_AUTOFREEBUFFER
= 0x00000010,
100 ASN1DECODE_NOASSERT
= ASN1FLAGS_NOASSERT
103 typedef struct tagASN1bitstring_t
109 typedef enum tagASN1blocktype_e
111 ASN1_DER_SET_OF_BLOCK
,
114 typedef struct tagASN1charstring_t
120 typedef struct tagASN1char16string_t
124 } ASN1char16string_t
;
126 typedef struct tagASN1char32string_t
130 } ASN1char32string_t
;
132 typedef struct tagASN1encodedOID_t
139 ASN1_PER_RULE_ALIGNED
= 0x0001,ASN1_PER_RULE_UNALIGNED
= 0x0002,ASN1_PER_RULE
= ASN1_PER_RULE_ALIGNED
| ASN1_PER_RULE_UNALIGNED
,
140 ASN1_BER_RULE_BER
= 0x0100,ASN1_BER_RULE_CER
= 0x0200,ASN1_BER_RULE_DER
= 0x0400,
141 ASN1_BER_RULE
= ASN1_BER_RULE_BER
| ASN1_BER_RULE_CER
| ASN1_BER_RULE_DER
142 } ASN1encodingrule_e
;
144 typedef enum tagASN1error_e
147 ASN1_ERR_INTERNAL
= -1001,
148 ASN1_ERR_EOD
= -1002,
149 ASN1_ERR_CORRUPT
= -1003,
150 ASN1_ERR_LARGE
= -1004,
151 ASN1_ERR_CONSTRAINT
= -1005,
152 ASN1_ERR_MEMORY
= -1006,
153 ASN1_ERR_OVERFLOW
= -1007,
154 ASN1_ERR_BADPDU
= -1008,
155 ASN1_ERR_BADARGS
= -1009,
156 ASN1_ERR_BADREAL
= -1010,
157 ASN1_ERR_BADTAG
= -1011,
158 ASN1_ERR_CHOICE
= -1012,
159 ASN1_ERR_RULE
= -1013,
160 ASN1_ERR_UTF8
= -1014,
161 ASN1_ERR_PDU_TYPE
= -1051,
162 ASN1_ERR_NYI
= -1052,
163 ASN1_WRN_EXTENDED
= 1001,
164 ASN1_WRN_NOEOD
= 1002,
169 ASN1_CHOICE_BASE
= 1,
170 ASN1_CHOICE_INVALID
= -1,
171 ASN1_CHOICE_EXTENSION
= 0
174 #define ASN1_SUCCEEDED(ret) (((int)(ret)) >= 0)
175 #define ASN1_FAILED(ret) (((int)(ret)) < 0)
177 typedef struct tagASN1generalizedtime_t
185 ASN1uint16_t millisecond
;
186 ASN1bool_t universal
;
188 } ASN1generalizedtime_t
;
190 typedef struct tagASN1intx_t
196 typedef struct tagASN1module_t
198 ASN1magic_t nModuleName
;
199 ASN1encodingrule_e eRule
;
200 ASN1uint32_t dwFlags
;
202 const ASN1FreeFun_t
*apfnFreeMemory
;
203 const ASN1uint32_t
*acbStructSize
;
211 struct ASN1encoding_s
214 ASN1uint32_t version
;
222 ASN1uint32_t cbExtraHeader
;
223 ASN1encodingrule_e eRule
;
224 ASN1uint32_t dwFlags
;
227 struct ASN1decoding_s
230 ASN1uint32_t version
;
238 ASN1encodingrule_e eRule
;
239 ASN1uint32_t dwFlags
;
242 typedef struct ASN1objectidentifier_s
244 struct ASN1objectidentifier_s
*next
;
246 } *ASN1objectidentifier_t
;
248 typedef struct tagASN1objectidentifier2_t
251 ASN1uint32_t value
[16];
252 } ASN1objectidentifier2_t
;
254 typedef struct tagASN1octetstring_t
260 typedef struct tagASN1open_t
270 typedef enum tagASN1option_e
272 ASN1OPT_CHANGE_RULE
= 0x101,
273 ASN1OPT_GET_RULE
= 0x201,
274 ASN1OPT_NOT_REUSE_BUFFER
= 0x301,
275 ASN1OPT_REWIND_BUFFER
= 0x302,
276 ASN1OPT_SET_DECODED_BUFFER
= 0x501,
277 ASN1OPT_DEL_DECODED_BUFFER
= 0x502,
278 ASN1OPT_GET_DECODED_BUFFER_SIZE
= 0x601,
281 typedef struct tagASN1optionparam_t
{
282 ASN1option_e eOption
;
285 ASN1encodingrule_e eRule
;
286 ASN1uint32_t cbRequiredDecodedBufSize
;
290 ASN1uint32_t cbBufSize
;
293 } ASN1optionparam_t
, ASN1optionparam_s
;
295 typedef struct tagASN1utctime_t
303 ASN1bool_t universal
;
307 typedef struct tagASN1wstring_t
313 void WINAPI
ASN1_CloseDecoder(ASN1decoding_t
);
314 void WINAPI
ASN1_CloseEncoder(ASN1encoding_t
);
315 void WINAPI
ASN1_CloseEncoder2(ASN1encoding_t
);
316 void WINAPI
ASN1_CloseModule(ASN1module_t
);
317 ASN1error_e WINAPI
ASN1_CreateDecoder(ASN1module_t
, ASN1decoding_t
*,ASN1octet_t
*, ASN1uint32_t
, ASN1decoding_t
);
318 ASN1error_e WINAPI
ASN1_CreateDecoderEx(ASN1module_t
, ASN1decoding_t
*,ASN1octet_t
*, ASN1uint32_t
, ASN1decoding_t
, ASN1uint32_t
);
319 ASN1error_e WINAPI
ASN1_CreateEncoder(ASN1module_t
, ASN1encoding_t
*, ASN1octet_t
*, ASN1uint32_t
, ASN1encoding_t
);
320 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
);
321 ASN1error_e WINAPI
ASN1_Decode(ASN1decoding_t
, void** , ASN1uint32_t
, ASN1uint32_t
, ASN1octet_t
*, ASN1uint32_t
);
322 ASN1error_e WINAPI
ASN1_Encode(ASN1encoding_t
, void*, ASN1uint32_t
, ASN1uint32_t
, ASN1octet_t
*, ASN1uint32_t
);
323 void WINAPI
ASN1_FreeDecoded(ASN1decoding_t
, void*, ASN1uint32_t
);
324 void WINAPI
ASN1_FreeEncoded(ASN1encoding_t
, void*);
325 ASN1error_e WINAPI
ASN1_GetDecoderOption(ASN1decoding_t
, ASN1optionparam_t
*);
326 ASN1error_e WINAPI
ASN1_GetEncoderOption(ASN1encoding_t
, ASN1optionparam_t
*);
327 ASN1error_e WINAPI
ASN1_SetDecoderOption(ASN1decoding_t
, ASN1optionparam_t
*);
328 ASN1error_e WINAPI
ASN1_SetEncoderOption(ASN1encoding_t
, ASN1optionparam_t
*);
329 int WINAPI
ASN1bitstring_cmp(ASN1bitstring_t
*,ASN1bitstring_t
*);
330 void WINAPI
ASN1bitstring_free(ASN1bitstring_t
*);
331 int WINAPI
ASN1char16string_cmp(ASN1char16string_t
*,ASN1char16string_t
*);
332 void WINAPI
ASN1char16string_free(ASN1char16string_t
*);
333 int WINAPI
ASN1char32string_cmp(ASN1char32string_t
*,ASN1char32string_t
*);
334 void WINAPI
ASN1char32string_free(ASN1char32string_t
*);
335 int WINAPI
ASN1charstring_cmp(ASN1charstring_t
*,ASN1charstring_t
*);
336 void WINAPI
ASN1charstring_free(ASN1charstring_t
*);
337 LPVOID WINAPI
ASN1DecAlloc(ASN1decoding_t
,ASN1uint32_t
);
338 LPVOID WINAPI
ASN1DecRealloc(ASN1decoding_t
,LPVOID
,ASN1uint32_t
);
339 ASN1error_e WINAPI
ASN1DecSetError(ASN1decoding_t
,ASN1error_e
);
340 ASN1error_e WINAPI
ASN1EncSetError(ASN1encoding_t
,ASN1error_e
);
341 void WINAPI
ASN1Free(LPVOID
);
342 int WINAPI
ASN1generalizedtime_cmp(ASN1generalizedtime_t
*,ASN1generalizedtime_t
*);
343 int WINAPI
ASN1intx_cmp(ASN1intx_t
*,ASN1intx_t
*);
344 void WINAPI
ASN1intx_free(ASN1intx_t
*);
345 void WINAPI
ASN1intx_setuint32(ASN1intx_t
*,ASN1uint32_t
);
346 ASN1uint32_t WINAPI
ASN1intx_uoctets(ASN1intx_t
*);
347 ASN1int32_t WINAPI
ASN1intx2int32(ASN1intx_t
*);
348 ASN1uint32_t WINAPI
ASN1intx2uint32(ASN1intx_t
*);
349 int WINAPI
ASN1intxisuint32(ASN1intx_t
*);
350 int WINAPI
ASN1objectidentifier_cmp(ASN1objectidentifier_t
*,ASN1objectidentifier_t
*);
351 void WINAPI
ASN1objectidentifier_free(ASN1objectidentifier_t
*);
352 int WINAPI
ASN1objectidentifier2_cmp(ASN1objectidentifier2_t
*,ASN1objectidentifier2_t
*);
353 int WINAPI
ASN1octetstring_cmp(ASN1octetstring_t
*,ASN1octetstring_t
*);
354 void WINAPI
ASN1octetstring_free(ASN1octetstring_t
*);
355 int WINAPI
ASN1open_cmp(ASN1open_t
*,ASN1open_t
*);
356 void WINAPI
ASN1open_free(ASN1open_t
*);
357 ASN1uint32_t WINAPI
ASN1uint32_uoctets(ASN1uint32_t
);
358 void WINAPI
ASN1utf8string_free(ASN1wstring_t
*);
359 int WINAPI
ASN1utctime_cmp(ASN1utctime_t
*,ASN1utctime_t
*);
360 int WINAPI
ASN1ztchar16string_cmp(ASN1ztchar16string_t
*,ASN1ztchar16string_t
*);
361 void WINAPI
ASN1ztchar16string_free(ASN1ztchar16string_t
*);
362 void WINAPI
ASN1ztchar32string_free(ASN1ztchar32string_t
*);
363 int WINAPI
ASN1ztcharstring_cmp(ASN1ztcharstring_t
*,ASN1ztcharstring_t
*);
364 void WINAPI
ASN1ztcharstring_free(ASN1charstring_t
*);
372 #endif /* __MS_ASN1_H__ */