2 * Copyright 2020 Vijay Kiran Kamuju
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
27 static void test_CreateModule(void)
29 const ASN1GenericFun_t encfn
[] = { NULL
};
30 const ASN1GenericFun_t decfn
[] = { NULL
};
31 const ASN1FreeFun_t freefn
[] = { NULL
};
32 const ASN1uint32_t size
[] = { 0 };
33 ASN1magic_t name
= 0x61736e31;
36 mod
= ASN1_CreateModule(0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
, 0);
37 ok(!mod
, "Expected Failure.\n");
39 mod
= ASN1_CreateModule(0, 0, 0, 0, encfn
, NULL
, NULL
, NULL
, 0);
40 ok(!mod
, "Expected Failure.\n");
42 mod
= ASN1_CreateModule(0, 0, 0, 0, encfn
, decfn
, NULL
, NULL
, 0);
43 ok(!mod
, "Expected Failure.\n");
45 mod
= ASN1_CreateModule(0, 0, 0, 0, encfn
, decfn
, freefn
, NULL
, 0);
46 ok(!mod
, "Expected Failure.\n");
48 mod
= ASN1_CreateModule(0, 0, 0, 0, encfn
, decfn
, freefn
, size
, 0);
49 ok(!!mod
, "Failed to create module.\n");
50 ok(mod
->nModuleName
==0, "Got Module name = %d.\n",mod
->nModuleName
);
51 ok(mod
->eRule
==0, "Got eRule = %08x.\n",mod
->eRule
);
52 ok(mod
->dwFlags
==0, "Got Flags = %08x.\n",mod
->dwFlags
);
53 ok(mod
->cPDUs
==0, "Got PDUs = %08x.\n",mod
->cPDUs
);
54 ok(mod
->apfnFreeMemory
==freefn
, "Free function = %p.\n",mod
->apfnFreeMemory
);
55 ok(mod
->acbStructSize
==size
, "Struct size = %p.\n",mod
->acbStructSize
);
56 ok(!mod
->PER
.apfnEncoder
, "Encoder function should not be set.\n");
57 ok(!mod
->PER
.apfnDecoder
, "Decoder function should not be set.\n");
58 ASN1_CloseModule(mod
);
60 mod
= ASN1_CreateModule(ASN1_THIS_VERSION
, ASN1_BER_RULE_DER
, ASN1FLAGS_NOASSERT
, 1, encfn
, decfn
, freefn
, size
, name
);
61 ok(!!mod
, "Failed to create module.\n");
62 ok(mod
->nModuleName
==name
, "Got Module name = %d.\n",mod
->nModuleName
);
63 ok(mod
->eRule
==ASN1_BER_RULE_DER
, "Got eRule = %08x.\n",mod
->eRule
);
64 ok(mod
->cPDUs
==1, "Got PDUs = %08x.\n",mod
->cPDUs
);
65 ok(mod
->dwFlags
==ASN1FLAGS_NOASSERT
, "Got Flags = %08x.\n",mod
->dwFlags
);
66 ok(mod
->apfnFreeMemory
==freefn
, "Free function = %p.\n",mod
->apfnFreeMemory
);
67 ok(mod
->acbStructSize
==size
, "Struct size = %p.\n",mod
->acbStructSize
);
68 ok(mod
->BER
.apfnEncoder
==(ASN1BerEncFun_t
*)encfn
, "Encoder function = %p.\n",mod
->BER
.apfnEncoder
);
69 ok(mod
->BER
.apfnDecoder
==(ASN1BerDecFun_t
*)decfn
, "Decoder function = %p.\n",mod
->BER
.apfnDecoder
);
70 ASN1_CloseModule(mod
);
72 mod
= ASN1_CreateModule(ASN1_THIS_VERSION
, ASN1_PER_RULE_ALIGNED
, ASN1FLAGS_NOASSERT
, 1, encfn
, decfn
, freefn
, size
, name
);
73 ok(!!mod
, "Failed to create module.\n");
74 ok(mod
->nModuleName
==name
, "Got Module name = %d.\n",mod
->nModuleName
);
75 ok(mod
->eRule
==ASN1_PER_RULE_ALIGNED
, "Got eRule = %08x.\n",mod
->eRule
);
76 ok(mod
->cPDUs
==1, "Got PDUs = %08x.\n",mod
->cPDUs
);
77 ok(mod
->dwFlags
==ASN1FLAGS_NOASSERT
, "Got Flags = %08x.\n",mod
->dwFlags
);
78 ok(mod
->apfnFreeMemory
==freefn
, "Free function = %p.\n",mod
->apfnFreeMemory
);
79 ok(mod
->acbStructSize
==size
, "Struct size = %p.\n",mod
->acbStructSize
);
80 ok(mod
->PER
.apfnEncoder
==(ASN1PerEncFun_t
*)encfn
/* WINXP & WIN2008 */ ||
81 broken(!mod
->PER
.apfnEncoder
), "Encoder function = %p.\n",mod
->PER
.apfnEncoder
);
82 ok(mod
->PER
.apfnDecoder
==(ASN1PerDecFun_t
*)decfn
/* WINXP & WIN2008 */ ||
83 broken(!mod
->PER
.apfnDecoder
), "Decoder function = %p.\n",mod
->PER
.apfnDecoder
);
84 ASN1_CloseModule(mod
);
87 static void test_CreateEncoder(void)
89 const ASN1GenericFun_t encfn
[] = { NULL
};
90 const ASN1GenericFun_t decfn
[] = { NULL
};
91 const ASN1FreeFun_t freefn
[] = { NULL
};
92 const ASN1uint32_t size
[] = { 0 };
93 ASN1magic_t name
= 0x61736e31;
94 ASN1encoding_t encoder
= NULL
;
95 ASN1octet_t buf
[] = {0x54,0x65,0x73,0x74,0};
99 ret
= ASN1_CreateEncoder(NULL
, NULL
, NULL
, 0, NULL
);
100 ok(ret
== ASN1_ERR_BADARGS
,"Got error code %d.\n",ret
);
102 mod
= ASN1_CreateModule(ASN1_THIS_VERSION
, ASN1_BER_RULE_DER
, ASN1FLAGS_NOASSERT
, 1, encfn
, decfn
, freefn
, size
, name
);
103 ret
= ASN1_CreateEncoder(mod
, NULL
, NULL
, 0, NULL
);
104 ok(ret
== ASN1_ERR_BADARGS
,"Got error code %d.\n",ret
);
106 ret
= ASN1_CreateEncoder(mod
, &encoder
, NULL
, 0, NULL
);
107 ok(ASN1_SUCCEEDED(ret
),"Got error code %d.\n",ret
);
108 ok(!!encoder
,"Encoder creation failed.\n");
109 ok(encoder
->magic
==0x44434e45,"Got invalid magic = %08x.\n",encoder
->magic
);
110 ok(!encoder
->version
,"Got incorrect version = %08x.\n",encoder
->version
);
111 ok(encoder
->module
==mod
,"Got incorrect module = %p.\n",encoder
->module
);
112 ok(!encoder
->buf
,"Got incorrect buf = %p.\n",encoder
->buf
);
113 ok(!encoder
->size
,"Got incorrect size = %u.\n",encoder
->size
);
114 ok(!encoder
->len
,"Got incorrect length = %u.\n",encoder
->len
);
115 ok(encoder
->err
==ASN1_SUCCESS
,"Got incorrect err = %d.\n",encoder
->err
);
116 ok(!encoder
->bit
,"Got incorrect bit = %u.\n",encoder
->bit
);
117 ok(!encoder
->pos
,"Got incorrect pos = %p.\n",encoder
->pos
);
118 ok(!encoder
->cbExtraHeader
,"Got incorrect cbExtraHeader = %u.\n",encoder
->cbExtraHeader
);
119 ok(encoder
->eRule
== ASN1_BER_RULE_DER
,"Got incorrect eRule = %08x.\n",encoder
->eRule
);
120 ok(encoder
->dwFlags
== ASN1ENCODE_NOASSERT
,"Got incorrect dwFlags = %08x.\n",encoder
->dwFlags
);
121 ASN1_CloseEncoder(encoder
);
123 ret
= ASN1_CreateEncoder(mod
, &encoder
, buf
, 0, NULL
);
124 ok(ASN1_SUCCEEDED(ret
),"Got error code %d.\n",ret
);
125 ok(!!encoder
,"Encoder creation failed.\n");
126 ok(encoder
->magic
==0x44434e45,"Got invalid magic = %08x.\n",encoder
->magic
);
127 ok(!encoder
->version
,"Got incorrect version = %08x.\n",encoder
->version
);
128 ok(encoder
->module
==mod
,"Got incorrect module = %p.\n",encoder
->module
);
129 ok(!encoder
->buf
,"Got incorrect buf = %p.\n",encoder
->buf
);
130 ok(!encoder
->size
,"Got incorrect size = %u.\n",encoder
->size
);
131 ok(!encoder
->len
,"Got incorrect length = %u.\n",encoder
->len
);
132 ok(encoder
->err
==ASN1_SUCCESS
,"Got incorrect err = %d.\n",encoder
->err
);
133 ok(!encoder
->bit
,"Got incorrect bit = %u.\n",encoder
->bit
);
134 ok(!encoder
->pos
,"Got incorrect pos = %p.\n",encoder
->pos
);
135 ok(!encoder
->cbExtraHeader
,"Got incorrect cbExtraHeader = %u.\n",encoder
->cbExtraHeader
);
136 ok(encoder
->eRule
== ASN1_BER_RULE_DER
,"Got incorrect eRule = %08x.\n",encoder
->eRule
);
137 ok(encoder
->dwFlags
== ASN1ENCODE_NOASSERT
,"Got incorrect dwFlags = %08x.\n",encoder
->dwFlags
);
138 ASN1_CloseEncoder(encoder
);
140 ret
= ASN1_CreateEncoder(mod
, &encoder
, buf
, 2, NULL
);
141 ok(ASN1_SUCCEEDED(ret
),"Got error code %d.\n",ret
);
142 ok(!!encoder
,"Encoder creation failed.\n");
143 ok(encoder
->magic
==0x44434e45,"Got invalid magic = %08x.\n",encoder
->magic
);
144 ok(!encoder
->version
,"Got incorrect version = %08x.\n",encoder
->version
);
145 ok(encoder
->module
==mod
,"Got incorrect module = %p.\n",encoder
->module
);
146 ok(encoder
->buf
==buf
,"Got incorrect buf = %p.\n",encoder
->buf
);
147 ok(encoder
->size
==2,"Got incorrect size = %u.\n",encoder
->size
);
148 ok(!encoder
->len
,"Got incorrect length = %u.\n",encoder
->len
);
149 ok(encoder
->err
==ASN1_SUCCESS
,"Got incorrect err = %d.\n",encoder
->err
);
150 ok(!encoder
->bit
,"Got incorrect bit = %u.\n",encoder
->bit
);
151 ok(encoder
->pos
==buf
,"Got incorrect pos = %p.\n",encoder
->pos
);
152 ok(!encoder
->cbExtraHeader
,"Got incorrect cbExtraHeader = %u.\n",encoder
->cbExtraHeader
);
153 ok(encoder
->eRule
== ASN1_BER_RULE_DER
,"Got incorrect eRule = %08x.\n",encoder
->eRule
);
154 ok(encoder
->dwFlags
== (ASN1ENCODE_NOASSERT
|ASN1ENCODE_SETBUFFER
),"Got incorrect dwFlags = %08x.\n",encoder
->dwFlags
);
155 ASN1_CloseEncoder(encoder
);
157 ret
= ASN1_CreateEncoder(mod
, &encoder
, buf
, 4, NULL
);
158 ok(ASN1_SUCCEEDED(ret
),"Got error code %d.\n",ret
);
159 ok(!!encoder
,"Encoder creation failed.\n");
160 ok(encoder
->magic
==0x44434e45,"Got invalid magic = %08x.\n",encoder
->magic
);
161 ok(!encoder
->version
,"Got incorrect version = %08x.\n",encoder
->version
);
162 ok(encoder
->module
==mod
,"Got incorrect module = %p.\n",encoder
->module
);
163 ok(encoder
->buf
==buf
,"Got incorrect buf = %p.\n",encoder
->buf
);
164 ok(encoder
->size
==4,"Got incorrect size = %u.\n",encoder
->size
);
165 ok(!encoder
->len
,"Got incorrect length = %u.\n",encoder
->len
);
166 ok(encoder
->err
==ASN1_SUCCESS
,"Got incorrect err = %d.\n",encoder
->err
);
167 ok(!encoder
->bit
,"Got incorrect bit = %u.\n",encoder
->bit
);
168 ok(encoder
->pos
==buf
,"Got incorrect pos = %p.\n",encoder
->pos
);
169 ok(!encoder
->cbExtraHeader
,"Got incorrect cbExtraHeader = %u.\n",encoder
->cbExtraHeader
);
170 ok(encoder
->eRule
== ASN1_BER_RULE_DER
,"Got incorrect rule = %08x.\n",encoder
->eRule
);
171 ok(encoder
->dwFlags
== (ASN1ENCODE_NOASSERT
|ASN1ENCODE_SETBUFFER
),"Got incorrect dwFlags = %08x.\n",encoder
->dwFlags
);
172 ASN1_CloseEncoder(encoder
);
173 ASN1_CloseModule(mod
);
175 mod
= ASN1_CreateModule(ASN1_THIS_VERSION
, ASN1_BER_RULE_DER
, ASN1FLAGS_NONE
, 1, encfn
, decfn
, freefn
, size
, name
);
176 ret
= ASN1_CreateEncoder(mod
, &encoder
, buf
, 0, NULL
);
177 ok(encoder
->dwFlags
== 0,"Got incorrect dwFlags = %08x.\n",encoder
->dwFlags
);
178 ASN1_CloseEncoder(encoder
);
180 ret
= ASN1_CreateEncoder(mod
, &encoder
, buf
, 4, NULL
);
181 ok(encoder
->dwFlags
== ASN1ENCODE_SETBUFFER
,"Got incorrect dwFlags = %08x.\n",encoder
->dwFlags
);
182 ASN1_CloseEncoder(encoder
);
183 ASN1_CloseModule(mod
);
185 mod
= ASN1_CreateModule(ASN1_THIS_VERSION
, ASN1_PER_RULE_ALIGNED
, ASN1FLAGS_NOASSERT
, 1, encfn
, decfn
, freefn
, size
, name
);
186 ret
= ASN1_CreateEncoder(mod
, &encoder
, buf
, 0, NULL
);
187 ok(ASN1_SUCCEEDED(ret
),"Got error code %d.\n",ret
);
188 ok(!!encoder
,"Encoder creation failed.\n");
189 ok(encoder
->magic
==0x44434e45,"Got invalid magic = %08x.\n",encoder
->magic
);
190 ok(!encoder
->version
,"Got incorrect version = %08x.\n",encoder
->version
);
191 ok(encoder
->module
==mod
,"Got incorrect module = %p.\n",encoder
->module
);
192 ok(!encoder
->buf
,"Got incorrect buf = %p.\n",encoder
->buf
);
193 ok(!encoder
->size
,"Got incorrect size = %u.\n",encoder
->size
);
194 ok(!encoder
->len
,"Got incorrect length = %u.\n",encoder
->len
);
195 ok(encoder
->err
==ASN1_SUCCESS
,"Got incorrect err = %d.\n",encoder
->err
);
196 ok(!encoder
->bit
,"Got incorrect bit = %u.\n",encoder
->bit
);
197 ok(!encoder
->pos
,"Got incorrect pos = %p.\n",encoder
->pos
);
198 ok(!encoder
->cbExtraHeader
,"Got incorrect cbExtraHeader = %u.\n",encoder
->cbExtraHeader
);
199 ok(encoder
->eRule
== ASN1_PER_RULE_ALIGNED
,"Got incorrect eRule = %08x.\n",encoder
->eRule
);
200 ok(encoder
->dwFlags
== ASN1ENCODE_NOASSERT
,"Got incorrect dwFlags = %08x.\n",encoder
->dwFlags
);
201 ASN1_CloseEncoder(encoder
);
203 ret
= ASN1_CreateEncoder(mod
, &encoder
, buf
, 4, NULL
);
204 ok(!!encoder
,"Encoder creation failed.\n");
205 ok(encoder
->magic
==0x44434e45,"Got invalid magic = %08x.\n",encoder
->magic
);
206 ok(!encoder
->version
,"Got incorrect version = %08x.\n",encoder
->version
);
207 ok(encoder
->module
==mod
,"Got incorrect module = %p.\n",encoder
->module
);
208 ok(encoder
->buf
==buf
,"Got incorrect buf = %p.\n",encoder
->buf
);
209 ok(encoder
->size
==4,"Got incorrect size = %u.\n",encoder
->size
);
210 ok(!encoder
->len
,"Got incorrect length = %u.\n",encoder
->len
);
211 ok(encoder
->err
==ASN1_SUCCESS
,"Got incorrect err = %d.\n",encoder
->err
);
212 ok(!encoder
->bit
,"Got incorrect bit = %u.\n",encoder
->bit
);
213 ok(encoder
->pos
==buf
,"Got incorrect pos = %p.\n",encoder
->pos
);
214 ok(!encoder
->cbExtraHeader
,"Got incorrect cbExtraHeader = %u.\n",encoder
->cbExtraHeader
);
215 ok(encoder
->eRule
== ASN1_PER_RULE_ALIGNED
,"Got incorrect rule = %08x.\n",encoder
->eRule
);
216 ok(encoder
->dwFlags
== (ASN1FLAGS_NOASSERT
|ASN1ENCODE_SETBUFFER
),"Got incorrect dwFlags = %08x.\n",encoder
->dwFlags
);
217 ASN1_CloseEncoder(encoder
);
218 ASN1_CloseModule(mod
);
220 mod
= ASN1_CreateModule(ASN1_THIS_VERSION
, ASN1_PER_RULE_ALIGNED
, ASN1FLAGS_NONE
, 1, encfn
, decfn
, freefn
, size
, name
);
221 ret
= ASN1_CreateEncoder(mod
, &encoder
, buf
, 0, NULL
);
222 ok(encoder
->dwFlags
== 0,"Got incorrect dwFlags = %08x.\n",encoder
->dwFlags
);
223 ASN1_CloseEncoder(encoder
);
225 ret
= ASN1_CreateEncoder(mod
, &encoder
, buf
, 4, NULL
);
226 ok(encoder
->dwFlags
== ASN1ENCODE_SETBUFFER
,"Got incorrect dwFlags = %08x.\n",encoder
->dwFlags
);
227 ASN1_CloseEncoder(encoder
);
228 ASN1_CloseModule(mod
);
231 static void test_CreateDecoder(void)
233 const ASN1GenericFun_t encfn
[] = { NULL
};
234 const ASN1GenericFun_t decfn
[] = { NULL
};
235 const ASN1FreeFun_t freefn
[] = { NULL
};
236 const ASN1uint32_t size
[] = { 0 };
237 ASN1magic_t name
= 0x61736e31;
238 ASN1decoding_t decoder
= NULL
;
239 ASN1octet_t buf
[] = {0x54,0x65,0x73,0x74,0};
243 ret
= ASN1_CreateDecoder(NULL
, NULL
, NULL
, 0, NULL
);
244 ok(ret
== ASN1_ERR_BADARGS
,"Got error code %d.\n",ret
);
246 mod
= ASN1_CreateModule(ASN1_THIS_VERSION
, ASN1_BER_RULE_DER
, ASN1FLAGS_NOASSERT
, 1, encfn
, decfn
, freefn
, size
, name
);
247 ret
= ASN1_CreateDecoder(mod
, NULL
, NULL
, 0, NULL
);
248 ok(ret
== ASN1_ERR_BADARGS
,"Got error code %d.\n",ret
);
250 ret
= ASN1_CreateDecoder(mod
, &decoder
, NULL
, 0, NULL
);
251 ok(ASN1_SUCCEEDED(ret
),"Got error code %d.\n",ret
);
252 ok(!!decoder
,"Decoder creation failed.\n");
253 ok(decoder
->magic
==0x44434544,"Got invalid magic = %08x.\n",decoder
->magic
);
254 ok(!decoder
->version
,"Got incorrect version = %08x.\n",decoder
->version
);
255 ok(decoder
->module
==mod
,"Got incorrect module = %p.\n",decoder
->module
);
256 ok(!decoder
->buf
,"Got incorrect buf = %p.\n",decoder
->buf
);
257 ok(!decoder
->size
,"Got incorrect size = %u.\n",decoder
->size
);
258 ok(!decoder
->len
,"Got incorrect length = %u.\n",decoder
->len
);
259 ok(decoder
->err
==ASN1_SUCCESS
,"Got incorrect err = %d.\n",decoder
->err
);
260 ok(!decoder
->bit
,"Got incorrect bit = %u.\n",decoder
->bit
);
261 ok(!decoder
->pos
,"Got incorrect pos = %p.\n",decoder
->pos
);
262 ok(decoder
->eRule
== ASN1_BER_RULE_DER
,"Got incorrect eRule = %08x.\n",decoder
->eRule
);
263 ok(decoder
->dwFlags
== ASN1DECODE_NOASSERT
,"Got incorrect dwFlags = %08x.\n",decoder
->dwFlags
);
264 ASN1_CloseDecoder(decoder
);
266 ret
= ASN1_CreateDecoder(mod
, &decoder
, buf
, 0, NULL
);
267 ok(ASN1_SUCCEEDED(ret
),"Got error code %d.\n",ret
);
268 ok(!!decoder
,"Decoder creation failed.\n");
269 ok(decoder
->magic
==0x44434544,"Got invalid magic = %08x.\n",decoder
->magic
);
270 ok(!decoder
->version
,"Got incorrect version = %08x.\n",decoder
->version
);
271 ok(decoder
->module
==mod
,"Got incorrect module = %p.\n",decoder
->module
);
272 ok(decoder
->buf
==buf
,"Got incorrect buf = %s.\n",decoder
->buf
);
273 ok(!decoder
->size
,"Got incorrect size = %u.\n",decoder
->size
);
274 ok(!decoder
->len
,"Got incorrect length = %u.\n",decoder
->len
);
275 ok(decoder
->err
==ASN1_SUCCESS
,"Got incorrect err = %d.\n",decoder
->err
);
276 ok(!decoder
->bit
,"Got incorrect bit = %u.\n",decoder
->bit
);
277 ok(decoder
->pos
==buf
,"Got incorrect pos = %s.\n",decoder
->pos
);
278 ok(decoder
->eRule
== ASN1_BER_RULE_DER
,"Got incorrect eRule = %08x.\n",decoder
->eRule
);
279 ok(decoder
->dwFlags
== (ASN1DECODE_NOASSERT
|ASN1DECODE_SETBUFFER
), "Got incorrect dwFlags = %08x.\n",decoder
->dwFlags
);
280 ASN1_CloseDecoder(decoder
);
282 ret
= ASN1_CreateDecoder(mod
, &decoder
, buf
, 2, NULL
);
283 ok(ASN1_SUCCEEDED(ret
),"Got error code %d.\n",ret
);
284 ok(!!decoder
,"Decoder creation failed.\n");
285 ok(decoder
->magic
==0x44434544,"Got invalid magic = %08x.\n",decoder
->magic
);
286 ok(!decoder
->version
,"Got incorrect version = %08x.\n",decoder
->version
);
287 ok(decoder
->module
==mod
,"Got incorrect module = %p.\n",decoder
->module
);
288 ok(decoder
->buf
==buf
,"Got incorrect buf = %p.\n",decoder
->buf
);
289 ok(decoder
->size
==2,"Got incorrect size = %u.\n",decoder
->size
);
290 ok(!decoder
->len
,"Got incorrect length = %u.\n",decoder
->len
);
291 ok(decoder
->err
==ASN1_SUCCESS
,"Got incorrect err = %d.\n",decoder
->err
);
292 ok(!decoder
->bit
,"Got incorrect bit = %u.\n",decoder
->bit
);
293 ok(decoder
->pos
==buf
,"Got incorrect pos = %p.\n",decoder
->pos
);
294 ok(decoder
->eRule
== ASN1_BER_RULE_DER
,"Got incorrect eRule = %08x.\n",decoder
->eRule
);
295 ok(decoder
->dwFlags
== (ASN1DECODE_NOASSERT
|ASN1DECODE_SETBUFFER
),"Got incorrect dwFlags = %08x.\n",decoder
->dwFlags
);
296 ASN1_CloseDecoder(decoder
);
298 ret
= ASN1_CreateDecoder(mod
, &decoder
, buf
, 4, NULL
);
299 ok(ASN1_SUCCEEDED(ret
),"Got error code %d.\n",ret
);
300 ok(!!decoder
,"Decoder creation failed.\n");
301 ok(decoder
->magic
==0x44434544,"Got invalid magic = %08x.\n",decoder
->magic
);
302 ok(!decoder
->version
,"Got incorrect version = %08x.\n",decoder
->version
);
303 ok(decoder
->module
==mod
,"Got incorrect module = %p.\n",decoder
->module
);
304 ok(decoder
->buf
==buf
,"Got incorrect buf = %p.\n",decoder
->buf
);
305 ok(decoder
->size
==4,"Got incorrect size = %u.\n",decoder
->size
);
306 ok(!decoder
->len
,"Got incorrect length = %u.\n",decoder
->len
);
307 ok(decoder
->err
==ASN1_SUCCESS
,"Got incorrect err = %d.\n",decoder
->err
);
308 ok(!decoder
->bit
,"Got incorrect bit = %u.\n",decoder
->bit
);
309 ok(decoder
->pos
==buf
,"Got incorrect pos = %p.\n",decoder
->pos
);
310 ok(decoder
->eRule
== ASN1_BER_RULE_DER
,"Got incorrect rule = %08x.\n",decoder
->eRule
);
311 ok(decoder
->dwFlags
== (ASN1DECODE_NOASSERT
|ASN1DECODE_SETBUFFER
),"Got incorrect dwFlags = %08x.\n",decoder
->dwFlags
);
312 ASN1_CloseDecoder(decoder
);
313 ASN1_CloseModule(mod
);
315 mod
= ASN1_CreateModule(ASN1_THIS_VERSION
, ASN1_BER_RULE_DER
, ASN1FLAGS_NONE
, 1, encfn
, decfn
, freefn
, size
, name
);
316 ret
= ASN1_CreateDecoder(mod
, &decoder
, buf
, 0, NULL
);
317 ok(decoder
->dwFlags
== ASN1DECODE_SETBUFFER
,"Got incorrect dwFlags = %08x.\n",decoder
->dwFlags
);
318 ASN1_CloseDecoder(decoder
);
320 ret
= ASN1_CreateDecoder(mod
, &decoder
, buf
, 4, NULL
);
321 ok(decoder
->dwFlags
== ASN1DECODE_SETBUFFER
,"Got incorrect dwFlags = %08x.\n",decoder
->dwFlags
);
322 ASN1_CloseDecoder(decoder
);
323 ASN1_CloseModule(mod
);
325 mod
= ASN1_CreateModule(ASN1_THIS_VERSION
, ASN1_PER_RULE_ALIGNED
, ASN1FLAGS_NOASSERT
, 1, encfn
, decfn
, freefn
, size
, name
);
326 ret
= ASN1_CreateDecoder(mod
, &decoder
, buf
, 0, NULL
);
327 ok(ASN1_SUCCEEDED(ret
),"Got error code %d.\n",ret
);
328 ok(!!decoder
,"Decoder creation failed.\n");
329 ok(decoder
->magic
==0x44434544,"Got invalid magic = %08x.\n",decoder
->magic
);
330 ok(!decoder
->version
,"Got incorrect version = %08x.\n",decoder
->version
);
331 ok(decoder
->module
==mod
,"Got incorrect module = %p.\n",decoder
->module
);
332 ok(decoder
->buf
==buf
,"Got incorrect buf = %s.\n",decoder
->buf
);
333 ok(!decoder
->size
,"Got incorrect size = %u.\n",decoder
->size
);
334 ok(!decoder
->len
,"Got incorrect length = %u.\n",decoder
->len
);
335 ok(decoder
->err
==ASN1_SUCCESS
,"Got incorrect err = %d.\n",decoder
->err
);
336 ok(!decoder
->bit
,"Got incorrect bit = %u.\n",decoder
->bit
);
337 ok(decoder
->pos
==buf
,"Got incorrect pos = %s.\n",decoder
->pos
);
338 ok(decoder
->eRule
== ASN1_PER_RULE_ALIGNED
,"Got incorrect eRule = %08x.\n",decoder
->eRule
);
339 ok(decoder
->dwFlags
== (ASN1DECODE_NOASSERT
|ASN1DECODE_SETBUFFER
),"Got incorrect dwFlags = %08x.\n",decoder
->dwFlags
);
340 ASN1_CloseDecoder(decoder
);
342 ret
= ASN1_CreateDecoder(mod
, &decoder
, buf
, 4, NULL
);
343 ok(!!decoder
,"Decoder creation failed.\n");
344 ok(decoder
->magic
==0x44434544,"Got invalid magic = %08x.\n",decoder
->magic
);
345 ok(!decoder
->version
,"Got incorrect version = %08x.\n",decoder
->version
);
346 ok(decoder
->module
==mod
,"Got incorrect module = %p.\n",decoder
->module
);
347 ok(decoder
->buf
==buf
,"Got incorrect buf = %p.\n",decoder
->buf
);
348 ok(decoder
->size
==4,"Got incorrect size = %u.\n",decoder
->size
);
349 ok(!decoder
->len
,"Got incorrect length = %u.\n",decoder
->len
);
350 ok(decoder
->err
==ASN1_SUCCESS
,"Got incorrect err = %d.\n",decoder
->err
);
351 ok(!decoder
->bit
,"Got incorrect bit = %u.\n",decoder
->bit
);
352 ok(decoder
->pos
==buf
,"Got incorrect pos = %p.\n",decoder
->pos
);
353 ok(decoder
->eRule
== ASN1_PER_RULE_ALIGNED
,"Got incorrect rule = %08x.\n",decoder
->eRule
);
354 ok(decoder
->dwFlags
== (ASN1FLAGS_NOASSERT
|ASN1DECODE_SETBUFFER
),"Got incorrect dwFlags = %08x.\n",decoder
->dwFlags
);
355 ASN1_CloseDecoder(decoder
);
356 ASN1_CloseModule(mod
);
358 mod
= ASN1_CreateModule(ASN1_THIS_VERSION
, ASN1_PER_RULE_ALIGNED
, ASN1FLAGS_NONE
, 1, encfn
, decfn
, freefn
, size
, name
);
359 ret
= ASN1_CreateDecoder(mod
, &decoder
, buf
, 0, NULL
);
360 ok(decoder
->dwFlags
== ASN1DECODE_SETBUFFER
,"Got incorrect dwFlags = %08x.\n",decoder
->dwFlags
);
361 ASN1_CloseDecoder(decoder
);
363 ret
= ASN1_CreateDecoder(mod
, &decoder
, buf
, 4, NULL
);
364 ok(decoder
->dwFlags
== ASN1DECODE_SETBUFFER
,"Got incorrect dwFlags = %08x.\n",decoder
->dwFlags
);
365 ASN1_CloseDecoder(decoder
);
366 ASN1_CloseModule(mod
);
372 test_CreateEncoder();
373 test_CreateDecoder();