doc: update FIPS provider version information
[openssl.git] / test / cc_dummy.c
1 /*
2  * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9
10 #include "internal/quic_cc.h"
11 #include "internal/quic_types.h"
12
13 typedef struct ossl_cc_dummy_st {
14     size_t max_dgram_len;
15     size_t *p_diag_max_dgram_len;
16 } OSSL_CC_DUMMY;
17
18 static void dummy_update_diag(OSSL_CC_DUMMY *d);
19
20 static OSSL_CC_DATA *dummy_new(OSSL_TIME (*now_cb)(void *arg),
21                                void *now_cb_arg)
22 {
23     OSSL_CC_DUMMY *d = OPENSSL_zalloc(sizeof(*d));
24
25     if (d == NULL)
26         return NULL;
27
28     d->max_dgram_len = QUIC_MIN_INITIAL_DGRAM_LEN;
29     return (OSSL_CC_DATA *)d;
30 }
31
32 static void dummy_free(OSSL_CC_DATA *cc)
33 {
34     OPENSSL_free(cc);
35 }
36
37 static void dummy_reset(OSSL_CC_DATA *cc)
38 {
39
40 }
41
42 static int dummy_set_input_params(OSSL_CC_DATA *cc, const OSSL_PARAM *params)
43 {
44     OSSL_CC_DUMMY *d = (OSSL_CC_DUMMY *)cc;
45     const OSSL_PARAM *p;
46     size_t value;
47
48     p = OSSL_PARAM_locate_const(params, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN);
49     if (p != NULL) {
50         if (!OSSL_PARAM_get_size_t(p, &value))
51             return 0;
52         if (value < QUIC_MIN_INITIAL_DGRAM_LEN)
53             return 0;
54
55         d->max_dgram_len = value;
56         dummy_update_diag(d);
57     }
58
59     return 1;
60 }
61
62 static int dummy_bind_diagnostic(OSSL_CC_DATA *cc, OSSL_PARAM *params)
63 {
64     OSSL_CC_DUMMY *d = (OSSL_CC_DUMMY *)cc;
65     const OSSL_PARAM *p;
66
67     p = OSSL_PARAM_locate_const(params, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN);
68     if (p != NULL) {
69         if (p->data_type != OSSL_PARAM_UNSIGNED_INTEGER
70             || p->data_size != sizeof(size_t))
71             return 0;
72
73         d->p_diag_max_dgram_len = p->data;
74     }
75
76     dummy_update_diag(d);
77     return 1;
78 }
79
80 static int dummy_unbind_diagnostic(OSSL_CC_DATA *cc, OSSL_PARAM *params)
81 {
82     OSSL_CC_DUMMY *d = (OSSL_CC_DUMMY *)cc;
83
84     if (OSSL_PARAM_locate_const(params, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN)
85         != NULL)
86         d->p_diag_max_dgram_len = NULL;
87
88     return 1;
89 }
90
91 static void dummy_update_diag(OSSL_CC_DUMMY *d)
92 {
93     if (d->p_diag_max_dgram_len != NULL)
94         *d->p_diag_max_dgram_len = d->max_dgram_len;
95 }
96
97 static uint64_t dummy_get_tx_allowance(OSSL_CC_DATA *cc)
98 {
99     return SIZE_MAX;
100 }
101
102 static OSSL_TIME dummy_get_wakeup_deadline(OSSL_CC_DATA *cc)
103 {
104     return ossl_time_infinite();
105 }
106
107 static int dummy_on_data_sent(OSSL_CC_DATA *cc,
108                               uint64_t num_bytes)
109 {
110     return 1;
111 }
112
113 static int dummy_on_data_acked(OSSL_CC_DATA *cc,
114                                const OSSL_CC_ACK_INFO *info)
115 {
116     return 1;
117 }
118
119 static int dummy_on_data_lost(OSSL_CC_DATA *cc,
120                               const OSSL_CC_LOSS_INFO *info)
121 {
122     return 1;
123 }
124
125 static int dummy_on_data_lost_finished(OSSL_CC_DATA *cc,
126                                        uint32_t flags)
127 {
128     return 1;
129 }
130
131 static int dummy_on_data_invalidated(OSSL_CC_DATA *cc,
132                                      uint64_t num_bytes)
133 {
134     return 1;
135 }
136
137 const OSSL_CC_METHOD ossl_cc_dummy_method = {
138     dummy_new,
139     dummy_free,
140     dummy_reset,
141     dummy_set_input_params,
142     dummy_bind_diagnostic,
143     dummy_unbind_diagnostic,
144     dummy_get_tx_allowance,
145     dummy_get_wakeup_deadline,
146     dummy_on_data_sent,
147     dummy_on_data_acked,
148     dummy_on_data_lost,
149     dummy_on_data_lost_finished,
150     dummy_on_data_invalidated,
151 };