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