/rust/registry/src/index.crates.io-6f17d22bba15001f/tls-parser-0.11.0/src/tls_alert.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use nom_derive::*; |
2 | | use rusticata_macros::newtype_enum; |
3 | | |
4 | | /// TLS alert severity |
5 | 395k | #[derive(Clone, Copy, Debug, PartialEq, Eq, Nom)] <tls_parser::tls_alert::TlsAlertSeverity as nom_derive::traits::Parse<&[u8]>>::parse_be Line | Count | Source | 5 | 24.7k | #[derive(Clone, Copy, Debug, PartialEq, Eq, Nom)] |
Unexecuted instantiation: <tls_parser::tls_alert::TlsAlertSeverity as nom_derive::traits::Parse<&[u8]>>::parse_le Unexecuted instantiation: <tls_parser::tls_alert::TlsAlertSeverity as nom_derive::traits::Parse<&[u8]>>::parse <tls_parser::tls_alert::TlsAlertSeverity as nom_derive::traits::Parse<&[u8]>>::parse_be Line | Count | Source | 5 | 371k | #[derive(Clone, Copy, Debug, PartialEq, Eq, Nom)] |
Unexecuted instantiation: <tls_parser::tls_alert::TlsAlertSeverity as nom_derive::traits::Parse<&[u8]>>::parse_le Unexecuted instantiation: <tls_parser::tls_alert::TlsAlertSeverity as nom_derive::traits::Parse<&[u8]>>::parse |
6 | | pub struct TlsAlertSeverity(pub u8); |
7 | | |
8 | | newtype_enum! { |
9 | | impl display TlsAlertSeverity { |
10 | | Warning = 0x01, |
11 | | Fatal = 0x02 |
12 | | } |
13 | | } |
14 | | |
15 | | /// TLS alert description |
16 | | /// |
17 | | /// Alerts are defined in the [IANA TLS Alert |
18 | | /// Registry](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-6) |
19 | 371k | #[derive(Clone, Copy, Debug, PartialEq, Eq, Nom)] <tls_parser::tls_alert::TlsAlertDescription as nom_derive::traits::Parse<&[u8]>>::parse_be Line | Count | Source | 19 | 23.1k | #[derive(Clone, Copy, Debug, PartialEq, Eq, Nom)] |
Unexecuted instantiation: <tls_parser::tls_alert::TlsAlertDescription as nom_derive::traits::Parse<&[u8]>>::parse_le Unexecuted instantiation: <tls_parser::tls_alert::TlsAlertDescription as nom_derive::traits::Parse<&[u8]>>::parse <tls_parser::tls_alert::TlsAlertDescription as nom_derive::traits::Parse<&[u8]>>::parse_be Line | Count | Source | 19 | 347k | #[derive(Clone, Copy, Debug, PartialEq, Eq, Nom)] |
Unexecuted instantiation: <tls_parser::tls_alert::TlsAlertDescription as nom_derive::traits::Parse<&[u8]>>::parse_le Unexecuted instantiation: <tls_parser::tls_alert::TlsAlertDescription as nom_derive::traits::Parse<&[u8]>>::parse |
20 | | pub struct TlsAlertDescription(pub u8); |
21 | | |
22 | | newtype_enum! { |
23 | | impl display TlsAlertDescription { |
24 | | CloseNotify = 0x00, |
25 | | UnexpectedMessage = 0x0A, |
26 | | BadRecordMac = 0x14, |
27 | | DecryptionFailed = 0x15, |
28 | | RecordOverflow = 0x16, |
29 | | DecompressionFailure = 0x1E, |
30 | | HandshakeFailure = 0x28, |
31 | | NoCertificate = 0x29, |
32 | | BadCertificate = 0x2A, |
33 | | UnsupportedCertificate = 0x2B, |
34 | | CertificateRevoked = 0x2C, |
35 | | CertificateExpired = 0x2D, |
36 | | CertificateUnknown = 0x2E, |
37 | | IllegalParameter = 0x2F, |
38 | | UnknownCa = 0x30, |
39 | | AccessDenied = 0x31, |
40 | | DecodeError = 0x32, |
41 | | DecryptError = 0x33, |
42 | | ExportRestriction = 0x3C, |
43 | | ProtocolVersion = 0x46, |
44 | | InsufficientSecurity = 0x47, |
45 | | InternalError = 0x50, |
46 | | InappropriateFallback = 0x56, |
47 | | UserCancelled = 0x5A, |
48 | | NoRenegotiation = 0x64, |
49 | | MissingExtension = 0x6d, |
50 | | UnsupportedExtension = 0x6e, |
51 | | CertUnobtainable = 0x6f, |
52 | | UnrecognizedName = 0x70, |
53 | | BadCertStatusResponse = 0x71, |
54 | | BadCertHashValue = 0x72, |
55 | | UnknownPskIdentity = 0x73, |
56 | | CertificateRequired = 0x74, |
57 | | NoApplicationProtocol = 0x78 // [RFC7301] |
58 | | } |
59 | | } |
60 | | |
61 | | /// TLS alert message |
62 | 391k | #[derive(Clone, PartialEq, Nom)] <tls_parser::tls_alert::TlsMessageAlert as nom_derive::traits::Parse<&[u8]>>::parse_be Line | Count | Source | 62 | 24.0k | #[derive(Clone, PartialEq, Nom)] |
Unexecuted instantiation: <tls_parser::tls_alert::TlsMessageAlert as nom_derive::traits::Parse<&[u8]>>::parse_le <tls_parser::tls_alert::TlsMessageAlert as nom_derive::traits::Parse<&[u8]>>::parse Line | Count | Source | 62 | 23.8k | #[derive(Clone, PartialEq, Nom)] |
<tls_parser::tls_alert::TlsMessageAlert as nom_derive::traits::Parse<&[u8]>>::parse_be Line | Count | Source | 62 | 367k | #[derive(Clone, PartialEq, Nom)] |
Unexecuted instantiation: <tls_parser::tls_alert::TlsMessageAlert as nom_derive::traits::Parse<&[u8]>>::parse_le <tls_parser::tls_alert::TlsMessageAlert as nom_derive::traits::Parse<&[u8]>>::parse Line | Count | Source | 62 | 351k | #[derive(Clone, PartialEq, Nom)] |
|
63 | | pub struct TlsMessageAlert { |
64 | | /// Should match a [TlsAlertSeverity](enum.TlsAlertSeverity.html) value |
65 | | pub severity: TlsAlertSeverity, |
66 | | /// Should match a [TlsAlertDescription](enum.TlsAlertDescription.html) value |
67 | | pub code: TlsAlertDescription, |
68 | | } |
69 | | |
70 | | #[cfg(test)] |
71 | | mod tests { |
72 | | use crate::tls_alert::*; |
73 | | |
74 | | #[test] |
75 | | fn test_tlsalert_cast_severity() { |
76 | | let a = TlsAlertSeverity::Warning; |
77 | | |
78 | | let a_u8 = a.0; |
79 | | assert_eq!(a_u8, 0x01); |
80 | | |
81 | | let b = TlsAlertSeverity(a_u8); |
82 | | assert_eq!(b, TlsAlertSeverity::Warning); |
83 | | |
84 | | let s = format!("{}", b); |
85 | | assert_eq!(s, "Warning"); |
86 | | |
87 | | let s = format!("{}", TlsAlertSeverity(129)); |
88 | | assert_eq!(s, "TlsAlertSeverity(129 / 0x81)"); |
89 | | } |
90 | | |
91 | | #[test] |
92 | | fn test_tlsalert_cast_description() { |
93 | | let a = TlsAlertDescription::HandshakeFailure; |
94 | | |
95 | | let a_u8 = a.0; |
96 | | assert_eq!(a_u8, 0x28); |
97 | | |
98 | | let b = TlsAlertDescription(a_u8); |
99 | | assert_eq!(b, TlsAlertDescription::HandshakeFailure); |
100 | | } |
101 | | } // mod tests |