2 * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include "internal/quic_srtm.h"
15 static const QUIC_STATELESS_RESET_TOKEN token_1 = {{
16 0x01, 0x02, 0x03, 0x04
19 static const QUIC_STATELESS_RESET_TOKEN token_2 = {{
20 0x01, 0x02, 0x03, 0x05
23 static int test_srtm(void)
30 if (!TEST_ptr(srtm = ossl_quic_srtm_new(NULL, NULL)))
33 if (!TEST_true(ossl_quic_srtm_add(srtm, ptrs + 0, 0, &token_1))
34 || !TEST_false(ossl_quic_srtm_add(srtm, ptrs + 0, 0, &token_1))
35 || !TEST_false(ossl_quic_srtm_remove(srtm, ptrs + 0, 1))
36 || !TEST_false(ossl_quic_srtm_remove(srtm, ptrs + 3, 0))
37 || !TEST_true(ossl_quic_srtm_cull(srtm, ptrs + 3))
38 || !TEST_true(ossl_quic_srtm_cull(srtm, ptrs + 3))
39 || !TEST_true(ossl_quic_srtm_add(srtm, ptrs + 0, 1, &token_1))
40 || !TEST_true(ossl_quic_srtm_add(srtm, ptrs + 0, 2, &token_1))
41 || !TEST_true(ossl_quic_srtm_add(srtm, ptrs + 0, 3, &token_1))
42 || !TEST_true(ossl_quic_srtm_add(srtm, ptrs + 1, 0, &token_1))
43 || !TEST_true(ossl_quic_srtm_add(srtm, ptrs + 2, 0, &token_2))
44 || !TEST_true(ossl_quic_srtm_add(srtm, ptrs + 3, 3, &token_2))
45 || !TEST_true(ossl_quic_srtm_remove(srtm, ptrs + 3, 3))
46 || !TEST_true(ossl_quic_srtm_lookup(srtm, &token_1, 0, &opaque, &seq_num))
47 || !TEST_ptr_eq(opaque, ptrs + 1)
48 || !TEST_uint64_t_eq(seq_num, 0)
49 || !TEST_true(ossl_quic_srtm_lookup(srtm, &token_1, 1, &opaque, &seq_num))
50 || !TEST_ptr_eq(opaque, ptrs + 0)
51 || !TEST_uint64_t_eq(seq_num, 3)
52 || !TEST_true(ossl_quic_srtm_lookup(srtm, &token_1, 2, &opaque, &seq_num))
53 || !TEST_ptr_eq(opaque, ptrs + 0)
54 || !TEST_uint64_t_eq(seq_num, 2)
55 || !TEST_true(ossl_quic_srtm_lookup(srtm, &token_1, 3, &opaque, &seq_num))
56 || !TEST_ptr_eq(opaque, ptrs + 0)
57 || !TEST_uint64_t_eq(seq_num, 1)
58 || !TEST_true(ossl_quic_srtm_lookup(srtm, &token_1, 4, &opaque, &seq_num))
59 || !TEST_ptr_eq(opaque, ptrs + 0)
60 || !TEST_uint64_t_eq(seq_num, 0)
61 || !TEST_false(ossl_quic_srtm_lookup(srtm, &token_1, 5, &opaque, &seq_num))
62 || !TEST_true(ossl_quic_srtm_cull(srtm, ptrs + 0))
63 || !TEST_true(ossl_quic_srtm_lookup(srtm, &token_1, 0, &opaque, &seq_num))
64 || !TEST_ptr_eq(opaque, ptrs + 1)
65 || !TEST_uint64_t_eq(seq_num, 0)
66 || !TEST_true(ossl_quic_srtm_lookup(srtm, &token_2, 0, &opaque, &seq_num))
67 || !TEST_ptr_eq(opaque, ptrs + 2)
68 || !TEST_uint64_t_eq(seq_num, 0)
69 || !TEST_true(ossl_quic_srtm_remove(srtm, ptrs + 2, 0))
70 || !TEST_false(ossl_quic_srtm_lookup(srtm, &token_2, 0, &opaque, &seq_num))
76 ossl_quic_srtm_free(srtm);