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    EnumName: HashAlgorithm;
12    EnumVal{
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    EnumName: ClientCertificateType;
29    EnumVal{
30        RSASign => 0x01,
31        DSSSign => 0x02,
32        RSAFixedDH => 0x03,
33        DSSFixedDH => 0x04,
34        RSAEphemeralDH => 0x05,
35        DSSEphemeralDH => 0x06,
36        FortezzaDMS => 0x14,
37        ECDSASign => 0x40,
38        RSAFixedECDH => 0x41,
39        ECDSAFixedECDH => 0x42
40    }
41}
42
43enum_builder! {
44    /// The `Compression` TLS protocol enum.  Values in this enum are taken
45    /// from the various RFCs covering TLS, and are listed by IANA.
46    /// The `Unknown` item is used when processing unrecognised ordinals.
47    @U8
48    EnumName: Compression;
49    EnumVal{
50        Null => 0x00,
51        Deflate => 0x01,
52        LSZ => 0x40
53    }
54}
55
56enum_builder! {
57    /// The `AlertLevel` TLS protocol enum.  Values in this enum are taken
58    /// from the various RFCs covering TLS, and are listed by IANA.
59    /// The `Unknown` item is used when processing unrecognised ordinals.
60    @U8
61    EnumName: AlertLevel;
62    EnumVal{
63        Warning => 0x01,
64        Fatal => 0x02
65    }
66}
67
68enum_builder! {
69    /// The `HeartbeatMessageType` TLS protocol enum.  Values in this enum are taken
70    /// from the various RFCs covering TLS, and are listed by IANA.
71    /// The `Unknown` item is used when processing unrecognised ordinals.
72    @U8
73    EnumName: HeartbeatMessageType;
74    EnumVal{
75        Request => 0x01,
76        Response => 0x02
77    }
78}
79
80enum_builder! {
81    /// The `ExtensionType` TLS protocol enum.  Values in this enum are taken
82    /// from the various RFCs covering TLS, and are listed by IANA.
83    /// The `Unknown` item is used when processing unrecognised ordinals.
84    @U16
85    EnumName: ExtensionType;
86    EnumVal{
87        ServerName => 0x0000,
88        MaxFragmentLength => 0x0001,
89        ClientCertificateUrl => 0x0002,
90        TrustedCAKeys => 0x0003,
91        TruncatedHMAC => 0x0004,
92        StatusRequest => 0x0005,
93        UserMapping => 0x0006,
94        ClientAuthz => 0x0007,
95        ServerAuthz => 0x0008,
96        CertificateType => 0x0009,
97        EllipticCurves => 0x000a,
98        ECPointFormats => 0x000b,
99        SRP => 0x000c,
100        SignatureAlgorithms => 0x000d,
101        UseSRTP => 0x000e,
102        Heartbeat => 0x000f,
103        ALProtocolNegotiation => 0x0010,
104        SCT => 0x0012,
105        Padding => 0x0015,
106        ExtendedMasterSecret => 0x0017,
107        SessionTicket => 0x0023,
108        PreSharedKey => 0x0029,
109        EarlyData => 0x002a,
110        SupportedVersions => 0x002b,
111        Cookie => 0x002c,
112        PSKKeyExchangeModes => 0x002d,
113        TicketEarlyDataInfo => 0x002e,
114        CertificateAuthorities => 0x002f,
115        OIDFilters => 0x0030,
116        PostHandshakeAuth => 0x0031,
117        SignatureAlgorithmsCert => 0x0032,
118        KeyShare => 0x0033,
119        TransportParameters => 0x0039,
120        NextProtocolNegotiation => 0x3374,
121        ChannelId => 0x754f,
122        RenegotiationInfo => 0xff01,
123        TransportParametersDraft => 0xffa5
124    }
125}
126
127enum_builder! {
128    /// The `ServerNameType` TLS protocol enum.  Values in this enum are taken
129    /// from the various RFCs covering TLS, and are listed by IANA.
130    /// The `Unknown` item is used when processing unrecognised ordinals.
131    @U8
132    EnumName: ServerNameType;
133    EnumVal{
134        HostName => 0x00
135    }
136}
137
138enum_builder! {
139    /// The `NamedCurve` TLS protocol enum.  Values in this enum are taken
140    /// from the various RFCs covering TLS, and are listed by IANA.
141    /// The `Unknown` item is used when processing unrecognised ordinals.
142    ///
143    /// This enum is used for recognizing elliptic curve parameters advertised
144    /// by a peer during a TLS handshake. It is **not** a list of curves that
145    /// Rustls supports. See [`crate::kx_group`] for the list of supported
146    /// elliptic curve groups.
147    @U16
148    EnumName: NamedCurve;
149    EnumVal{
150        sect163k1 => 0x0001,
151        sect163r1 => 0x0002,
152        sect163r2 => 0x0003,
153        sect193r1 => 0x0004,
154        sect193r2 => 0x0005,
155        sect233k1 => 0x0006,
156        sect233r1 => 0x0007,
157        sect239k1 => 0x0008,
158        sect283k1 => 0x0009,
159        sect283r1 => 0x000a,
160        sect409k1 => 0x000b,
161        sect409r1 => 0x000c,
162        sect571k1 => 0x000d,
163        sect571r1 => 0x000e,
164        secp160k1 => 0x000f,
165        secp160r1 => 0x0010,
166        secp160r2 => 0x0011,
167        secp192k1 => 0x0012,
168        secp192r1 => 0x0013,
169        secp224k1 => 0x0014,
170        secp224r1 => 0x0015,
171        secp256k1 => 0x0016,
172        secp256r1 => 0x0017,
173        secp384r1 => 0x0018,
174        secp521r1 => 0x0019,
175        brainpoolp256r1 => 0x001a,
176        brainpoolp384r1 => 0x001b,
177        brainpoolp512r1 => 0x001c,
178        X25519 => 0x001d,
179        X448 => 0x001e,
180        arbitrary_explicit_prime_curves => 0xff01,
181        arbitrary_explicit_char2_curves => 0xff02
182    }
183}
184
185enum_builder! {
186    /// The `NamedGroup` TLS protocol enum.  Values in this enum are taken
187    /// from the various RFCs covering TLS, and are listed by IANA.
188    /// The `Unknown` item is used when processing unrecognised ordinals.
189    @U16
190    EnumName: NamedGroup;
191    EnumVal{
192        secp256r1 => 0x0017,
193        secp384r1 => 0x0018,
194        secp521r1 => 0x0019,
195        X25519 => 0x001d,
196        X448 => 0x001e,
197        FFDHE2048 => 0x0100,
198        FFDHE3072 => 0x0101,
199        FFDHE4096 => 0x0102,
200        FFDHE6144 => 0x0103,
201        FFDHE8192 => 0x0104
202    }
203}
204
205enum_builder! {
206    /// The `ECPointFormat` TLS protocol enum.  Values in this enum are taken
207    /// from the various RFCs covering TLS, and are listed by IANA.
208    /// The `Unknown` item is used when processing unrecognised ordinals.
209    @U8
210    EnumName: ECPointFormat;
211    EnumVal{
212        Uncompressed => 0x00,
213        ANSIX962CompressedPrime => 0x01,
214        ANSIX962CompressedChar2 => 0x02
215    }
216}
217
218impl ECPointFormat {
219    pub const SUPPORTED: [Self; 1] = [Self::Uncompressed];
220}
221
222enum_builder! {
223    /// The `HeartbeatMode` TLS protocol enum.  Values in this enum are taken
224    /// from the various RFCs covering TLS, and are listed by IANA.
225    /// The `Unknown` item is used when processing unrecognised ordinals.
226    @U8
227    EnumName: HeartbeatMode;
228    EnumVal{
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    EnumName: ECCurveType;
240    EnumVal{
241        ExplicitPrime => 0x01,
242        ExplicitChar2 => 0x02,
243        NamedCurve => 0x03
244    }
245}
246
247enum_builder! {
248    /// The `PSKKeyExchangeMode` TLS protocol enum.  Values in this enum are taken
249    /// from the various RFCs covering TLS, and are listed by IANA.
250    /// The `Unknown` item is used when processing unrecognised ordinals.
251    @U8
252    EnumName: PSKKeyExchangeMode;
253    EnumVal{
254        PSK_KE => 0x00,
255        PSK_DHE_KE => 0x01
256    }
257}
258
259enum_builder! {
260    /// The `KeyUpdateRequest` TLS protocol enum.  Values in this enum are taken
261    /// from the various RFCs covering TLS, and are listed by IANA.
262    /// The `Unknown` item is used when processing unrecognised ordinals.
263    @U8
264    EnumName: KeyUpdateRequest;
265    EnumVal{
266        UpdateNotRequested => 0x00,
267        UpdateRequested => 0x01
268    }
269}
270
271enum_builder! {
272    /// The `CertificateStatusType` TLS protocol enum.  Values in this enum are taken
273    /// from the various RFCs covering TLS, and are listed by IANA.
274    /// The `Unknown` item is used when processing unrecognised ordinals.
275    @U8
276    EnumName: CertificateStatusType;
277    EnumVal{
278        OCSP => 0x01
279    }
280}
281
282#[cfg(test)]
283pub(crate) mod tests {
284    //! These tests are intended to provide coverage and
285    //! check panic-safety of relatively unused values.
286
287    use super::*;
288
289    #[test]
290    fn test_enums() {
291        test_enum8::<HashAlgorithm>(HashAlgorithm::NONE, HashAlgorithm::SHA512);
292        test_enum8::<ClientCertificateType>(
293            ClientCertificateType::RSASign,
294            ClientCertificateType::ECDSAFixedECDH,
295        );
296        test_enum8::<Compression>(Compression::Null, Compression::LSZ);
297        test_enum8::<AlertLevel>(AlertLevel::Warning, AlertLevel::Fatal);
298        test_enum8::<HeartbeatMessageType>(
299            HeartbeatMessageType::Request,
300            HeartbeatMessageType::Response,
301        );
302        test_enum16::<ExtensionType>(ExtensionType::ServerName, ExtensionType::RenegotiationInfo);
303        test_enum8::<ServerNameType>(ServerNameType::HostName, ServerNameType::HostName);
304        test_enum16::<NamedCurve>(
305            NamedCurve::sect163k1,
306            NamedCurve::arbitrary_explicit_char2_curves,
307        );
308        test_enum16::<NamedGroup>(NamedGroup::secp256r1, NamedGroup::FFDHE8192);
309        test_enum8::<ECPointFormat>(
310            ECPointFormat::Uncompressed,
311            ECPointFormat::ANSIX962CompressedChar2,
312        );
313        test_enum8::<HeartbeatMode>(
314            HeartbeatMode::PeerAllowedToSend,
315            HeartbeatMode::PeerNotAllowedToSend,
316        );
317        test_enum8::<ECCurveType>(ECCurveType::ExplicitPrime, ECCurveType::NamedCurve);
318        test_enum8::<PSKKeyExchangeMode>(
319            PSKKeyExchangeMode::PSK_KE,
320            PSKKeyExchangeMode::PSK_DHE_KE,
321        );
322        test_enum8::<KeyUpdateRequest>(
323            KeyUpdateRequest::UpdateNotRequested,
324            KeyUpdateRequest::UpdateRequested,
325        );
326        test_enum8::<CertificateStatusType>(
327            CertificateStatusType::OCSP,
328            CertificateStatusType::OCSP,
329        );
330    }
331
332    pub(crate) fn test_enum8<T: Codec>(first: T, last: T) {
333        let first_v = get8(&first);
334        let last_v = get8(&last);
335
336        for val in first_v..last_v + 1 {
337            let mut buf = Vec::new();
338            val.encode(&mut buf);
339            assert_eq!(buf.len(), 1);
340
341            let t = T::read_bytes(&buf).unwrap();
342            assert_eq!(val, get8(&t));
343        }
344    }
345
346    pub(crate) fn test_enum16<T: Codec>(first: T, last: T) {
347        let first_v = get16(&first);
348        let last_v = get16(&last);
349
350        for val in first_v..last_v + 1 {
351            let mut buf = Vec::new();
352            val.encode(&mut buf);
353            assert_eq!(buf.len(), 2);
354
355            let t = T::read_bytes(&buf).unwrap();
356            assert_eq!(val, get16(&t));
357        }
358    }
359
360    fn get8<T: Codec>(enum_value: &T) -> u8 {
361        let enc = enum_value.get_encoding();
362        assert_eq!(enc.len(), 1);
363        enc[0]
364    }
365
366    fn get16<T: Codec>(enum_value: &T) -> u16 {
367        let enc = enum_value.get_encoding();
368        assert_eq!(enc.len(), 2);
369        (enc[0] as u16 >> 8) | (enc[1] as u16)
370    }
371}