1macro_rules! wire_type {
4 ($name:ident, $raw:ty, $grease:expr) => {
5 #[doc = concat!("A raw TLS ", stringify!($name), " value.")]
6 #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
7 pub struct $name($raw);
8 impl $name {
9 #[inline]
11 pub const fn new(raw: $raw) -> Self {
12 Self(raw)
13 }
14 #[inline]
16 pub const fn raw(self) -> $raw {
17 self.0
18 }
19 #[inline]
21 pub const fn is_grease(self) -> bool {
22 $grease(self.0)
23 }
24 }
25 };
26}
27
28const fn grease_u16(value: u16) -> bool {
29 let high = (value >> 8) as u8;
30 let low = value as u8;
31 high == low && high & 0x0f == 0x0a
32}
33const fn grease_u8(value: u8) -> bool {
34 matches!(value, 0x0b | 0x2a | 0x49 | 0x68 | 0x87 | 0xa6 | 0xc5 | 0xe4)
35}
36
37const fn never_u8(_: u8) -> bool {
38 false
39}
40
41const fn never_u16(_: u16) -> bool {
42 false
43}
44
45wire_type!(TlsContentType, u8, never_u8);
46wire_type!(TlsProtocolVersion, u16, grease_u16);
47wire_type!(TlsHandshakeType, u8, never_u8);
48wire_type!(TlsCipherSuite, u16, grease_u16);
49wire_type!(TlsCompressionMethod, u8, never_u8);
50wire_type!(TlsExtensionType, u16, grease_u16);
51wire_type!(TlsNamedGroup, u16, grease_u16);
52wire_type!(TlsSignatureScheme, u16, grease_u16);
53wire_type!(TlsPskKeyExchangeMode, u8, grease_u8);
54wire_type!(TlsServerNameType, u8, never_u8);
55wire_type!(TlsCertificateCompressionAlgorithm, u16, never_u16);
56
57impl TlsContentType {
58 pub const CHANGE_CIPHER_SPEC: Self = Self(20);
60 pub const ALERT: Self = Self(21);
62 pub const HANDSHAKE: Self = Self(22);
64 pub const APPLICATION_DATA: Self = Self(23);
66}
67impl TlsProtocolVersion {
68 pub const TLS12: Self = Self(0x0303);
70 pub const TLS13: Self = Self(0x0304);
72}
73impl TlsHandshakeType {
74 pub const CLIENT_HELLO: Self = Self(1);
76 pub const SERVER_HELLO: Self = Self(2);
78}
79impl TlsExtensionType {
80 pub const SERVER_NAME: Self = Self(0);
82 pub const SUPPORTED_GROUPS: Self = Self(10);
84 pub const EC_POINT_FORMATS: Self = Self(11);
86 pub const SIGNATURE_ALGORITHMS: Self = Self(13);
88 pub const APPLICATION_LAYER_PROTOCOL_NEGOTIATION: Self = Self(16);
90 pub const COMPRESS_CERTIFICATE: Self = Self(27);
92 pub const PRE_SHARED_KEY: Self = Self(41);
94 pub const EARLY_DATA: Self = Self(42);
96 pub const COOKIE: Self = Self(44);
98 pub const SIGNATURE_ALGORITHMS_CERT: Self = Self(50);
100 pub const SUPPORTED_VERSIONS: Self = Self(43);
102 pub const PSK_KEY_EXCHANGE_MODES: Self = Self(45);
104 pub const KEY_SHARE: Self = Self(51);
106 pub const QUIC_TRANSPORT_PARAMETERS: Self = Self(0x0039);
108}
109
110impl TlsCipherSuite {
111 pub const TLS_AES_128_GCM_SHA256: Self = Self(0x1301);
113 pub const TLS_AES_256_GCM_SHA384: Self = Self(0x1302);
115 pub const TLS_CHACHA20_POLY1305_SHA256: Self = Self(0x1303);
117}
118
119impl TlsCompressionMethod {
120 pub const NULL: Self = Self(0);
122}
123
124impl TlsNamedGroup {
125 pub const SECP256R1: Self = Self(23);
127 pub const SECP384R1: Self = Self(24);
129 pub const X25519: Self = Self(29);
131}
132
133impl TlsSignatureScheme {
134 pub const RSA_PSS_RSAE_SHA256: Self = Self(0x0804);
136 pub const ECDSA_SECP256R1_SHA256: Self = Self(0x0403);
138 pub const ED25519: Self = Self(0x0807);
140}
141
142impl TlsPskKeyExchangeMode {
143 pub const PSK_KE: Self = Self(0);
145 pub const PSK_DHE_KE: Self = Self(1);
147}
148
149impl TlsServerNameType {
150 pub const HOST_NAME: Self = Self(0);
152}
153
154impl TlsCertificateCompressionAlgorithm {
155 pub const ZLIB: Self = Self(1);
157 pub const BROTLI: Self = Self(2);
159 pub const ZSTD: Self = Self(3);
161}