clia_rustls_mod/msgs/
enums.rs

1#![allow(clippy::upper_case_acronyms)]
2#![allow(non_camel_case_types)]
3/// This file is autogenerated.  See https://github.com/ctz/tls-hacking/
4use crate::crypto::KeyExchangeAlgorithm;
5use crate::msgs::codec::{Codec, Reader};
6
7enum_builder! {
8    /// The `HashAlgorithm` TLS protocol enum.  Values in this enum are taken
9    /// from the various RFCs covering TLS, and are listed by IANA.
10    /// The `Unknown` item is used when processing unrecognised ordinals.
11    @U8
12    pub enum HashAlgorithm {
13        NONE => 0x00,
14        MD5 => 0x01,
15        SHA1 => 0x02,
16        SHA224 => 0x03,
17        SHA256 => 0x04,
18        SHA384 => 0x05,
19        SHA512 => 0x06,
20    }
21}
22
23enum_builder! {
24    /// The `ClientCertificateType` TLS protocol enum.  Values in this enum are taken
25    /// from the various RFCs covering TLS, and are listed by IANA.
26    /// The `Unknown` item is used when processing unrecognised ordinals.
27    @U8
28    pub(crate) enum ClientCertificateType {
29        RSASign => 0x01,
30        DSSSign => 0x02,
31        RSAFixedDH => 0x03,
32        DSSFixedDH => 0x04,
33        RSAEphemeralDH => 0x05,
34        DSSEphemeralDH => 0x06,
35        FortezzaDMS => 0x14,
36        ECDSASign => 0x40,
37        RSAFixedECDH => 0x41,
38        ECDSAFixedECDH => 0x42,
39    }
40}
41
42enum_builder! {
43    /// The `Compression` TLS protocol enum.  Values in this enum are taken
44    /// from the various RFCs covering TLS, and are listed by IANA.
45    /// The `Unknown` item is used when processing unrecognised ordinals.
46    @U8
47    pub enum Compression {
48        Null => 0x00,
49        Deflate => 0x01,
50        LSZ => 0x40,
51    }
52}
53
54enum_builder! {
55    /// The `AlertLevel` TLS protocol enum.  Values in this enum are taken
56    /// from the various RFCs covering TLS, and are listed by IANA.
57    /// The `Unknown` item is used when processing unrecognised ordinals.
58    @U8
59    pub enum AlertLevel {
60        Warning => 0x01,
61        Fatal => 0x02,
62    }
63}
64
65enum_builder! {
66    /// The `HeartbeatMessageType` TLS protocol enum.  Values in this enum are taken
67    /// from the various RFCs covering TLS, and are listed by IANA.
68    /// The `Unknown` item is used when processing unrecognised ordinals.
69    @U8
70    pub(crate) enum HeartbeatMessageType {
71        Request => 0x01,
72        Response => 0x02,
73    }
74}
75
76enum_builder! {
77    /// The `ExtensionType` TLS protocol enum.  Values in this enum are taken
78    /// from the various RFCs covering TLS, and are listed by IANA.
79    /// The `Unknown` item is used when processing unrecognised ordinals.
80    @U16
81    pub(crate) enum ExtensionType {
82        ServerName => 0x0000,
83        MaxFragmentLength => 0x0001,
84        ClientCertificateUrl => 0x0002,
85        TrustedCAKeys => 0x0003,
86        TruncatedHMAC => 0x0004,
87        StatusRequest => 0x0005,
88        UserMapping => 0x0006,
89        ClientAuthz => 0x0007,
90        ServerAuthz => 0x0008,
91        CertificateType => 0x0009,
92        EllipticCurves => 0x000a,
93        ECPointFormats => 0x000b,
94        SRP => 0x000c,
95        SignatureAlgorithms => 0x000d,
96        UseSRTP => 0x000e,
97        Heartbeat => 0x000f,
98        ALProtocolNegotiation => 0x0010,
99        SCT => 0x0012,
100        Padding => 0x0015,
101        ExtendedMasterSecret => 0x0017,
102        SessionTicket => 0x0023,
103        PreSharedKey => 0x0029,
104        EarlyData => 0x002a,
105        SupportedVersions => 0x002b,
106        Cookie => 0x002c,
107        PSKKeyExchangeModes => 0x002d,
108        TicketEarlyDataInfo => 0x002e,
109        CertificateAuthorities => 0x002f,
110        OIDFilters => 0x0030,
111        PostHandshakeAuth => 0x0031,
112        SignatureAlgorithmsCert => 0x0032,
113        KeyShare => 0x0033,
114        TransportParameters => 0x0039,
115        NextProtocolNegotiation => 0x3374,
116        ChannelId => 0x754f,
117        RenegotiationInfo => 0xff01,
118        TransportParametersDraft => 0xffa5,
119    }
120}
121
122enum_builder! {
123    /// The `ServerNameType` TLS protocol enum.  Values in this enum are taken
124    /// from the various RFCs covering TLS, and are listed by IANA.
125    /// The `Unknown` item is used when processing unrecognised ordinals.
126    @U8
127    pub(crate) enum ServerNameType {
128        HostName => 0x00,
129    }
130}
131
132enum_builder! {
133    /// The `NamedCurve` TLS protocol enum.  Values in this enum are taken
134    /// from the various RFCs covering TLS, and are listed by IANA.
135    /// The `Unknown` item is used when processing unrecognised ordinals.
136    ///
137    /// This enum is used for recognizing elliptic curve parameters advertised
138    /// by a peer during a TLS handshake. It is **not** a list of curves that
139    /// Rustls supports. See [`crate::crypto::ring::kx_group`] for the list of supported
140    /// elliptic curve groups.
141    @U16
142    pub(crate) enum NamedCurve {
143        sect163k1 => 0x0001,
144        sect163r1 => 0x0002,
145        sect163r2 => 0x0003,
146        sect193r1 => 0x0004,
147        sect193r2 => 0x0005,
148        sect233k1 => 0x0006,
149        sect233r1 => 0x0007,
150        sect239k1 => 0x0008,
151        sect283k1 => 0x0009,
152        sect283r1 => 0x000a,
153        sect409k1 => 0x000b,
154        sect409r1 => 0x000c,
155        sect571k1 => 0x000d,
156        sect571r1 => 0x000e,
157        secp160k1 => 0x000f,
158        secp160r1 => 0x0010,
159        secp160r2 => 0x0011,
160        secp192k1 => 0x0012,
161        secp192r1 => 0x0013,
162        secp224k1 => 0x0014,
163        secp224r1 => 0x0015,
164        secp256k1 => 0x0016,
165        secp256r1 => 0x0017,
166        secp384r1 => 0x0018,
167        secp521r1 => 0x0019,
168        brainpoolp256r1 => 0x001a,
169        brainpoolp384r1 => 0x001b,
170        brainpoolp512r1 => 0x001c,
171        X25519 => 0x001d,
172        X448 => 0x001e,
173        arbitrary_explicit_prime_curves => 0xff01,
174        arbitrary_explicit_char2_curves => 0xff02,
175    }
176}
177
178enum_builder! {
179    /// The `NamedGroup` TLS protocol enum.  Values in this enum are taken
180    /// from the various RFCs covering TLS, and are listed by IANA.
181    /// The `Unknown` item is used when processing unrecognised ordinals.
182    @U16
183    pub enum NamedGroup {
184        secp256r1 => 0x0017,
185        secp384r1 => 0x0018,
186        secp521r1 => 0x0019,
187        X25519 => 0x001d,
188        X448 => 0x001e,
189        FFDHE2048 => 0x0100,
190        FFDHE3072 => 0x0101,
191        FFDHE4096 => 0x0102,
192        FFDHE6144 => 0x0103,
193        FFDHE8192 => 0x0104,
194    }
195}
196
197impl NamedGroup {
198    /// Return the key exchange algorithm associated with this `NamedGroup`
199    pub fn key_exchange_algorithm(self) -> KeyExchangeAlgorithm {
200        match u16::from(self) {
201            x if (0x100..0x200).contains(&x) => KeyExchangeAlgorithm::DHE,
202            _ => KeyExchangeAlgorithm::ECDHE,
203        }
204    }
205}
206
207enum_builder! {
208    /// The `ECPointFormat` TLS protocol enum.  Values in this enum are taken
209    /// from the various RFCs covering TLS, and are listed by IANA.
210    /// The `Unknown` item is used when processing unrecognised ordinals.
211    @U8
212    pub enum ECPointFormat {
213        Uncompressed => 0x00,
214        ANSIX962CompressedPrime => 0x01,
215        ANSIX962CompressedChar2 => 0x02,
216    }
217}
218
219impl ECPointFormat {
220    pub(crate) const SUPPORTED: [Self; 1] = [Self::Uncompressed];
221}
222
223enum_builder! {
224    /// The `HeartbeatMode` TLS protocol enum.  Values in this enum are taken
225    /// from the various RFCs covering TLS, and are listed by IANA.
226    /// The `Unknown` item is used when processing unrecognised ordinals.
227    @U8
228    pub(crate) enum HeartbeatMode {
229        PeerAllowedToSend => 0x01,
230        PeerNotAllowedToSend => 0x02,
231    }
232}
233
234enum_builder! {
235    /// The `ECCurveType` TLS protocol enum.  Values in this enum are taken
236    /// from the various RFCs covering TLS, and are listed by IANA.
237    /// The `Unknown` item is used when processing unrecognised ordinals.
238    @U8
239    pub(crate) enum ECCurveType {
240        ExplicitPrime => 0x01,
241        ExplicitChar2 => 0x02,
242        NamedCurve => 0x03,
243    }
244}
245
246enum_builder! {
247    /// The `PSKKeyExchangeMode` TLS protocol enum.  Values in this enum are taken
248    /// from the various RFCs covering TLS, and are listed by IANA.
249    /// The `Unknown` item is used when processing unrecognised ordinals.
250    @U8
251    pub enum PSKKeyExchangeMode {
252        PSK_KE => 0x00,
253        PSK_DHE_KE => 0x01,
254    }
255}
256
257enum_builder! {
258    /// The `KeyUpdateRequest` TLS protocol enum.  Values in this enum are taken
259    /// from the various RFCs covering TLS, and are listed by IANA.
260    /// The `Unknown` item is used when processing unrecognised ordinals.
261    @U8
262    pub enum KeyUpdateRequest {
263        UpdateNotRequested => 0x00,
264        UpdateRequested => 0x01,
265    }
266}
267
268enum_builder! {
269    /// The `CertificateStatusType` TLS protocol enum.  Values in this enum are taken
270    /// from the various RFCs covering TLS, and are listed by IANA.
271    /// The `Unknown` item is used when processing unrecognised ordinals.
272    @U8
273    pub enum CertificateStatusType {
274        OCSP => 0x01,
275    }
276}
277
278enum_builder! {
279    /// The Key Encapsulation Mechanism (`Kem`) type for HPKE operations.
280    /// Listed by IANA, as specified in [RFC 9180 Section 7.1]
281    ///
282    /// [RFC 9180 Section 7.1]: <https://datatracker.ietf.org/doc/html/rfc9180#kemid-values>
283    @U16
284    pub enum HpkeKem {
285        DHKEM_P256_HKDF_SHA256 => 0x0010,
286        DHKEM_P384_HKDF_SHA384 => 0x0011,
287        DHKEM_P521_HKDF_SHA512 => 0x0012,
288        DHKEM_X25519_HKDF_SHA256 => 0x0020,
289        DHKEM_X448_HKDF_SHA512 => 0x0021,
290    }
291}
292
293enum_builder! {
294    /// The Key Derivation Function (`Kdf`) type for HPKE operations.
295    /// Listed by IANA, as specified in [RFC 9180 Section 7.2]
296    ///
297    /// [RFC 9180 Section 7.2]: <https://datatracker.ietf.org/doc/html/rfc9180#name-key-derivation-functions-kd>
298    @U16
299    pub enum HpkeKdf {
300        HKDF_SHA256 => 0x0001,
301        HKDF_SHA384 => 0x0002,
302        HKDF_SHA512 => 0x0003,
303    }
304}
305
306impl Default for HpkeKdf {
307    // TODO(XXX): revisit the default configuration. This is just what Cloudflare ships right now.
308    fn default() -> Self {
309        Self::HKDF_SHA256
310    }
311}
312
313enum_builder! {
314    /// The Authenticated Encryption with Associated Data (`Aead`) type for HPKE operations.
315    /// Listed by IANA, as specified in [RFC 9180 Section 7.3]
316    ///
317    /// [RFC 9180 Section 7.3]: <https://datatracker.ietf.org/doc/html/rfc9180#name-authenticated-encryption-wi>
318    @U16
319    pub enum HpkeAead {
320        AES_128_GCM => 0x0001,
321        AES_256_GCM => 0x0002,
322        CHACHA20_POLY_1305 => 0x0003,
323        EXPORT_ONLY => 0xFFFF,
324    }
325}
326
327impl Default for HpkeAead {
328    // TODO(XXX): revisit the default configuration. This is just what Cloudflare ships right now.
329    fn default() -> Self {
330        Self::AES_128_GCM
331    }
332}
333
334enum_builder! {
335    /// The Encrypted Client Hello protocol version (`EchVersion`).
336    ///
337    /// Specified in [draft-ietf-tls-esni Section 4].
338    /// TODO(XXX): Update reference once RFC is published.
339    ///
340    /// [draft-ietf-tls-esni Section 4]: <https://www.ietf.org/archive/id/draft-ietf-tls-esni-17.html#section-4>
341    @U16
342    pub enum EchVersion {
343        V14 => 0xfe0d,
344    }
345}
346
347#[cfg(test)]
348pub(crate) mod tests {
349    // These tests are intended to provide coverage and
350    // check panic-safety of relatively unused values.
351
352    use std::prelude::v1::*;
353
354    use super::*;
355
356    #[test]
357    fn test_enums() {
358        test_enum8::<HashAlgorithm>(HashAlgorithm::NONE, HashAlgorithm::SHA512);
359        test_enum8::<ClientCertificateType>(
360            ClientCertificateType::RSASign,
361            ClientCertificateType::ECDSAFixedECDH,
362        );
363        test_enum8::<Compression>(Compression::Null, Compression::LSZ);
364        test_enum8::<AlertLevel>(AlertLevel::Warning, AlertLevel::Fatal);
365        test_enum8::<HeartbeatMessageType>(
366            HeartbeatMessageType::Request,
367            HeartbeatMessageType::Response,
368        );
369        test_enum16::<ExtensionType>(ExtensionType::ServerName, ExtensionType::RenegotiationInfo);
370        test_enum8::<ServerNameType>(ServerNameType::HostName, ServerNameType::HostName);
371        test_enum16::<NamedCurve>(
372            NamedCurve::sect163k1,
373            NamedCurve::arbitrary_explicit_char2_curves,
374        );
375        test_enum16::<NamedGroup>(NamedGroup::secp256r1, NamedGroup::FFDHE8192);
376        test_enum8::<ECPointFormat>(
377            ECPointFormat::Uncompressed,
378            ECPointFormat::ANSIX962CompressedChar2,
379        );
380        test_enum8::<HeartbeatMode>(
381            HeartbeatMode::PeerAllowedToSend,
382            HeartbeatMode::PeerNotAllowedToSend,
383        );
384        test_enum8::<ECCurveType>(ECCurveType::ExplicitPrime, ECCurveType::NamedCurve);
385        test_enum8::<PSKKeyExchangeMode>(
386            PSKKeyExchangeMode::PSK_KE,
387            PSKKeyExchangeMode::PSK_DHE_KE,
388        );
389        test_enum8::<KeyUpdateRequest>(
390            KeyUpdateRequest::UpdateNotRequested,
391            KeyUpdateRequest::UpdateRequested,
392        );
393        test_enum8::<CertificateStatusType>(
394            CertificateStatusType::OCSP,
395            CertificateStatusType::OCSP,
396        );
397    }
398
399    pub(crate) fn test_enum8<T: for<'a> Codec<'a>>(first: T, last: T) {
400        let first_v = get8(&first);
401        let last_v = get8(&last);
402
403        for val in first_v..last_v + 1 {
404            let mut buf = Vec::new();
405            val.encode(&mut buf);
406            assert_eq!(buf.len(), 1);
407
408            let t = T::read_bytes(&buf).unwrap();
409            assert_eq!(val, get8(&t));
410        }
411    }
412
413    pub(crate) fn test_enum16<T: for<'a> Codec<'a>>(first: T, last: T) {
414        let first_v = get16(&first);
415        let last_v = get16(&last);
416
417        for val in first_v..last_v + 1 {
418            let mut buf = Vec::new();
419            val.encode(&mut buf);
420            assert_eq!(buf.len(), 2);
421
422            let t = T::read_bytes(&buf).unwrap();
423            assert_eq!(val, get16(&t));
424        }
425    }
426
427    fn get8<T: for<'a> Codec<'a>>(enum_value: &T) -> u8 {
428        let enc = enum_value.get_encoding();
429        assert_eq!(enc.len(), 1);
430        enc[0]
431    }
432
433    fn get16<T: for<'a> Codec<'a>>(enum_value: &T) -> u16 {
434        let enc = enum_value.get_encoding();
435        assert_eq!(enc.len(), 2);
436        (enc[0] as u16 >> 8) | (enc[1] as u16)
437    }
438}