23 #include <winpr/winpr.h>
24 #include <winpr/wtypes.h>
25 #include <winpr/stream.h>
27 #define ER_TAG_MASK 0x1F
31 ER_TAG_BOOLEAN = 0x01,
32 ER_TAG_INTEGER = 0x02,
33 ER_TAG_BIT_STRING = 0x03,
34 ER_TAG_OCTET_STRING = 0x04,
36 ER_TAG_OBJECT_IDENTIFIER = 0x06,
37 ER_TAG_ENUMERATED = 0x0A,
38 ER_TAG_UTF8STRING = 0x0C,
39 ER_TAG_PRINTABLE_STRING = 0x13,
40 ER_TAG_IA5STRING = 0x16,
41 ER_TAG_UTCTIME = 0x17,
42 ER_TAG_GENERAL_STRING = 0x1B,
43 ER_TAG_GENERALIZED_TIME = 0x18,
46 ER_TAG_SEQUENCE = 0x30,
47 ER_TAG_SEQUENCE_OF = 0x30,
51 ER_TAG_CONTEXTUAL = 0xA0
59 } WinPrAsn1EncodingRule;
61 typedef struct WinPrAsn1Encoder WinPrAsn1Encoder;
65 WinPrAsn1EncodingRule encoding;
71 typedef BYTE WinPrAsn1_tag;
72 typedef BYTE WinPrAsn1_tagId;
73 typedef BOOL WinPrAsn1_BOOL;
74 typedef INT32 WinPrAsn1_INTEGER;
75 typedef INT32 WinPrAsn1_ENUMERATED;
76 typedef char* WinPrAsn1_STRING;
77 typedef char* WinPrAsn1_IA5STRING;
108 WINPR_API
void WinPrAsn1Decoder_Init(
WinPrAsn1Decoder* dec, WinPrAsn1EncodingRule encoding,
110 WINPR_API
void WinPrAsn1Decoder_InitMem(
WinPrAsn1Decoder* dec, WinPrAsn1EncodingRule encoding,
111 const BYTE* source,
size_t len);
113 WINPR_API BOOL WinPrAsn1DecPeekTag(
WinPrAsn1Decoder* dec, WinPrAsn1_tag* tag);
114 WINPR_API
size_t WinPrAsn1DecReadTagAndLen(
WinPrAsn1Decoder* dec, WinPrAsn1_tag* tag,
116 WINPR_API
size_t WinPrAsn1DecPeekTagAndLen(
WinPrAsn1Decoder* dec, WinPrAsn1_tag* tag,
118 WINPR_API
size_t WinPrAsn1DecReadTagLenValue(
WinPrAsn1Decoder* dec, WinPrAsn1_tag* tag,
120 WINPR_API
size_t WinPrAsn1DecReadBoolean(
WinPrAsn1Decoder* dec, WinPrAsn1_BOOL* target);
121 WINPR_API
size_t WinPrAsn1DecReadInteger(
WinPrAsn1Decoder* dec, WinPrAsn1_INTEGER* target);
123 WinPrAsn1_ENUMERATED* target);
128 WINPR_API
size_t WinPrAsn1DecReadIA5String(
WinPrAsn1Decoder* dec, WinPrAsn1_IA5STRING* target);
129 WINPR_API
size_t WinPrAsn1DecReadGeneralString(
WinPrAsn1Decoder* dec, WinPrAsn1_STRING* target);
133 WINPR_API
size_t WinPrAsn1DecReadApp(
WinPrAsn1Decoder* dec, WinPrAsn1_tagId* tagId,
138 WINPR_API
size_t WinPrAsn1DecReadContextualTag(
WinPrAsn1Decoder* dec, WinPrAsn1_tagId* tagId,
140 WINPR_API
size_t WinPrAsn1DecPeekContextualTag(
WinPrAsn1Decoder* dec, WinPrAsn1_tagId* tagId,
143 WINPR_API
size_t WinPrAsn1DecReadContextualBool(
WinPrAsn1Decoder* dec, WinPrAsn1_tagId tagId,
144 BOOL* error, WinPrAsn1_BOOL* target);
145 WINPR_API
size_t WinPrAsn1DecReadContextualInteger(
WinPrAsn1Decoder* dec, WinPrAsn1_tagId tagId,
146 BOOL* error, WinPrAsn1_INTEGER* target);
147 WINPR_API
size_t WinPrAsn1DecReadContextualOID(
WinPrAsn1Decoder* dec, WinPrAsn1_tagId tagId,
150 WINPR_API
size_t WinPrAsn1DecReadContextualOctetString(
WinPrAsn1Decoder* dec,
151 WinPrAsn1_tagId tagId, BOOL* error,
155 WinPrAsn1_tagId tagId, BOOL* error,
161 WINPR_API
void WinPrAsn1Encoder_Free(WinPrAsn1Encoder** penc);
162 WINPR_API WinPrAsn1Encoder* WinPrAsn1Encoder_New(WinPrAsn1EncodingRule encoding);
164 WINPR_API
void WinPrAsn1Encoder_Reset(WinPrAsn1Encoder* enc);
166 WINPR_API BOOL WinPrAsn1EncAppContainer(WinPrAsn1Encoder* enc, WinPrAsn1_tagId tagId);
167 WINPR_API BOOL WinPrAsn1EncSeqContainer(WinPrAsn1Encoder* enc);
168 WINPR_API BOOL WinPrAsn1EncContextualSeqContainer(WinPrAsn1Encoder* enc, WinPrAsn1_tagId tagId);
169 WINPR_API BOOL WinPrAsn1EncSetContainer(WinPrAsn1Encoder* enc);
170 WINPR_API BOOL WinPrAsn1EncContextualSetContainer(WinPrAsn1Encoder* enc, WinPrAsn1_tagId tagId);
171 WINPR_API BOOL WinPrAsn1EncContextualContainer(WinPrAsn1Encoder* enc, WinPrAsn1_tagId tagId);
172 WINPR_API BOOL WinPrAsn1EncOctetStringContainer(WinPrAsn1Encoder* enc);
173 WINPR_API BOOL WinPrAsn1EncContextualOctetStringContainer(WinPrAsn1Encoder* enc,
174 WinPrAsn1_tagId tagId);
175 WINPR_API
size_t WinPrAsn1EncEndContainer(WinPrAsn1Encoder* enc);
178 WINPR_API
size_t WinPrAsn1EncContextualRawContent(WinPrAsn1Encoder* enc, WinPrAsn1_tagId tagId,
180 WINPR_API
size_t WinPrAsn1EncInteger(WinPrAsn1Encoder* enc, WinPrAsn1_INTEGER integer);
181 WINPR_API
size_t WinPrAsn1EncContextualInteger(WinPrAsn1Encoder* enc, WinPrAsn1_tagId tagId,
182 WinPrAsn1_INTEGER integer);
183 WINPR_API
size_t WinPrAsn1EncBoolean(WinPrAsn1Encoder* enc, WinPrAsn1_BOOL b);
184 WINPR_API
size_t WinPrAsn1EncContextualBoolean(WinPrAsn1Encoder* enc, WinPrAsn1_tagId tagId,
186 WINPR_API
size_t WinPrAsn1EncEnumerated(WinPrAsn1Encoder* enc, WinPrAsn1_ENUMERATED e);
187 WINPR_API
size_t WinPrAsn1EncContextualEnumerated(WinPrAsn1Encoder* enc, WinPrAsn1_tagId tagId,
188 WinPrAsn1_ENUMERATED e);
190 WINPR_API
size_t WinPrAsn1EncOID(WinPrAsn1Encoder* enc,
const WinPrAsn1_OID* oid);
191 WINPR_API
size_t WinPrAsn1EncContextualOID(WinPrAsn1Encoder* enc, WinPrAsn1_tagId tagId,
193 WINPR_API
size_t WinPrAsn1EncOctetString(WinPrAsn1Encoder* enc,
195 WINPR_API
size_t WinPrAsn1EncContextualOctetString(WinPrAsn1Encoder* enc, WinPrAsn1_tagId tagId,
197 WINPR_API
size_t WinPrAsn1EncIA5String(WinPrAsn1Encoder* enc, WinPrAsn1_IA5STRING ia5);
198 WINPR_API
size_t WinPrAsn1EncGeneralString(WinPrAsn1Encoder* enc, WinPrAsn1_STRING str);
199 WINPR_API
size_t WinPrAsn1EncContextualIA5String(WinPrAsn1Encoder* enc, WinPrAsn1_tagId tagId,
200 WinPrAsn1_IA5STRING ia5);
201 WINPR_API
size_t WinPrAsn1EncUtcTime(WinPrAsn1Encoder* enc,
const WinPrAsn1_UTCTIME* utc);
202 WINPR_API
size_t WinPrAsn1EncContextualUtcTime(WinPrAsn1Encoder* enc, WinPrAsn1_tagId tagId,
205 WINPR_API BOOL WinPrAsn1EncStreamSize(WinPrAsn1Encoder* enc,
size_t* s);
206 WINPR_API BOOL WinPrAsn1EncToStream(WinPrAsn1Encoder* enc,
wStream* s);