Lines Matching +full:pkt +full:- +full:size
2 * Copyright 2016-2025 The OpenSSL Project Authors. All Rights Reserved.
31 /* QUIC sub-packet with 4-byte length prefix, containing a 1-byte vlint */
33 /* QUIC sub-packet with 1-byte length prefix, containing a 1-byte vlint */
35 /* QUIC sub-packet with 2-byte length prefix, containing a 2-byte vlint */
37 /* QUIC sub-packet with 8-byte length prefix, containing a 4-byte vlint */
42 /* QUIC sub-packet with 8-byte length prefix, containing a 8-byte vlint */
47 /* QUIC sub-packet, length known up-front */
49 /* Nested and sequential sub-packets with length prefixes */
59 static int cleanup(WPACKET *pkt) in cleanup() argument
61 WPACKET_cleanup(pkt); in cleanup()
67 WPACKET pkt; in test_WPACKET_init() local
72 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_init()
73 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_init()
75 || !TEST_false(WPACKET_close(&pkt)) in test_WPACKET_init()
77 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_init()
82 || !TEST_false(WPACKET_close(&pkt)) in test_WPACKET_init()
83 || !TEST_false(WPACKET_finish(&pkt)) in test_WPACKET_init()
84 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_init()
85 || !TEST_mem_eq(buf->data, written, simple1, sizeof(simple1))) in test_WPACKET_init()
86 return cleanup(&pkt); in test_WPACKET_init()
89 if (!TEST_true(WPACKET_init_len(&pkt, buf, 1)) in test_WPACKET_init()
90 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_init()
91 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_init()
92 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_init()
93 || !TEST_mem_eq(buf->data, written, simple2, sizeof(simple2))) in test_WPACKET_init()
94 return cleanup(&pkt); in test_WPACKET_init()
97 if (!TEST_true(WPACKET_init_len(&pkt, buf, 4)) in test_WPACKET_init()
98 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_init()
99 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_init()
100 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_init()
101 || !TEST_mem_eq(buf->data, written, simple3, sizeof(simple3))) in test_WPACKET_init()
102 return cleanup(&pkt); in test_WPACKET_init()
104 if (!TEST_true(WPACKET_init_len(&pkt, buf, 1))) in test_WPACKET_init()
105 return cleanup(&pkt); in test_WPACKET_init()
108 * Putting more bytes in than fit for the size of the length prefix in test_WPACKET_init()
111 if (!TEST_int_eq(WPACKET_put_bytes_u8(&pkt, 0xff), i < 256)) in test_WPACKET_init()
112 return cleanup(&pkt); in test_WPACKET_init()
114 if (!TEST_true(WPACKET_finish(&pkt))) in test_WPACKET_init()
115 return cleanup(&pkt); in test_WPACKET_init()
117 /* Test initialising from a fixed size buffer */ in test_WPACKET_init()
118 if (!TEST_true(WPACKET_init_static_len(&pkt, sbuf, sizeof(sbuf), 0)) in test_WPACKET_init()
120 || !TEST_true(WPACKET_put_bytes_u24(&pkt, 0xffffff)) in test_WPACKET_init()
122 || !TEST_false(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_init()
124 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_init()
125 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_init()
128 || !TEST_true(WPACKET_init_static_len(&pkt, sbuf, sizeof(sbuf), 1)) in test_WPACKET_init()
130 || !TEST_true(WPACKET_put_bytes_u16(&pkt, 0xfeff)) in test_WPACKET_init()
132 || !TEST_false(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_init()
133 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_init()
134 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_init()
136 return cleanup(&pkt); in test_WPACKET_init()
143 WPACKET pkt; in test_WPACKET_set_max_size() local
146 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_set_max_size()
149 * possible max size in test_WPACKET_set_max_size()
151 || !TEST_true(WPACKET_set_max_size(&pkt, SIZE_MAX)) in test_WPACKET_set_max_size()
153 || !TEST_true(WPACKET_set_max_size(&pkt, SIZE_MAX -1)) in test_WPACKET_set_max_size()
155 || !TEST_true(WPACKET_set_max_size(&pkt, SIZE_MAX)) in test_WPACKET_set_max_size()
156 || !TEST_true(WPACKET_finish(&pkt))) in test_WPACKET_set_max_size()
157 return cleanup(&pkt); in test_WPACKET_set_max_size()
159 if (!TEST_true(WPACKET_init_len(&pkt, buf, 1)) in test_WPACKET_set_max_size()
164 || !TEST_false(WPACKET_set_max_size(&pkt, 0)) in test_WPACKET_set_max_size()
166 * Max size can't be bigger than biggest that will fit in in test_WPACKET_set_max_size()
169 || !TEST_false(WPACKET_set_max_size(&pkt, 0x0101)) in test_WPACKET_set_max_size()
170 /* It can be the same as the maximum possible size */ in test_WPACKET_set_max_size()
171 || !TEST_true(WPACKET_set_max_size(&pkt, 0x0100)) in test_WPACKET_set_max_size()
173 || !TEST_true(WPACKET_set_max_size(&pkt, 0x01)) in test_WPACKET_set_max_size()
175 || !TEST_false(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_set_max_size()
176 /* You can't put in more bytes than max size */ in test_WPACKET_set_max_size()
177 || !TEST_true(WPACKET_set_max_size(&pkt, 0x02)) in test_WPACKET_set_max_size()
178 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_set_max_size()
179 || !TEST_false(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_set_max_size()
180 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_set_max_size()
181 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_set_max_size()
182 || !TEST_mem_eq(buf->data, written, simple2, sizeof(simple2))) in test_WPACKET_set_max_size()
183 return cleanup(&pkt); in test_WPACKET_set_max_size()
190 WPACKET pkt; in test_WPACKET_start_sub_packet() local
194 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_start_sub_packet()
195 || !TEST_true(WPACKET_start_sub_packet(&pkt)) in test_WPACKET_start_sub_packet()
196 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_start_sub_packet()
198 || !TEST_false(WPACKET_finish(&pkt)) in test_WPACKET_start_sub_packet()
199 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_start_sub_packet()
201 || !TEST_false(WPACKET_close(&pkt)) in test_WPACKET_start_sub_packet()
203 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_start_sub_packet()
204 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_start_sub_packet()
205 || !TEST_mem_eq(buf->data, written, simple1, sizeof(simple1))) in test_WPACKET_start_sub_packet()
206 return cleanup(&pkt); in test_WPACKET_start_sub_packet()
208 /* Single sub-packet with length prefix */ in test_WPACKET_start_sub_packet()
209 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_start_sub_packet()
210 || !TEST_true(WPACKET_start_sub_packet_u8(&pkt)) in test_WPACKET_start_sub_packet()
211 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_start_sub_packet()
212 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_start_sub_packet()
213 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_start_sub_packet()
214 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_start_sub_packet()
215 || !TEST_mem_eq(buf->data, written, simple2, sizeof(simple2))) in test_WPACKET_start_sub_packet()
216 return cleanup(&pkt); in test_WPACKET_start_sub_packet()
218 /* Nested sub-packets with length prefixes */ in test_WPACKET_start_sub_packet()
219 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_start_sub_packet()
220 || !TEST_true(WPACKET_start_sub_packet_u8(&pkt)) in test_WPACKET_start_sub_packet()
221 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_start_sub_packet()
222 || !TEST_true(WPACKET_start_sub_packet_u8(&pkt)) in test_WPACKET_start_sub_packet()
223 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_start_sub_packet()
224 || !TEST_true(WPACKET_get_length(&pkt, &len)) in test_WPACKET_start_sub_packet()
226 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_start_sub_packet()
227 || !TEST_true(WPACKET_get_length(&pkt, &len)) in test_WPACKET_start_sub_packet()
229 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_start_sub_packet()
230 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_start_sub_packet()
231 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_start_sub_packet()
232 || !TEST_mem_eq(buf->data, written, nestedsub, sizeof(nestedsub))) in test_WPACKET_start_sub_packet()
233 return cleanup(&pkt); in test_WPACKET_start_sub_packet()
235 /* Sequential sub-packets with length prefixes */ in test_WPACKET_start_sub_packet()
236 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_start_sub_packet()
237 || !TEST_true(WPACKET_start_sub_packet_u8(&pkt)) in test_WPACKET_start_sub_packet()
238 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_start_sub_packet()
239 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_start_sub_packet()
240 || !TEST_true(WPACKET_start_sub_packet_u8(&pkt)) in test_WPACKET_start_sub_packet()
241 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_start_sub_packet()
242 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_start_sub_packet()
243 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_start_sub_packet()
244 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_start_sub_packet()
245 || !TEST_mem_eq(buf->data, written, seqsub, sizeof(seqsub))) in test_WPACKET_start_sub_packet()
246 return cleanup(&pkt); in test_WPACKET_start_sub_packet()
248 /* Nested sub-packets with lengths filled before finish */ in test_WPACKET_start_sub_packet()
249 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_start_sub_packet()
250 || !TEST_true(WPACKET_start_sub_packet_u8(&pkt)) in test_WPACKET_start_sub_packet()
251 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_start_sub_packet()
252 || !TEST_true(WPACKET_start_sub_packet_u8(&pkt)) in test_WPACKET_start_sub_packet()
253 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_start_sub_packet()
254 || !TEST_true(WPACKET_get_length(&pkt, &len)) in test_WPACKET_start_sub_packet()
256 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_start_sub_packet()
257 || !TEST_true(WPACKET_get_length(&pkt, &len)) in test_WPACKET_start_sub_packet()
259 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_start_sub_packet()
260 || !TEST_true(WPACKET_fill_lengths(&pkt)) in test_WPACKET_start_sub_packet()
261 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_start_sub_packet()
262 || !TEST_mem_eq(buf->data, written, nestedsub, sizeof(nestedsub)) in test_WPACKET_start_sub_packet()
263 || !TEST_true(WPACKET_finish(&pkt))) in test_WPACKET_start_sub_packet()
264 return cleanup(&pkt); in test_WPACKET_start_sub_packet()
272 WPACKET pkt; in test_WPACKET_set_flags() local
275 /* Set packet to be non-zero length */ in test_WPACKET_set_flags()
276 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_set_flags()
277 || !TEST_true(WPACKET_set_flags(&pkt, WPACKET_FLAGS_NON_ZERO_LENGTH)) in test_WPACKET_set_flags()
279 || !TEST_false(WPACKET_finish(&pkt)) in test_WPACKET_set_flags()
280 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_set_flags()
281 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_set_flags()
282 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_set_flags()
283 || !TEST_mem_eq(buf->data, written, simple1, sizeof(simple1))) in test_WPACKET_set_flags()
284 return cleanup(&pkt); in test_WPACKET_set_flags()
286 /* Repeat above test in a sub-packet */ in test_WPACKET_set_flags()
287 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_set_flags()
288 || !TEST_true(WPACKET_start_sub_packet(&pkt)) in test_WPACKET_set_flags()
289 || !TEST_true(WPACKET_set_flags(&pkt, WPACKET_FLAGS_NON_ZERO_LENGTH)) in test_WPACKET_set_flags()
291 || !TEST_false(WPACKET_close(&pkt)) in test_WPACKET_set_flags()
292 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_set_flags()
293 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_set_flags()
294 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_set_flags()
295 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_set_flags()
296 || !TEST_mem_eq(buf->data, written, simple1, sizeof(simple1))) in test_WPACKET_set_flags()
297 return cleanup(&pkt); in test_WPACKET_set_flags()
299 /* Set packet to abandon non-zero length */ in test_WPACKET_set_flags()
300 if (!TEST_true(WPACKET_init_len(&pkt, buf, 1)) in test_WPACKET_set_flags()
301 || !TEST_true(WPACKET_set_flags(&pkt, WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH)) in test_WPACKET_set_flags()
302 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_set_flags()
303 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_set_flags()
305 return cleanup(&pkt); in test_WPACKET_set_flags()
307 /* Repeat above test but only abandon a sub-packet */ in test_WPACKET_set_flags()
308 if (!TEST_true(WPACKET_init_len(&pkt, buf, 1)) in test_WPACKET_set_flags()
309 || !TEST_true(WPACKET_start_sub_packet_u8(&pkt)) in test_WPACKET_set_flags()
310 || !TEST_true(WPACKET_set_flags(&pkt, WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH)) in test_WPACKET_set_flags()
311 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_set_flags()
312 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_set_flags()
313 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_set_flags()
314 || !TEST_mem_eq(buf->data, written, empty, sizeof(empty))) in test_WPACKET_set_flags()
315 return cleanup(&pkt); in test_WPACKET_set_flags()
317 /* And repeat with a non empty sub-packet */ in test_WPACKET_set_flags()
318 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_set_flags()
319 || !TEST_true(WPACKET_start_sub_packet_u8(&pkt)) in test_WPACKET_set_flags()
320 || !TEST_true(WPACKET_set_flags(&pkt, WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH)) in test_WPACKET_set_flags()
321 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff)) in test_WPACKET_set_flags()
322 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_set_flags()
323 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_set_flags()
324 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_set_flags()
325 || !TEST_mem_eq(buf->data, written, simple2, sizeof(simple2))) in test_WPACKET_set_flags()
326 return cleanup(&pkt); in test_WPACKET_set_flags()
332 WPACKET pkt; in test_WPACKET_allocate_bytes() local
336 if (!TEST_true(WPACKET_init_len(&pkt, buf, 1)) in test_WPACKET_allocate_bytes()
337 || !TEST_true(WPACKET_allocate_bytes(&pkt, 2, &bytes))) in test_WPACKET_allocate_bytes()
338 return cleanup(&pkt); in test_WPACKET_allocate_bytes()
341 if (!TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_allocate_bytes()
342 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_allocate_bytes()
343 || !TEST_mem_eq(buf->data, written, alloc, sizeof(alloc))) in test_WPACKET_allocate_bytes()
344 return cleanup(&pkt); in test_WPACKET_allocate_bytes()
347 if (!TEST_true(WPACKET_init_len(&pkt, buf, 1)) in test_WPACKET_allocate_bytes()
348 || !TEST_true(WPACKET_sub_allocate_bytes_u8(&pkt, 2, &bytes))) in test_WPACKET_allocate_bytes()
349 return cleanup(&pkt); in test_WPACKET_allocate_bytes()
352 if (!TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_allocate_bytes()
353 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_allocate_bytes()
354 || !TEST_mem_eq(buf->data, written, submem, sizeof(submem))) in test_WPACKET_allocate_bytes()
355 return cleanup(&pkt); in test_WPACKET_allocate_bytes()
362 WPACKET pkt; in test_WPACKET_memcpy() local
366 if (!TEST_true(WPACKET_init_len(&pkt, buf, 1)) in test_WPACKET_memcpy()
367 || !TEST_true(WPACKET_memcpy(&pkt, bytes, sizeof(bytes))) in test_WPACKET_memcpy()
368 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_memcpy()
369 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_memcpy()
370 || !TEST_mem_eq(buf->data, written, alloc, sizeof(alloc))) in test_WPACKET_memcpy()
371 return cleanup(&pkt); in test_WPACKET_memcpy()
374 if (!TEST_true(WPACKET_init_len(&pkt, buf, 1)) in test_WPACKET_memcpy()
375 || !TEST_true(WPACKET_sub_memcpy_u8(&pkt, bytes, sizeof(bytes))) in test_WPACKET_memcpy()
376 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_memcpy()
377 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_memcpy()
378 || !TEST_mem_eq(buf->data, written, submem, sizeof(submem))) in test_WPACKET_memcpy()
379 return cleanup(&pkt); in test_WPACKET_memcpy()
386 WPACKET pkt; in test_WPACKET_init_der() local
396 if (!TEST_true(WPACKET_init_der(&pkt, sbuf, sizeof(sbuf))) in test_WPACKET_init_der()
397 || !TEST_true(WPACKET_put_bytes_u24(&pkt, 0xfffefd)) in test_WPACKET_init_der()
398 /* Test writing data in a length prefixed sub-packet */ in test_WPACKET_init_der()
399 || !TEST_true(WPACKET_start_sub_packet(&pkt)) in test_WPACKET_init_der()
400 || !TEST_true(WPACKET_memcpy(&pkt, testdata, sizeof(testdata))) in test_WPACKET_init_der()
401 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_init_der()
402 || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xfc)) in test_WPACKET_init_der()
403 /* this sub-packet is empty, and should render zero bytes */ in test_WPACKET_init_der()
404 || (!TEST_true(WPACKET_start_sub_packet(&pkt)) in test_WPACKET_init_der()
405 || !TEST_true(WPACKET_set_flags(&pkt, flags)) in test_WPACKET_init_der()
406 || !TEST_true(WPACKET_get_total_written(&pkt, &size1)) in test_WPACKET_init_der()
407 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_init_der()
408 || !TEST_true(WPACKET_get_total_written(&pkt, &size2)) in test_WPACKET_init_der()
410 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_init_der()
411 || !TEST_true(WPACKET_get_total_written(&pkt, &written[0])) in test_WPACKET_init_der()
412 || !TEST_mem_eq(WPACKET_get_curr(&pkt), written[0], simpleder, in test_WPACKET_init_der()
414 return cleanup(&pkt); in test_WPACKET_init_der()
417 if (!TEST_int_gt(RAND_bytes(&testdata2[3], sizeof(testdata2) - 3), 0)) in test_WPACKET_init_der()
421 * Test with a sub-packet that has 2 length bytes. We do 2 passes - first in test_WPACKET_init_der()
427 if (!TEST_true(WPACKET_init_null_der(&pkt))) in test_WPACKET_init_der()
430 if (!TEST_true(WPACKET_init_der(&pkt, sbuf, sizeof(sbuf)))) in test_WPACKET_init_der()
433 if (!TEST_true(WPACKET_start_sub_packet(&pkt)) in test_WPACKET_init_der()
434 || !TEST_true(WPACKET_memcpy(&pkt, &testdata2[3], in test_WPACKET_init_der()
435 sizeof(testdata2) - 3)) in test_WPACKET_init_der()
436 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_init_der()
437 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_init_der()
438 || !TEST_true(WPACKET_get_total_written(&pkt, &written[i]))) in test_WPACKET_init_der()
439 return cleanup(&pkt); in test_WPACKET_init_der()
443 * Check that the size calculated in the first pass equals the size of the in test_WPACKET_init_der()
448 || !TEST_mem_eq(WPACKET_get_curr(&pkt), written[1], testdata2, in test_WPACKET_init_der()
459 WPACKET pkt; in test_WPACKET_quic() local
463 /* QUIC sub-packet with 4-byte length prefix, containing a 1-byte vlint */ in test_WPACKET_quic()
464 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_quic()
465 || !TEST_true(WPACKET_start_quic_sub_packet(&pkt)) in test_WPACKET_quic()
466 || !TEST_true(WPACKET_quic_write_vlint(&pkt, 0x09)) in test_WPACKET_quic()
468 || !TEST_false(WPACKET_finish(&pkt)) in test_WPACKET_quic()
469 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_quic()
471 || !TEST_false(WPACKET_close(&pkt)) in test_WPACKET_quic()
473 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_quic()
474 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_quic()
475 || !TEST_mem_eq(buf->data, written, quic1, sizeof(quic1))) in test_WPACKET_quic()
476 return cleanup(&pkt); in test_WPACKET_quic()
478 /* QUIC sub-packet with 1-byte length prefix, containing a 1-byte vlint */ in test_WPACKET_quic()
479 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_quic()
480 || !TEST_true(WPACKET_start_quic_sub_packet_bound(&pkt, OSSL_QUIC_VLINT_1B_MAX)) in test_WPACKET_quic()
481 || !TEST_true(WPACKET_quic_write_vlint(&pkt, 0x09)) in test_WPACKET_quic()
482 || !TEST_false(WPACKET_finish(&pkt)) in test_WPACKET_quic()
483 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_quic()
484 || !TEST_false(WPACKET_close(&pkt)) in test_WPACKET_quic()
485 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_quic()
486 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_quic()
487 || !TEST_mem_eq(buf->data, written, quic2, sizeof(quic2))) in test_WPACKET_quic()
488 return cleanup(&pkt); in test_WPACKET_quic()
490 /* QUIC sub-packet with 2-byte length prefix, containing a 2-byte vlint */ in test_WPACKET_quic()
491 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_quic()
492 || !TEST_true(WPACKET_start_quic_sub_packet_bound(&pkt, OSSL_QUIC_VLINT_2B_MIN)) in test_WPACKET_quic()
493 || !TEST_true(WPACKET_quic_write_vlint(&pkt, 0x41)) in test_WPACKET_quic()
494 || !TEST_false(WPACKET_finish(&pkt)) in test_WPACKET_quic()
495 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_quic()
496 || !TEST_false(WPACKET_close(&pkt)) in test_WPACKET_quic()
497 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_quic()
498 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_quic()
499 || !TEST_mem_eq(buf->data, written, quic3, sizeof(quic3))) in test_WPACKET_quic()
500 return cleanup(&pkt); in test_WPACKET_quic()
502 /* QUIC sub-packet with 8-byte length prefix, containing a 4-byte vlint */ in test_WPACKET_quic()
503 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_quic()
504 || !TEST_true(WPACKET_start_quic_sub_packet_bound(&pkt, OSSL_QUIC_VLINT_8B_MIN)) in test_WPACKET_quic()
505 || !TEST_true(WPACKET_quic_write_vlint(&pkt, 0x13c6a)) in test_WPACKET_quic()
506 || !TEST_false(WPACKET_finish(&pkt)) in test_WPACKET_quic()
507 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_quic()
508 || !TEST_false(WPACKET_close(&pkt)) in test_WPACKET_quic()
509 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_quic()
510 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_quic()
511 || !TEST_mem_eq(buf->data, written, quic4, sizeof(quic4))) in test_WPACKET_quic()
512 return cleanup(&pkt); in test_WPACKET_quic()
514 /* QUIC sub-packet with 8-byte length prefix, containing a 8-byte vlint */ in test_WPACKET_quic()
515 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_quic()
516 || !TEST_true(WPACKET_start_quic_sub_packet_bound(&pkt, OSSL_QUIC_VLINT_8B_MIN)) in test_WPACKET_quic()
517 || !TEST_true(WPACKET_quic_write_vlint(&pkt, 0x2f77213f3f505ba5ULL)) in test_WPACKET_quic()
518 || !TEST_false(WPACKET_finish(&pkt)) in test_WPACKET_quic()
519 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_quic()
520 || !TEST_false(WPACKET_close(&pkt)) in test_WPACKET_quic()
521 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_quic()
522 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_quic()
523 || !TEST_mem_eq(buf->data, written, quic5, sizeof(quic5))) in test_WPACKET_quic()
524 return cleanup(&pkt); in test_WPACKET_quic()
526 /* QUIC sub-packet, length known up-front */ in test_WPACKET_quic()
527 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_quic()
528 || !TEST_true(WPACKET_quic_sub_allocate_bytes(&pkt, 3, &bytes))) in test_WPACKET_quic()
529 return cleanup(&pkt); in test_WPACKET_quic()
535 if (!TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_quic()
536 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_quic()
537 || !TEST_mem_eq(buf->data, written, quic6, sizeof(quic6))) in test_WPACKET_quic()
538 return cleanup(&pkt); in test_WPACKET_quic()
540 /* Nested and sequential sub-packets with length prefixes */ in test_WPACKET_quic()
541 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_quic()
542 || !TEST_true(WPACKET_quic_write_vlint(&pkt, 0x07)) in test_WPACKET_quic()
543 || !TEST_true(WPACKET_get_length(&pkt, &len)) in test_WPACKET_quic()
545 || !TEST_true(WPACKET_start_quic_sub_packet_bound(&pkt, OSSL_QUIC_VLINT_4B_MIN)) in test_WPACKET_quic()
546 || !TEST_true(WPACKET_quic_write_vlint(&pkt, 0x2514)) in test_WPACKET_quic()
547 || !TEST_true(WPACKET_get_length(&pkt, &len)) in test_WPACKET_quic()
549 || !TEST_true(WPACKET_start_quic_sub_packet_bound(&pkt, OSSL_QUIC_VLINT_2B_MIN)) in test_WPACKET_quic()
550 || !TEST_true(WPACKET_quic_write_vlint(&pkt, 0x05)) in test_WPACKET_quic()
551 || !TEST_true(WPACKET_get_length(&pkt, &len)) in test_WPACKET_quic()
553 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_quic()
554 || !TEST_true(WPACKET_start_quic_sub_packet_bound(&pkt, OSSL_QUIC_VLINT_2B_MIN)) in test_WPACKET_quic()
555 || !TEST_true(WPACKET_quic_write_vlint(&pkt, 0x11)) in test_WPACKET_quic()
556 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_quic()
557 || !TEST_true(WPACKET_get_length(&pkt, &len)) in test_WPACKET_quic()
559 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_quic()
560 || !TEST_true(WPACKET_start_quic_sub_packet_bound(&pkt, OSSL_QUIC_VLINT_2B_MIN)) in test_WPACKET_quic()
561 || !TEST_true(WPACKET_quic_write_vlint(&pkt, 0x12)) in test_WPACKET_quic()
562 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_quic()
563 || !TEST_true(WPACKET_start_quic_sub_packet_bound(&pkt, OSSL_QUIC_VLINT_2B_MIN)) in test_WPACKET_quic()
564 || !TEST_true(WPACKET_quic_write_vlint(&pkt, 0x13)) in test_WPACKET_quic()
565 || !TEST_true(WPACKET_close(&pkt)) in test_WPACKET_quic()
566 || !TEST_true(WPACKET_finish(&pkt)) in test_WPACKET_quic()
567 || !TEST_true(WPACKET_get_total_written(&pkt, &written)) in test_WPACKET_quic()
568 || !TEST_mem_eq(buf->data, written, quic7, sizeof(quic7))) in test_WPACKET_quic()
569 return cleanup(&pkt); in test_WPACKET_quic()
572 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_quic()
573 || !TEST_false(WPACKET_quic_write_vlint(&pkt, OSSL_QUIC_VLINT_MAX+1)) in test_WPACKET_quic()
574 || !TEST_true(WPACKET_quic_write_vlint(&pkt, OSSL_QUIC_VLINT_MAX))) in test_WPACKET_quic()
575 return cleanup(&pkt); in test_WPACKET_quic()
577 WPACKET_cleanup(&pkt); in test_WPACKET_quic()
586 WPACKET pkt; in test_WPACKET_quic_vlint_random() local
596 * Ensure that all size classes get tested with equal probability. in test_WPACKET_quic_vlint_random()
613 if (!TEST_true(WPACKET_init(&pkt, buf)) in test_WPACKET_quic_vlint_random()
614 || !TEST_true(WPACKET_quic_write_vlint(&pkt, expected)) in test_WPACKET_quic_vlint_random()
615 || !TEST_true(WPACKET_get_total_written(&pkt, &written))) in test_WPACKET_quic_vlint_random()
616 return cleanup(&pkt); in test_WPACKET_quic_vlint_random()
618 if (!TEST_true(PACKET_buf_init(&read_pkt, (unsigned char *)buf->data, written)) in test_WPACKET_quic_vlint_random()
621 return cleanup(&pkt); in test_WPACKET_quic_vlint_random()
623 WPACKET_cleanup(&pkt); in test_WPACKET_quic_vlint_random()
626 WPACKET_cleanup(&pkt); in test_WPACKET_quic_vlint_random()