/rust/registry/src/index.crates.io-1949cf8c6b5b557f/rustls-0.23.36/src/msgs/macros.rs
Line | Count | Source |
1 | | /// A macro which defines an enum type. |
2 | | macro_rules! enum_builder { |
3 | | ( |
4 | | $(#[doc = $comment:literal])* |
5 | | #[repr($uint:ty)] |
6 | | $(#[$metas:meta])* |
7 | | $enum_vis:vis enum $enum_name:ident |
8 | | { |
9 | | $( |
10 | | $(#[$enum_metas:meta])* |
11 | | $enum_var:ident => $enum_val:literal),* $(,)? |
12 | | $( !Debug: |
13 | | $( |
14 | | $(#[$enum_metas_nd:meta])* |
15 | | $enum_var_nd:ident => $enum_val_nd:literal |
16 | | ),* $(,)? |
17 | | )? |
18 | | } |
19 | | ) => { |
20 | | $(#[doc = $comment])* |
21 | | $(#[$metas])* |
22 | | #[non_exhaustive] |
23 | | #[derive(PartialEq, Eq, Clone, Copy)] |
24 | | $enum_vis enum $enum_name { |
25 | | $( |
26 | | $(#[$enum_metas])* |
27 | | $enum_var |
28 | | ),* |
29 | | $( |
30 | | , |
31 | | $( |
32 | | $(#[$enum_metas_nd])* |
33 | | $enum_var_nd |
34 | | ),* |
35 | | )? |
36 | | ,Unknown($uint) |
37 | | } |
38 | | |
39 | | impl $enum_name { |
40 | | // NOTE(allow) generated irrespective if there are callers |
41 | | #[allow(dead_code)] |
42 | 0 | $enum_vis fn to_array(self) -> [u8; core::mem::size_of::<$uint>()] { |
43 | 0 | <$uint>::from(self).to_be_bytes() |
44 | 0 | } Unexecuted instantiation: <rustls::enums::CertificateCompressionAlgorithm>::to_array Unexecuted instantiation: <rustls::enums::CertificateType>::to_array Unexecuted instantiation: <rustls::enums::EchClientHelloType>::to_array Unexecuted instantiation: <rustls::enums::HandshakeType>::to_array Unexecuted instantiation: <rustls::enums::CipherSuite>::to_array Unexecuted instantiation: <rustls::enums::SignatureScheme>::to_array Unexecuted instantiation: <rustls::enums::SignatureAlgorithm>::to_array Unexecuted instantiation: <rustls::enums::AlertDescription>::to_array Unexecuted instantiation: <rustls::enums::ContentType>::to_array Unexecuted instantiation: <rustls::enums::ProtocolVersion>::to_array Unexecuted instantiation: <rustls::msgs::enums::PskKeyExchangeMode>::to_array Unexecuted instantiation: <rustls::msgs::enums::NamedGroup>::to_array Unexecuted instantiation: <rustls::msgs::enums::ECPointFormat>::to_array Unexecuted instantiation: <rustls::msgs::enums::KeyUpdateRequest>::to_array Unexecuted instantiation: <rustls::msgs::enums::HpkeKdf>::to_array Unexecuted instantiation: <rustls::msgs::enums::HpkeAead>::to_array Unexecuted instantiation: <rustls::msgs::enums::EchVersion>::to_array Unexecuted instantiation: <rustls::msgs::enums::HashAlgorithm>::to_array Unexecuted instantiation: <rustls::msgs::enums::CertificateStatusType>::to_array Unexecuted instantiation: <rustls::msgs::enums::HpkeKem>::to_array Unexecuted instantiation: <rustls::msgs::enums::ExtensionType>::to_array Unexecuted instantiation: <rustls::msgs::enums::Compression>::to_array Unexecuted instantiation: <rustls::msgs::enums::AlertLevel>::to_array Unexecuted instantiation: <rustls::msgs::enums::ServerNameType>::to_array Unexecuted instantiation: <rustls::msgs::enums::HeartbeatMode>::to_array Unexecuted instantiation: <rustls::msgs::enums::ECCurveType>::to_array Unexecuted instantiation: <rustls::msgs::enums::NamedCurve>::to_array Unexecuted instantiation: <rustls::msgs::enums::HeartbeatMessageType>::to_array Unexecuted instantiation: <rustls::msgs::enums::ClientCertificateType>::to_array |
45 | | |
46 | | // NOTE(allow) generated irrespective if there are callers |
47 | | #[allow(dead_code)] |
48 | 0 | $enum_vis fn as_str(&self) -> Option<&'static str> { |
49 | 0 | match self { |
50 | 0 | $( $enum_name::$enum_var => Some(stringify!($enum_var))),* |
51 | 0 | $(, $( $enum_name::$enum_var_nd => Some(stringify!($enum_var_nd))),* )? |
52 | 0 | ,$enum_name::Unknown(_) => None, |
53 | | } |
54 | 0 | } Unexecuted instantiation: <rustls::enums::CertificateCompressionAlgorithm>::as_str Unexecuted instantiation: <rustls::enums::CertificateType>::as_str Unexecuted instantiation: <rustls::enums::EchClientHelloType>::as_str Unexecuted instantiation: <rustls::enums::HandshakeType>::as_str Unexecuted instantiation: <rustls::enums::CipherSuite>::as_str Unexecuted instantiation: <rustls::enums::SignatureScheme>::as_str Unexecuted instantiation: <rustls::enums::SignatureAlgorithm>::as_str Unexecuted instantiation: <rustls::enums::AlertDescription>::as_str Unexecuted instantiation: <rustls::enums::ContentType>::as_str Unexecuted instantiation: <rustls::enums::ProtocolVersion>::as_str Unexecuted instantiation: <rustls::msgs::enums::PskKeyExchangeMode>::as_str Unexecuted instantiation: <rustls::msgs::enums::NamedGroup>::as_str Unexecuted instantiation: <rustls::msgs::enums::ECPointFormat>::as_str Unexecuted instantiation: <rustls::msgs::enums::KeyUpdateRequest>::as_str Unexecuted instantiation: <rustls::msgs::enums::HpkeKdf>::as_str Unexecuted instantiation: <rustls::msgs::enums::HpkeAead>::as_str Unexecuted instantiation: <rustls::msgs::enums::EchVersion>::as_str Unexecuted instantiation: <rustls::msgs::enums::HashAlgorithm>::as_str Unexecuted instantiation: <rustls::msgs::enums::CertificateStatusType>::as_str Unexecuted instantiation: <rustls::msgs::enums::HpkeKem>::as_str Unexecuted instantiation: <rustls::msgs::enums::ExtensionType>::as_str Unexecuted instantiation: <rustls::msgs::enums::Compression>::as_str Unexecuted instantiation: <rustls::msgs::enums::AlertLevel>::as_str Unexecuted instantiation: <rustls::msgs::enums::ServerNameType>::as_str Unexecuted instantiation: <rustls::msgs::enums::HeartbeatMode>::as_str Unexecuted instantiation: <rustls::msgs::enums::ECCurveType>::as_str Unexecuted instantiation: <rustls::msgs::enums::NamedCurve>::as_str Unexecuted instantiation: <rustls::msgs::enums::HeartbeatMessageType>::as_str Unexecuted instantiation: <rustls::msgs::enums::ClientCertificateType>::as_str |
55 | | } |
56 | | |
57 | | impl Codec<'_> for $enum_name { |
58 | | // NOTE(allow) fully qualified Vec is only needed in no-std mode |
59 | | #[allow(unused_qualifications)] |
60 | 0 | fn encode(&self, bytes: &mut alloc::vec::Vec<u8>) { |
61 | 0 | <$uint>::from(*self).encode(bytes); |
62 | 0 | } Unexecuted instantiation: <rustls::enums::AlertDescription as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::enums::CertificateCompressionAlgorithm as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::enums::CertificateType as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::enums::EchClientHelloType as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::enums::CipherSuite as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::enums::SignatureScheme as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::enums::SignatureAlgorithm as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::enums::HandshakeType as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::enums::ContentType as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::enums::ProtocolVersion as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::ServerNameType as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::HeartbeatMode as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::ECCurveType as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::PskKeyExchangeMode as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::NamedCurve as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::NamedGroup as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::ECPointFormat as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::KeyUpdateRequest as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::HpkeKdf as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::HpkeAead as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::EchVersion as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::CertificateStatusType as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::HpkeKem as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::HashAlgorithm as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::HeartbeatMessageType as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::ExtensionType as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::ClientCertificateType as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::Compression as rustls::msgs::codec::Codec>::encode Unexecuted instantiation: <rustls::msgs::enums::AlertLevel as rustls::msgs::codec::Codec>::encode |
63 | | |
64 | 0 | fn read(r: &mut Reader<'_>) -> Result<Self, crate::error::InvalidMessage> { |
65 | 0 | match <$uint>::read(r) { |
66 | 0 | Ok(x) => Ok($enum_name::from(x)), |
67 | 0 | Err(_) => Err(crate::error::InvalidMessage::MissingData(stringify!($enum_name))), |
68 | | } |
69 | 0 | } Unexecuted instantiation: <rustls::enums::AlertDescription as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::enums::CertificateCompressionAlgorithm as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::enums::CertificateType as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::enums::EchClientHelloType as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::enums::CipherSuite as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::enums::SignatureScheme as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::enums::SignatureAlgorithm as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::enums::HandshakeType as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::enums::ContentType as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::enums::ProtocolVersion as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::ServerNameType as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::HeartbeatMode as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::ECCurveType as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::PskKeyExchangeMode as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::NamedCurve as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::NamedGroup as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::ECPointFormat as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::KeyUpdateRequest as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::HpkeKdf as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::HpkeAead as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::EchVersion as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::CertificateStatusType as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::HpkeKem as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::HashAlgorithm as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::HeartbeatMessageType as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::ExtensionType as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::ClientCertificateType as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::Compression as rustls::msgs::codec::Codec>::read Unexecuted instantiation: <rustls::msgs::enums::AlertLevel as rustls::msgs::codec::Codec>::read |
70 | | } |
71 | | |
72 | | impl From<$uint> for $enum_name { |
73 | 0 | fn from(x: $uint) -> Self { |
74 | 0 | match x { |
75 | 0 | $($enum_val => $enum_name::$enum_var),* |
76 | 0 | $(, $($enum_val_nd => $enum_name::$enum_var_nd),* )? |
77 | 0 | , x => $enum_name::Unknown(x), |
78 | | } |
79 | 0 | } Unexecuted instantiation: <rustls::enums::CertificateCompressionAlgorithm as core::convert::From<u16>>::from Unexecuted instantiation: <rustls::enums::AlertDescription as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::enums::CertificateType as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::enums::EchClientHelloType as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::enums::CipherSuite as core::convert::From<u16>>::from Unexecuted instantiation: <rustls::enums::SignatureScheme as core::convert::From<u16>>::from Unexecuted instantiation: <rustls::enums::SignatureAlgorithm as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::enums::HandshakeType as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::enums::ContentType as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::enums::ProtocolVersion as core::convert::From<u16>>::from Unexecuted instantiation: <rustls::msgs::enums::ServerNameType as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::msgs::enums::HeartbeatMode as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::msgs::enums::ECCurveType as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::msgs::enums::NamedCurve as core::convert::From<u16>>::from Unexecuted instantiation: <rustls::msgs::enums::NamedGroup as core::convert::From<u16>>::from Unexecuted instantiation: <rustls::msgs::enums::ECPointFormat as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::msgs::enums::PskKeyExchangeMode as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::msgs::enums::HpkeKdf as core::convert::From<u16>>::from Unexecuted instantiation: <rustls::msgs::enums::HpkeAead as core::convert::From<u16>>::from Unexecuted instantiation: <rustls::msgs::enums::KeyUpdateRequest as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::msgs::enums::CertificateStatusType as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::msgs::enums::HpkeKem as core::convert::From<u16>>::from Unexecuted instantiation: <rustls::msgs::enums::EchVersion as core::convert::From<u16>>::from Unexecuted instantiation: <rustls::msgs::enums::HashAlgorithm as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::msgs::enums::HeartbeatMessageType as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::msgs::enums::ExtensionType as core::convert::From<u16>>::from Unexecuted instantiation: <rustls::msgs::enums::ClientCertificateType as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::msgs::enums::Compression as core::convert::From<u8>>::from Unexecuted instantiation: <rustls::msgs::enums::AlertLevel as core::convert::From<u8>>::from |
80 | | } |
81 | | |
82 | | impl From<$enum_name> for $uint { |
83 | 0 | fn from(value: $enum_name) -> Self { |
84 | 0 | match value { |
85 | | $( $enum_name::$enum_var => $enum_val),* |
86 | | $(, $( $enum_name::$enum_var_nd => $enum_val_nd),* )? |
87 | 0 | ,$enum_name::Unknown(x) => x |
88 | | } |
89 | 0 | } Unexecuted instantiation: <u8 as core::convert::From<rustls::enums::SignatureAlgorithm>>::from Unexecuted instantiation: <u16 as core::convert::From<rustls::enums::CertificateCompressionAlgorithm>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::enums::CertificateType>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::enums::EchClientHelloType>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::enums::AlertDescription>>::from Unexecuted instantiation: <u16 as core::convert::From<rustls::enums::CipherSuite>>::from Unexecuted instantiation: <u16 as core::convert::From<rustls::enums::SignatureScheme>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::enums::HandshakeType>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::enums::ContentType>>::from Unexecuted instantiation: <u16 as core::convert::From<rustls::enums::ProtocolVersion>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::msgs::enums::ServerNameType>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::msgs::enums::HeartbeatMode>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::msgs::enums::ECCurveType>>::from Unexecuted instantiation: <u16 as core::convert::From<rustls::msgs::enums::NamedCurve>>::from Unexecuted instantiation: <u16 as core::convert::From<rustls::msgs::enums::NamedGroup>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::msgs::enums::ECPointFormat>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::msgs::enums::PskKeyExchangeMode>>::from Unexecuted instantiation: <u16 as core::convert::From<rustls::msgs::enums::HpkeKdf>>::from Unexecuted instantiation: <u16 as core::convert::From<rustls::msgs::enums::HpkeAead>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::msgs::enums::KeyUpdateRequest>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::msgs::enums::CertificateStatusType>>::from Unexecuted instantiation: <u16 as core::convert::From<rustls::msgs::enums::HpkeKem>>::from Unexecuted instantiation: <u16 as core::convert::From<rustls::msgs::enums::EchVersion>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::msgs::enums::HashAlgorithm>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::msgs::enums::HeartbeatMessageType>>::from Unexecuted instantiation: <u16 as core::convert::From<rustls::msgs::enums::ExtensionType>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::msgs::enums::ClientCertificateType>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::msgs::enums::Compression>>::from Unexecuted instantiation: <u8 as core::convert::From<rustls::msgs::enums::AlertLevel>>::from |
90 | | } |
91 | | |
92 | | impl core::fmt::Debug for $enum_name { |
93 | 0 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
94 | 0 | match self { |
95 | 0 | $( $enum_name::$enum_var => f.write_str(stringify!($enum_var)), )* |
96 | 0 | _ => write!(f, "{}(0x{:x?})", stringify!($enum_name), <$uint>::from(*self)), |
97 | | } |
98 | 0 | } Unexecuted instantiation: <rustls::enums::SignatureAlgorithm as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::enums::CertificateCompressionAlgorithm as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::enums::CertificateType as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::enums::EchClientHelloType as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::enums::AlertDescription as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::enums::CipherSuite as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::enums::SignatureScheme as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::enums::HandshakeType as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::enums::ContentType as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::enums::ProtocolVersion as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::ServerNameType as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::HeartbeatMode as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::ECCurveType as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::NamedCurve as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::NamedGroup as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::ECPointFormat as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::PskKeyExchangeMode as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::HpkeKdf as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::HpkeAead as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::KeyUpdateRequest as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::CertificateStatusType as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::HpkeKem as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::EchVersion as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::HashAlgorithm as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::AlertLevel as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::HeartbeatMessageType as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::ExtensionType as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::ClientCertificateType as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::enums::Compression as core::fmt::Debug>::fmt |
99 | | } |
100 | | }; |
101 | | } |
102 | | |
103 | | /// A macro which defines a structure containing TLS extensions |
104 | | /// |
105 | | /// The contents are defined by two blocks, which are merged to |
106 | | /// give the struct's items. The second block is optional. |
107 | | /// |
108 | | /// The first block defines the items read-into by decoding, |
109 | | /// and used for encoding. |
110 | | /// |
111 | | /// The type of each item in the first block _must_ be an `Option`. |
112 | | /// This records the presence of that extension. |
113 | | /// |
114 | | /// Each item in the first block is prefixed with a match arm, |
115 | | /// which must match an `ExtensionType` variant. This maps |
116 | | /// the item to its extension type. |
117 | | /// |
118 | | /// Items in the second block are not encoded or decoded-to. |
119 | | /// They therefore must have a reasonable `Default` value. |
120 | | /// |
121 | | /// All items must have a `Default`, `Debug` and `Clone`. |
122 | | macro_rules! extension_struct { |
123 | | ( |
124 | | $(#[doc = $comment:literal])* |
125 | | $struct_vis:vis struct $struct_name:ident$(<$struct_lt:lifetime>)* |
126 | | { |
127 | | $( |
128 | | $(#[$item_attr:meta])* |
129 | | $item_id:path => $item_vis:vis $item_slot:ident : Option<$item_ty:ty>, |
130 | | )+ |
131 | | } $( + { |
132 | | $( |
133 | | $(#[$meta_attr:meta])* |
134 | | $meta_vis:vis $meta_slot:ident : $meta_ty:ty, |
135 | | )+ |
136 | | })* |
137 | | ) => { |
138 | | $(#[doc = $comment])* |
139 | | #[non_exhaustive] |
140 | | #[derive(Clone, Default)] |
141 | | $struct_vis struct $struct_name$(<$struct_lt>)* { |
142 | | $( |
143 | | $(#[$item_attr])* |
144 | | $item_vis $item_slot: Option<$item_ty>, |
145 | | )+ |
146 | | $($( |
147 | | $(#[$meta_attr])* |
148 | | $meta_vis $meta_slot: $meta_ty, |
149 | | )+)* |
150 | | } |
151 | | |
152 | | impl<'a> $struct_name$(<$struct_lt>)* { |
153 | | /// Reads one extension typ, length and body from `r`. |
154 | | /// |
155 | | /// Unhandled extensions (according to `read_extension_body()` are inserted into `unknown_extensions`) |
156 | 0 | fn read_one( |
157 | 0 | &mut self, |
158 | 0 | r: &mut Reader<'a>, |
159 | 0 | mut unknown: impl FnMut(ExtensionType) -> Result<(), InvalidMessage>, |
160 | 0 | ) -> Result<ExtensionType, InvalidMessage> { |
161 | 0 | let typ = ExtensionType::read(r)?; |
162 | 0 | let len = usize::from(u16::read(r)?); |
163 | 0 | let mut ext_body = r.sub(len)?; |
164 | 0 | match self.read_extension_body(typ, &mut ext_body)? { |
165 | 0 | true => ext_body.expect_empty(stringify!($struct_name))?, |
166 | 0 | false => unknown(typ)?, |
167 | | |
168 | | }; |
169 | 0 | Ok(typ) |
170 | 0 | } Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_one::<<rustls::msgs::handshake::ClientExtensions as rustls::msgs::codec::Codec>::read::{closure#0}>Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::read_one::<<rustls::msgs::handshake::ServerExtensions as rustls::msgs::codec::Codec>::read::{closure#0}>Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions>::read_one::<<rustls::msgs::handshake::HelloRetryRequestExtensions as rustls::msgs::codec::Codec>::read::{closure#0}>Unexecuted instantiation: <rustls::msgs::handshake::CertificateRequestExtensions>::read_one::<<rustls::msgs::handshake::CertificateRequestExtensions as rustls::msgs::codec::Codec>::read::{closure#0}>Unexecuted instantiation: <rustls::msgs::handshake::NewSessionTicketExtensions>::read_one::<<rustls::msgs::handshake::NewSessionTicketExtensions as rustls::msgs::codec::Codec>::read::{closure#0}>Unexecuted instantiation: <rustls::msgs::handshake::CertificateExtensions>::read_one::<<rustls::msgs::handshake::CertificateExtensions as rustls::msgs::codec::Codec>::read::{closure#0}> |
171 | | |
172 | | /// Reads one extension body for an extension named by `typ`. |
173 | | /// |
174 | | /// Returns `true` if handled, `false` otherwise. |
175 | | /// |
176 | | /// `r` is fully consumed if `typ` is unhandled. |
177 | 0 | fn read_extension_body( |
178 | 0 | &mut self, |
179 | 0 | typ: ExtensionType, |
180 | 0 | r: &mut Reader<'a>, |
181 | 0 | ) -> Result<bool, InvalidMessage> { |
182 | 0 | match typ { |
183 | | $( |
184 | 0 | $item_id => Self::read_once(r, $item_id, &mut self.$item_slot)?, |
185 | | )* |
186 | | |
187 | | // read and ignore unhandled extensions |
188 | | _ => { |
189 | 0 | r.rest(); |
190 | 0 | return Ok(false); |
191 | | } |
192 | | } |
193 | | |
194 | 0 | Ok(true) |
195 | 0 | } Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_extension_body Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::read_extension_body Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions>::read_extension_body Unexecuted instantiation: <rustls::msgs::handshake::CertificateRequestExtensions>::read_extension_body Unexecuted instantiation: <rustls::msgs::handshake::NewSessionTicketExtensions>::read_extension_body Unexecuted instantiation: <rustls::msgs::handshake::CertificateExtensions>::read_extension_body |
196 | | |
197 | | /// Decode `r` as `T` into `out`, only if `out` is `None`. |
198 | 0 | fn read_once<T>(r: &mut Reader<'a>, id: ExtensionType, out: &mut Option<T>) -> Result<(), InvalidMessage> |
199 | 0 | where T: Codec<'a>, |
200 | | { |
201 | 0 | if let Some(_) = out { |
202 | 0 | return Err(InvalidMessage::DuplicateExtension(u16::from(id))); |
203 | 0 | } |
204 | | |
205 | 0 | *out = Some(T::read(r)?); |
206 | 0 | Ok(()) |
207 | 0 | } Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<rustls::msgs::base::PayloadU16<rustls::msgs::base::NonEmpty>> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<alloc::vec::Vec<rustls::msgs::handshake::ProtocolName>> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<alloc::vec::Vec<rustls::msgs::handshake::KeyShareEntry>> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<alloc::vec::Vec<rustls::msgs::handshake::DistinguishedName>> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<alloc::vec::Vec<rustls::msgs::enums::NamedGroup>> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<alloc::vec::Vec<rustls::msgs::enums::ExtensionType>> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<alloc::vec::Vec<rustls::enums::CertificateType>> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<alloc::vec::Vec<rustls::enums::SignatureScheme>> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<alloc::vec::Vec<rustls::enums::CertificateCompressionAlgorithm>> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<rustls::msgs::handshake::PresharedKeyOffer> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<rustls::msgs::handshake::ServerNamePayload> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<rustls::msgs::handshake::ClientSessionTicket> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<rustls::msgs::handshake::PskKeyExchangeModes> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<rustls::msgs::handshake::EncryptedClientHello> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<rustls::msgs::handshake::SupportedEcPointFormats> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<rustls::msgs::handshake::CertificateStatusRequest> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<rustls::msgs::handshake::SupportedProtocolVersions> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<rustls::msgs::base::Payload> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<rustls::msgs::base::PayloadU8> Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::read_once::<()> Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::read_once::<rustls::msgs::handshake::KeyShareEntry> Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::read_once::<rustls::msgs::handshake::SingleProtocolName> Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::read_once::<rustls::msgs::handshake::SupportedEcPointFormats> Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::read_once::<rustls::msgs::handshake::ServerEncryptedClientHello> Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::read_once::<rustls::msgs::base::Payload> Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::read_once::<rustls::msgs::base::PayloadU8> Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::read_once::<rustls::enums::CertificateType> Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::read_once::<rustls::enums::ProtocolVersion> Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::read_once::<u16> Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::read_once::<()> Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions>::read_once::<rustls::msgs::base::PayloadU16<rustls::msgs::base::NonEmpty>> Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions>::read_once::<rustls::msgs::base::Payload> Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions>::read_once::<rustls::msgs::enums::NamedGroup> Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions>::read_once::<rustls::enums::ProtocolVersion> Unexecuted instantiation: <rustls::msgs::handshake::CertificateRequestExtensions>::read_once::<alloc::vec::Vec<rustls::msgs::handshake::DistinguishedName>> Unexecuted instantiation: <rustls::msgs::handshake::CertificateRequestExtensions>::read_once::<alloc::vec::Vec<rustls::enums::SignatureScheme>> Unexecuted instantiation: <rustls::msgs::handshake::CertificateRequestExtensions>::read_once::<alloc::vec::Vec<rustls::enums::CertificateCompressionAlgorithm>> Unexecuted instantiation: <rustls::msgs::handshake::NewSessionTicketExtensions>::read_once::<u32> Unexecuted instantiation: <rustls::msgs::handshake::CertificateExtensions>::read_once::<rustls::msgs::handshake::CertificateStatus> |
208 | | |
209 | | /// Encode one extension body for `typ` into `output`. |
210 | | /// |
211 | | /// Adds nothing to `output` if `typ` is absent from this |
212 | | /// struct, either because it is `None` or unhandled by |
213 | | /// this struct. |
214 | 0 | fn encode_one( |
215 | 0 | &self, |
216 | 0 | typ: ExtensionType, |
217 | 0 | output: &mut Vec<u8>, |
218 | 0 | ) { |
219 | 0 | match typ { |
220 | | $( |
221 | 0 | $item_id => if let Some(item) = &self.$item_slot { |
222 | 0 | typ.encode(output); |
223 | 0 | item.encode(LengthPrefixedBuffer::new(ListLength::U16, output).buf); |
224 | 0 | }, |
225 | | |
226 | | )* |
227 | 0 | _ => {}, |
228 | | } |
229 | 0 | } Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::encode_one Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::encode_one Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions>::encode_one Unexecuted instantiation: <rustls::msgs::handshake::CertificateRequestExtensions>::encode_one Unexecuted instantiation: <rustls::msgs::handshake::NewSessionTicketExtensions>::encode_one Unexecuted instantiation: <rustls::msgs::handshake::CertificateExtensions>::encode_one |
230 | | |
231 | | /// Return a list of extensions whose items are `Some` |
232 | | #[allow(dead_code)] |
233 | 0 | pub(crate) fn collect_used(&self) -> Vec<ExtensionType> { |
234 | 0 | let mut r = Vec::with_capacity(Self::ALL_EXTENSIONS.len()); |
235 | | |
236 | | $( |
237 | 0 | if let Some(_) = &self.$item_slot { |
238 | 0 | r.push($item_id); |
239 | 0 | } |
240 | | )* |
241 | | |
242 | 0 | r |
243 | 0 | } Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::collect_used Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::collect_used Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions>::collect_used Unexecuted instantiation: <rustls::msgs::handshake::CertificateRequestExtensions>::collect_used Unexecuted instantiation: <rustls::msgs::handshake::NewSessionTicketExtensions>::collect_used Unexecuted instantiation: <rustls::msgs::handshake::CertificateExtensions>::collect_used |
244 | | |
245 | | /// Clone the value of the extension identified by `typ` from `source` to `self`. |
246 | | /// |
247 | | /// Does nothing if `typ` is not an extension handled by this object. |
248 | | #[allow(dead_code)] |
249 | 0 | pub(crate) fn clone_one( |
250 | 0 | &mut self, |
251 | 0 | source: &Self, |
252 | 0 | typ: ExtensionType, |
253 | 0 | ) { |
254 | 0 | match typ { |
255 | | $( |
256 | 0 | $item_id => self.$item_slot = source.$item_slot.clone(), |
257 | | )* |
258 | 0 | _ => {}, |
259 | | } |
260 | 0 | } Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::clone_one Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::clone_one Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions>::clone_one Unexecuted instantiation: <rustls::msgs::handshake::CertificateRequestExtensions>::clone_one Unexecuted instantiation: <rustls::msgs::handshake::NewSessionTicketExtensions>::clone_one Unexecuted instantiation: <rustls::msgs::handshake::CertificateExtensions>::clone_one |
261 | | |
262 | | /// Remove the extension identified by `typ` from `self`. |
263 | | #[allow(dead_code)] |
264 | 0 | pub(crate) fn clear(&mut self, typ: ExtensionType) { |
265 | 0 | match typ { |
266 | | $( |
267 | 0 | $item_id => self.$item_slot = None, |
268 | | )* |
269 | 0 | _ => {}, |
270 | | } |
271 | 0 | } Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::clear Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::clear Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions>::clear Unexecuted instantiation: <rustls::msgs::handshake::CertificateRequestExtensions>::clear Unexecuted instantiation: <rustls::msgs::handshake::NewSessionTicketExtensions>::clear Unexecuted instantiation: <rustls::msgs::handshake::CertificateExtensions>::clear |
272 | | |
273 | | /// Return true if all present extensions are named in `allowed` |
274 | | #[allow(dead_code)] |
275 | 0 | pub(crate) fn only_contains(&self, allowed: &[ExtensionType]) -> bool { |
276 | | $( |
277 | 0 | if let Some(_) = &self.$item_slot { |
278 | 0 | if !allowed.contains(&$item_id) { |
279 | 0 | return false; |
280 | 0 | } |
281 | 0 | } |
282 | | )* |
283 | | |
284 | 0 | true |
285 | 0 | } Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::only_contains Unexecuted instantiation: <rustls::msgs::handshake::CertificateExtensions>::only_contains Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::only_contains Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions>::only_contains Unexecuted instantiation: <rustls::msgs::handshake::CertificateRequestExtensions>::only_contains Unexecuted instantiation: <rustls::msgs::handshake::NewSessionTicketExtensions>::only_contains |
286 | | |
287 | | /// Return true if any extension named in `exts` is present. |
288 | | #[allow(dead_code)] |
289 | 0 | pub(crate) fn contains_any(&self, exts: &[ExtensionType]) -> bool { |
290 | 0 | for e in exts { |
291 | 0 | if self.contains(*e) { |
292 | 0 | return true; |
293 | 0 | } |
294 | | } |
295 | 0 | false |
296 | 0 | } Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::contains_any Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::contains_any Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions>::contains_any Unexecuted instantiation: <rustls::msgs::handshake::CertificateRequestExtensions>::contains_any Unexecuted instantiation: <rustls::msgs::handshake::NewSessionTicketExtensions>::contains_any Unexecuted instantiation: <rustls::msgs::handshake::CertificateExtensions>::contains_any |
297 | | |
298 | 0 | fn contains(&self, e: ExtensionType) -> bool { |
299 | 0 | match e { |
300 | | $( |
301 | | |
302 | 0 | $item_id => self.$item_slot.is_some(), |
303 | | )* |
304 | 0 | _ => false, |
305 | | } |
306 | 0 | } Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions>::contains Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions>::contains Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions>::contains Unexecuted instantiation: <rustls::msgs::handshake::CertificateRequestExtensions>::contains Unexecuted instantiation: <rustls::msgs::handshake::NewSessionTicketExtensions>::contains Unexecuted instantiation: <rustls::msgs::handshake::CertificateExtensions>::contains |
307 | | |
308 | | /// Every `ExtensionType` this structure may encode/decode. |
309 | | const ALL_EXTENSIONS: &'static [ExtensionType] = &[ |
310 | | $($item_id,)* |
311 | | ]; |
312 | | } |
313 | | |
314 | | impl<'a> core::fmt::Debug for $struct_name$(<$struct_lt>)* { |
315 | 0 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
316 | 0 | let mut ds = f.debug_struct(stringify!($struct_name)); |
317 | | $( |
318 | 0 | if let Some(ext) = &self.$item_slot { |
319 | 0 | ds.field(stringify!($item_slot), ext); |
320 | 0 | } |
321 | | )* |
322 | | $($( |
323 | 0 | ds.field(stringify!($meta_slot), &self.$meta_slot); |
324 | | )+)* |
325 | 0 | ds.finish_non_exhaustive() |
326 | 0 | } Unexecuted instantiation: <rustls::msgs::handshake::ClientExtensions as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::handshake::ServerExtensions as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::handshake::HelloRetryRequestExtensions as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::handshake::CertificateRequestExtensions as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::handshake::NewSessionTicketExtensions as core::fmt::Debug>::fmt Unexecuted instantiation: <rustls::msgs::handshake::CertificateExtensions as core::fmt::Debug>::fmt |
327 | | } |
328 | | } |
329 | | } |