rustls/
enums.rs

1#![expect(missing_docs)]
2
3enum_builder! {
4    /// The `HandshakeType` TLS protocol enum.  Values in this enum are taken
5    /// from the various RFCs covering TLS, and are listed by IANA.
6    /// The `Unknown` item is used when processing unrecognized ordinals.
7    #[repr(u8)]
8    pub enum HandshakeType {
9        HelloRequest => 0x00,
10        ClientHello => 0x01,
11        ServerHello => 0x02,
12        HelloVerifyRequest => 0x03,
13        NewSessionTicket => 0x04,
14        EndOfEarlyData => 0x05,
15        HelloRetryRequest => 0x06,
16        EncryptedExtensions => 0x08,
17        Certificate => 0x0b,
18        ServerKeyExchange => 0x0c,
19        CertificateRequest => 0x0d,
20        ServerHelloDone => 0x0e,
21        CertificateVerify => 0x0f,
22        ClientKeyExchange => 0x10,
23        Finished => 0x14,
24        CertificateURL => 0x15,
25        CertificateStatus => 0x16,
26        KeyUpdate => 0x18,
27        CompressedCertificate => 0x19,
28        MessageHash => 0xfe,
29    }
30}
31
32enum_builder! {
33    /// The `ContentType` TLS protocol enum.  Values in this enum are taken
34    /// from the various RFCs covering TLS, and are listed by IANA.
35    /// The `Unknown` item is used when processing unrecognized ordinals.
36    #[repr(u8)]
37    pub enum ContentType {
38        ChangeCipherSpec => 0x14,
39        Alert => 0x15,
40        Handshake => 0x16,
41        ApplicationData => 0x17,
42        Heartbeat => 0x18,
43    }
44}
45
46enum_builder! {
47    /// The `ProtocolVersion` TLS protocol enum.  Values in this enum are taken
48    /// from the various RFCs covering TLS, and are listed by IANA.
49    /// The `Unknown` item is used when processing unrecognized ordinals.
50    #[repr(u16)]
51    pub enum ProtocolVersion {
52        SSLv2 => 0x0002,
53        SSLv3 => 0x0300,
54        TLSv1_0 => 0x0301,
55        TLSv1_1 => 0x0302,
56        TLSv1_2 => 0x0303,
57        TLSv1_3 => 0x0304,
58        DTLSv1_0 => 0xFEFF,
59        DTLSv1_2 => 0xFEFD,
60        DTLSv1_3 => 0xFEFC,
61    }
62}
63
64enum_builder! {
65    /// The "TLS Certificate Compression Algorithm IDs" TLS protocol enum.
66    /// Values in this enum are taken from [RFC8879].
67    ///
68    /// [RFC8879]: https://www.rfc-editor.org/rfc/rfc8879.html#section-7.3
69    #[repr(u16)]
70    pub enum CertificateCompressionAlgorithm {
71        Zlib => 1,
72        Brotli => 2,
73        Zstd => 3,
74    }
75}
76
77enum_builder! {
78    /// The `CertificateType` enum sent in the cert_type extensions.
79    /// Values in this enum are taken from the various RFCs covering TLS, and are listed by IANA.
80    ///
81    /// [RFC 6091 Section 5]: <https://datatracker.ietf.org/doc/html/rfc6091#section-5>
82    /// [RFC 7250 Section 7]: <https://datatracker.ietf.org/doc/html/rfc7250#section-7>
83    #[repr(u8)]
84    #[derive(Default)]
85    pub enum CertificateType {
86        #[default]
87        X509 => 0x00,
88        RawPublicKey => 0x02,
89    }
90}
91
92enum_builder! {
93    /// The type of Encrypted Client Hello (`EchClientHelloType`).
94    ///
95    /// Specified in [draft-ietf-tls-esni Section 5].
96    ///
97    /// [draft-ietf-tls-esni Section 5]: <https://www.ietf.org/archive/id/draft-ietf-tls-esni-18.html#section-5>
98    #[repr(u8)]
99    pub enum EchClientHelloType {
100        ClientHelloOuter => 0,
101        ClientHelloInner => 1
102    }
103}
104
105#[cfg(test)]
106mod tests {
107    use super::*;
108    use crate::msgs::enums::tests::{test_enum8, test_enum16};
109
110    #[test]
111    fn test_enums() {
112        test_enum8::<ContentType>(ContentType::ChangeCipherSpec, ContentType::Heartbeat);
113        test_enum8::<HandshakeType>(HandshakeType::HelloRequest, HandshakeType::MessageHash);
114        test_enum16::<CertificateCompressionAlgorithm>(
115            CertificateCompressionAlgorithm::Zlib,
116            CertificateCompressionAlgorithm::Zstd,
117        );
118        test_enum8::<CertificateType>(CertificateType::X509, CertificateType::RawPublicKey);
119    }
120}