Debian Codegraph @

crt/s2n/bindings/rust/extended/s2n-tls/src/enums.rs

raw symbols SCIP
1 // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 #![allow(clippy::missing_safety_doc)] // TODO add safety docs
5
6 use crate::error::Error;
7 use core::convert::TryFrom;
8 use s2n_tls_sys::*;
9
10 #[derive(Debug, PartialEq, Copy, Clone)]
11 pub enum CallbackResult {
12 Success,
13 Failure,
14 }
15
16 impl From<CallbackResult> for s2n_status_code::Type {
17 fn from(input: CallbackResult) -> s2n_status_code::Type {
18 match input {
19 CallbackResult::Success => s2n_status_code::SUCCESS,
20 CallbackResult::Failure => s2n_status_code::FAILURE,
21 }
22 }
23 }
24
25 impl<T, E> From<Result<T, E>> for CallbackResult {
26 fn from(result: Result<T, E>) -> CallbackResult {
27 match result {
28 Ok(_) => CallbackResult::Success,
29 Err(_) => CallbackResult::Failure,
30 }
31 }
32 }
33
34 /// Corresponds to [`s2n_fips_mode`].
35 #[non_exhaustive]
36 #[derive(Debug, PartialEq, Copy, Clone)]
37 pub enum FipsMode {
38 Disabled,
39 Enabled,
40 }
41
42 impl FipsMode {
43 pub fn is_enabled(&self) -> bool {
44 matches!(self, FipsMode::Enabled)
45 }
46 }
47
48 impl TryFrom<s2n_fips_mode::Type> for FipsMode {
49 type Error = Error;
50
51 fn try_from(input: s2n_fips_mode::Type) -> Result<Self, Self::Error> {
52 let mode = match input {
53 s2n_fips_mode::FIPS_MODE_DISABLED => FipsMode::Disabled,
54 s2n_fips_mode::FIPS_MODE_ENABLED => FipsMode::Enabled,
55 _ => return Err(Error::INVALID_INPUT),
56 };
57
58 Ok(mode)
59 }
60 }
61
62 /// Corresponds to [`s2n_mode`].
63 #[derive(Debug, PartialEq, Copy, Clone)]
64 pub enum Mode {
65 Server,
66 Client,
67 }
68
69 impl From<Mode> for s2n_mode::Type {
70 fn from(input: Mode) -> s2n_mode::Type {
71 match input {
72 Mode::Server => s2n_mode::SERVER,
73 Mode::Client => s2n_mode::CLIENT,
74 }
75 }
76 }
77
78 impl TryFrom<s2n_mode::Type> for Mode {
79 type Error = Error;
80
81 fn try_from(input: s2n_mode::Type) -> Result<Self, Self::Error> {
82 let mode = match input {
83 s2n_mode::SERVER => Mode::Server,
84 s2n_mode::CLIENT => Mode::Client,
85 _ => return Err(Error::INVALID_INPUT),
86 };
87 Ok(mode)
88 }
89 }
90
91 #[non_exhaustive]
92 #[derive(Debug, PartialEq, Copy, Clone)]
93 pub enum Version {
94 SSLV2,
95 SSLV3,
96 TLS10,
97 TLS11,
98 TLS12,
99 TLS13,
100 }
101
102 impl TryFrom<s2n_tls_version::Type> for Version {
103 type Error = Error;
104
105 fn try_from(input: s2n_tls_version::Type) -> Result<Self, Self::Error> {
106 let version = match input {
107 s2n_tls_version::SSLV2 => Self::SSLV2,
108 s2n_tls_version::SSLV3 => Self::SSLV3,
109 s2n_tls_version::TLS10 => Self::TLS10,
110 s2n_tls_version::TLS11 => Self::TLS11,
111 s2n_tls_version::TLS12 => Self::TLS12,
112 s2n_tls_version::TLS13 => Self::TLS13,
113 _ => return Err(Error::INVALID_INPUT),
114 };
115 Ok(version)
116 }
117 }
118
119 #[non_exhaustive]
120 #[derive(Debug, PartialEq, Copy, Clone)]
121 pub enum CertSNIMatch {
122 /// The client did not supply an SNI
123 NoSNI,
124 ExactMatch,
125 WildcardMatch,
126 NoMatch,
127 }
128
129 impl TryFrom<s2n_cert_sni_match::Type> for CertSNIMatch {
130 type Error = Error;
131 fn try_from(input: s2n_cert_sni_match::Type) -> Result<Self, Self::Error> {
132 let match_type = match input {
133 s2n_cert_sni_match::SNI_NONE => Self::NoSNI,
134 s2n_cert_sni_match::SNI_EXACT_MATCH => Self::ExactMatch,
135 s2n_cert_sni_match::SNI_WILDCARD_MATCH => Self::WildcardMatch,
136 s2n_cert_sni_match::SNI_NO_MATCH => Self::NoMatch,
137 _ => return Err(Error::INVALID_INPUT),
138 };
139 Ok(match_type)
140 }
141 }
142
143 #[non_exhaustive]
144 #[derive(Debug, PartialEq, Copy, Clone)]
145 /// Corresponds to [`s2n_blinding`].
146 pub enum Blinding {
147 SelfService,
148 BuiltIn,
149 }
150
151 impl From<Blinding> for s2n_blinding::Type {
152 fn from(input: Blinding) -> s2n_blinding::Type {
153 match input {
154 Blinding::SelfService => s2n_blinding::SELF_SERVICE_BLINDING,
155 Blinding::BuiltIn => s2n_blinding::BUILT_IN_BLINDING,
156 }
157 }
158 }
159
160 /// Corresponds to [`s2n_cert_auth_type`].
161 #[non_exhaustive]
162 #[derive(Debug, PartialEq, Copy, Clone)]
163 pub enum ClientAuthType {
164 Required,
165 Optional,
166 None,
167 }
168
169 impl From<ClientAuthType> for s2n_cert_auth_type::Type {
170 fn from(input: ClientAuthType) -> s2n_cert_auth_type::Type {
171 match input {
172 ClientAuthType::Required => s2n_cert_auth_type::REQUIRED,
173 ClientAuthType::Optional => s2n_cert_auth_type::OPTIONAL,
174 ClientAuthType::None => s2n_cert_auth_type::NONE,
175 }
176 }
177 }
178
179 /// Corresponds to [`s2n_alert_behavior`].
180 #[non_exhaustive]
181 #[derive(Debug, PartialEq, Copy, Clone)]
182 pub enum AlertBehavior {
183 FailOnWarnings,
184 IgnoreWarnings,
185 }
186
187 impl From<AlertBehavior> for s2n_alert_behavior::Type {
188 fn from(input: AlertBehavior) -> s2n_alert_behavior::Type {
189 match input {
190 AlertBehavior::FailOnWarnings => s2n_alert_behavior::FAIL_ON_WARNINGS,
191 AlertBehavior::IgnoreWarnings => s2n_alert_behavior::IGNORE_WARNINGS,
192 }
193 }
194 }
195
196 /// Corresponds to [`s2n_tls_signature_algorithm`].
197 #[non_exhaustive]
198 #[derive(Debug, PartialEq, Copy, Clone)]
199 #[allow(non_camel_case_types)]
200 pub enum SignatureAlgorithm {
201 RSA_PKCS1,
202 RSA_PSS_RSAE,
203 RSA_PSS_PSS,
204 ECDSA,
205 MLDSA,
206 }
207
208 impl TryFrom<s2n_tls_signature_algorithm::Type> for SignatureAlgorithm {
209 type Error = Error;
210
211 fn try_from(input: s2n_tls_signature_algorithm::Type) -> Result<Self, Self::Error> {
212 let version = match input {
213 s2n_tls_signature_algorithm::RSA => Self::RSA_PKCS1,
214 s2n_tls_signature_algorithm::RSA_PSS_RSAE => Self::RSA_PSS_RSAE,
215 s2n_tls_signature_algorithm::RSA_PSS_PSS => Self::RSA_PSS_PSS,
216 s2n_tls_signature_algorithm::ECDSA => Self::ECDSA,
217 s2n_tls_signature_algorithm::MLDSA => Self::MLDSA,
218 _ => return Err(Error::INVALID_INPUT),
219 };
220 Ok(version)
221 }
222 }
223
224 /// Corresponds to [`s2n_tls_hash_algorithm`].
225 #[non_exhaustive]
226 #[derive(Debug, PartialEq, Copy, Clone)]
227 #[allow(non_camel_case_types)]
228 pub enum HashAlgorithm {
229 MD5,
230 SHA1,
231 SHA224,
232 SHA256,
233 SHA384,
234 SHA512,
235 }
236
237 impl TryFrom<s2n_tls_hash_algorithm::Type> for HashAlgorithm {
238 type Error = Error;
239
240 fn try_from(input: s2n_tls_hash_algorithm::Type) -> Result<Self, Self::Error> {
241 let version = match input {
242 s2n_tls_hash_algorithm::MD5 => Self::MD5,
243 s2n_tls_hash_algorithm::SHA1 => Self::SHA1,
244 s2n_tls_hash_algorithm::SHA224 => Self::SHA224,
245 s2n_tls_hash_algorithm::SHA256 => Self::SHA256,
246 s2n_tls_hash_algorithm::SHA384 => Self::SHA384,
247 s2n_tls_hash_algorithm::SHA512 => Self::SHA512,
248 _ => return Err(Error::INVALID_INPUT),
249 };
250 Ok(version)
251 }
252 }
253
254 /// Corresponds to [`s2n_peer_key_update`].
255 #[non_exhaustive]
256 #[derive(Debug, PartialEq, Copy, Clone)]
257 pub enum PeerKeyUpdate {
258 KeyUpdateNotRequested,
259 KeyUpdatedRequested,
260 }
261
262 impl From<PeerKeyUpdate> for s2n_peer_key_update::Type {
263 fn from(input: PeerKeyUpdate) -> s2n_peer_key_update::Type {
264 match input {
265 PeerKeyUpdate::KeyUpdateNotRequested => s2n_peer_key_update::KEY_UPDATE_NOT_REQUESTED,
266 PeerKeyUpdate::KeyUpdatedRequested => s2n_peer_key_update::KEY_UPDATE_REQUESTED,
267 }
268 }
269 }
270
271 #[non_exhaustive]
272 #[derive(Debug)]
273 pub enum PskMode {
274 Resumption,
275 External,
276 }
277
278 impl From<PskMode> for s2n_psk_mode::Type {
279 fn from(input: PskMode) -> Self {
280 match input {
281 PskMode::Resumption => s2n_psk_mode::RESUMPTION,
282 PskMode::External => s2n_psk_mode::EXTERNAL,
283 }
284 }
285 }
286
287 #[non_exhaustive]
288 #[derive(Debug)]
289 pub enum PskHmac {
290 SHA256,
291 SHA384,
292 }
293
294 impl From<PskHmac> for s2n_psk_hmac::Type {
295 fn from(input: PskHmac) -> Self {
296 match input {
297 PskHmac::SHA256 => s2n_psk_hmac::SHA256,
298 PskHmac::SHA384 => s2n_psk_hmac::SHA384,
299 }
300 }
301 }
302
303 /// Corresponds to [`s2n_serialization_version`].
304 #[non_exhaustive]
305 #[derive(Debug, PartialEq, Copy, Clone)]
306 pub enum SerializationVersion {
307 None,
308 V1,
309 }
310
311 impl From<SerializationVersion> for s2n_serialization_version::Type {
312 fn from(input: SerializationVersion) -> s2n_serialization_version::Type {
313 match input {
314 SerializationVersion::None => s2n_serialization_version::SERIALIZED_CONN_NONE,
315 SerializationVersion::V1 => s2n_serialization_version::SERIALIZED_CONN_V1,
316 }
317 }
318 }