• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 6449915476

08 Oct 2023 08:52PM UTC coverage: 91.697% (+0.005%) from 91.692%
6449915476

push

github

web-flow
Merge pull request #3729 from randombit/jack/enum-for-group-params

Wrap TLS::Group_Params enum in a class

79979 of 87221 relevant lines covered (91.7%)

8572940.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.05
/src/lib/tls/tls_algos.cpp
1
/*
2
* (C) 2017 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include <botan/tls_algos.h>
8

9
#include <botan/ec_group.h>
10
#include <botan/exceptn.h>
11
#include <botan/internal/fmt.h>
12

13
namespace Botan::TLS {
14

15
std::string kdf_algo_to_string(KDF_Algo algo) {
198,701✔
16
   switch(algo) {
198,701✔
17
      case KDF_Algo::SHA_1:
36,777✔
18
         return "SHA-1";
36,777✔
19
      case KDF_Algo::SHA_256:
119,946✔
20
         return "SHA-256";
119,946✔
21
      case KDF_Algo::SHA_384:
41,978✔
22
         return "SHA-384";
41,978✔
23
   }
24

25
   throw Invalid_State("kdf_algo_to_string unknown enum value");
×
26
}
27

28
std::string kex_method_to_string(Kex_Algo method) {
7,480✔
29
   switch(method) {
7,480✔
30
      case Kex_Algo::STATIC_RSA:
719✔
31
         return "RSA";
719✔
32
      case Kex_Algo::DH:
1,057✔
33
         return "DH";
1,057✔
34
      case Kex_Algo::ECDH:
4,035✔
35
         return "ECDH";
4,035✔
36
      case Kex_Algo::PSK:
824✔
37
         return "PSK";
824✔
38
      case Kex_Algo::ECDHE_PSK:
838✔
39
         return "ECDHE_PSK";
838✔
40
      case Kex_Algo::DHE_PSK:
×
41
         return "DHE_PSK";
×
42
      case Kex_Algo::KEM:
2✔
43
         return "KEM";
2✔
44
      case Kex_Algo::KEM_PSK:
×
45
         return "KEM_PSK";
×
46
      case Kex_Algo::HYBRID:
5✔
47
         return "HYBRID";
5✔
48
      case Kex_Algo::HYBRID_PSK:
×
49
         return "HYBRID_PSK";
×
50
      case Kex_Algo::UNDEFINED:
×
51
         return "UNDEFINED";
×
52
   }
53

54
   throw Invalid_State("kex_method_to_string unknown enum value");
×
55
}
56

57
Kex_Algo kex_method_from_string(std::string_view str) {
5✔
58
   if(str == "RSA") {
6✔
59
      return Kex_Algo::STATIC_RSA;
1✔
60
   }
61

62
   if(str == "DH") {
4✔
63
      return Kex_Algo::DH;
1✔
64
   }
65

66
   if(str == "ECDH") {
3✔
67
      return Kex_Algo::ECDH;
1✔
68
   }
69

70
   if(str == "PSK") {
2✔
71
      return Kex_Algo::PSK;
1✔
72
   }
73

74
   if(str == "ECDHE_PSK") {
1✔
75
      return Kex_Algo::ECDHE_PSK;
1✔
76
   }
77

78
   if(str == "DHE_PSK") {
×
79
      return Kex_Algo::DHE_PSK;
×
80
   }
81

82
   if(str == "KEM") {
×
83
      return Kex_Algo::KEM;
×
84
   }
85

86
   if(str == "KEM_PSK") {
×
87
      return Kex_Algo::KEM_PSK;
×
88
   }
89

90
   if(str == "HYBRID") {
×
91
      return Kex_Algo::HYBRID;
×
92
   }
93

94
   if(str == "HYBRID_PSK") {
×
95
      return Kex_Algo::HYBRID_PSK;
×
96
   }
97

98
   if(str == "UNDEFINED") {
×
99
      return Kex_Algo::UNDEFINED;
×
100
   }
101

102
   throw Invalid_Argument(fmt("Unknown kex method '{}'", str));
×
103
}
104

105
std::string auth_method_to_string(Auth_Method method) {
8,821✔
106
   switch(method) {
8,821✔
107
      case Auth_Method::RSA:
6,079✔
108
         return "RSA";
6,079✔
109
      case Auth_Method::ECDSA:
2,592✔
110
         return "ECDSA";
2,592✔
111
      case Auth_Method::IMPLICIT:
150✔
112
         return "IMPLICIT";
150✔
113
      case Auth_Method::UNDEFINED:
×
114
         return "UNDEFINED";
×
115
   }
116

117
   throw Invalid_State("auth_method_to_string unknown enum value");
×
118
}
119

120
Auth_Method auth_method_from_string(std::string_view str) {
3✔
121
   if(str == "RSA") {
3✔
122
      return Auth_Method::RSA;
1✔
123
   }
124
   if(str == "ECDSA") {
2✔
125
      return Auth_Method::ECDSA;
1✔
126
   }
127
   if(str == "IMPLICIT") {
1✔
128
      return Auth_Method::IMPLICIT;
1✔
129
   }
130
   if(str == "UNDEFINED") {
×
131
      return Auth_Method::UNDEFINED;
×
132
   }
133

134
   throw Invalid_Argument(fmt("Unknown TLS signature method '{}'", str));
×
135
}
136

137
std::optional<Group_Params> Group_Params::from_string(std::string_view group_name) {
447✔
138
   if(group_name == "secp256r1") {
522✔
139
      return Group_Params::SECP256R1;
68✔
140
   }
141
   if(group_name == "secp384r1") {
417✔
142
      return Group_Params::SECP384R1;
37✔
143
   }
144
   if(group_name == "secp521r1") {
342✔
145
      return Group_Params::SECP521R1;
38✔
146
   }
147
   if(group_name == "brainpool256r1") {
320✔
148
      return Group_Params::BRAINPOOL256R1;
18✔
149
   }
150
   if(group_name == "brainpool384r1") {
294✔
151
      return Group_Params::BRAINPOOL384R1;
8✔
152
   }
153
   if(group_name == "brainpool512r1") {
278✔
154
      return Group_Params::BRAINPOOL512R1;
8✔
155
   }
156
   if(group_name == "x25519") {
274✔
157
      return Group_Params::X25519;
77✔
158
   }
159

160
   if(group_name == "ffdhe/ietf/2048") {
288✔
161
      return Group_Params::FFDHE_2048;
56✔
162
   }
163
   if(group_name == "ffdhe/ietf/3072") {
208✔
164
      return Group_Params::FFDHE_3072;
24✔
165
   }
166
   if(group_name == "ffdhe/ietf/4096") {
157✔
167
      return Group_Params::FFDHE_4096;
27✔
168
   }
169
   if(group_name == "ffdhe/ietf/6144") {
108✔
170
      return Group_Params::FFDHE_6144;
22✔
171
   }
172
   if(group_name == "ffdhe/ietf/8192") {
64✔
173
      return Group_Params::FFDHE_8192;
22✔
174
   }
175

176
   if(group_name == "Kyber-512-r3") {
42✔
177
      return Group_Params::KYBER_512_R3_OQS;
19✔
178
   }
179
   if(group_name == "Kyber-768-r3") {
23✔
180
      return Group_Params::KYBER_768_R3_OQS;
×
181
   }
182
   if(group_name == "Kyber-1024-r3") {
23✔
183
      return Group_Params::KYBER_1024_R3_OQS;
×
184
   }
185

186
   if(group_name == "x25519/Kyber-512-r3/cloudflare") {
23✔
187
      return Group_Params::HYBRID_X25519_KYBER_512_R3_CLOUDFLARE;
×
188
   }
189

190
   if(group_name == "x25519/Kyber-512-r3") {
23✔
191
      return Group_Params::HYBRID_X25519_KYBER_512_R3_OQS;
19✔
192
   }
193
   if(group_name == "x25519/Kyber-768-r3") {
4✔
194
      return Group_Params::HYBRID_X25519_KYBER_768_R3_OQS;
×
195
   }
196

197
   if(group_name == "secp256r1/Kyber-512-r3") {
4✔
198
      return Group_Params::HYBRID_SECP256R1_KYBER_512_R3_OQS;
×
199
   }
200
   if(group_name == "secp256r1/Kyber-768-r3") {
4✔
201
      return Group_Params::HYBRID_SECP256R1_KYBER_768_R3_OQS;
×
202
   }
203
   if(group_name == "secp384r1/Kyber-768-r3") {
4✔
204
      return Group_Params::HYBRID_SECP384R1_KYBER_768_R3_OQS;
×
205
   }
206
   if(group_name == "secp521r1/Kyber-1024-r3") {
4✔
207
      return Group_Params::HYBRID_SECP521R1_KYBER_1024_R3_OQS;
×
208
   }
209

210
   return std::nullopt;
4✔
211
}
212

213
std::optional<std::string> Group_Params::to_string() const {
254✔
214
   switch(m_code) {
254✔
215
      case Group_Params::SECP256R1:
61✔
216
         return "secp256r1";
61✔
217
      case Group_Params::SECP384R1:
67✔
218
         return "secp384r1";
67✔
219
      case Group_Params::SECP521R1:
30✔
220
         return "secp521r1";
30✔
221
      case Group_Params::BRAINPOOL256R1:
16✔
222
         return "brainpool256r1";
16✔
223
      case Group_Params::BRAINPOOL384R1:
8✔
224
         return "brainpool384r1";
8✔
225
      case Group_Params::BRAINPOOL512R1:
10✔
226
         return "brainpool512r1";
10✔
227
      case Group_Params::X25519:
12✔
228
         return "x25519";
12✔
229

230
      case Group_Params::FFDHE_2048:
20✔
231
         return "ffdhe/ietf/2048";
20✔
232
      case Group_Params::FFDHE_3072:
8✔
233
         return "ffdhe/ietf/3072";
8✔
234
      case Group_Params::FFDHE_4096:
8✔
235
         return "ffdhe/ietf/4096";
8✔
236
      case Group_Params::FFDHE_6144:
6✔
237
         return "ffdhe/ietf/6144";
6✔
238
      case Group_Params::FFDHE_8192:
6✔
239
         return "ffdhe/ietf/8192";
6✔
240

241
      case Group_Params::KYBER_512_R3_OQS:
2✔
242
         return "Kyber-512-r3";
2✔
243
      case Group_Params::KYBER_768_R3_OQS:
×
244
         return "Kyber-768-r3";
×
245
      case Group_Params::KYBER_1024_R3_OQS:
×
246
         return "Kyber-1024-r3";
×
247

248
      case Group_Params::HYBRID_X25519_KYBER_512_R3_CLOUDFLARE:
×
249
         return "x25519/Kyber-512-r3/cloudflare";
×
250

251
      case Group_Params::HYBRID_X25519_KYBER_512_R3_OQS:
×
252
         return "x25519/Kyber-512-r3";
×
253
      case Group_Params::HYBRID_X25519_KYBER_768_R3_OQS:
×
254
         return "x25519/Kyber-768-r3";
×
255

256
      case Group_Params::HYBRID_SECP256R1_KYBER_512_R3_OQS:
×
257
         return "secp256r1/Kyber-512-r3";
×
258
      case Group_Params::HYBRID_SECP256R1_KYBER_768_R3_OQS:
×
259
         return "secp256r1/Kyber-768-r3";
×
260
      case Group_Params::HYBRID_SECP384R1_KYBER_768_R3_OQS:
×
261
         return "secp384r1/Kyber-768-r3";
×
262
      case Group_Params::HYBRID_SECP521R1_KYBER_1024_R3_OQS:
×
263
         return "secp521r1/Kyber-1024-r3";
×
264

265
      default:
×
266
         return std::nullopt;
×
267
   }
268
}
269

270
}  // namespace Botan::TLS
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc