ytls_record/
error.rs

1//! errors
2
3#[derive(Debug, PartialEq)]
4pub enum RecordError {
5    /// Record not valid
6    Validity,
7    /// Record not aligned
8    Alignment,
9    /// Record size error
10    Size,
11    /// RFC 8446 s. 5. Record size > MUST NOT exceed 2^14 bytes
12    OverflowLength,
13    /// Client Hello within Record
14    ClientHello(ClientHelloError),
15    /// Server Hello within Record
16    ServerHello(ServerHelloError),
17    /// Not allowed within Wrapped record
18    NotAllowed,
19}
20
21#[derive(Debug, PartialEq)]
22pub enum ClientHelloError {
23    /// Session Id <= 32 bytes
24    OverflowSesId,
25    /// Cipher Suites <= 65534 bytes
26    OverflowCipherSuites,
27    /// One of the extensions is invalid
28    Extensions(ExtensionsError),
29    /// One of the Cipher Suites is invalid
30    CipherSuites(CipherSuitesError),
31}
32
33#[derive(Debug, PartialEq)]
34pub enum ServerHelloError {
35    /// Session Id <= 32 bytes
36    OverflowSesId,
37    /// Cipher Suites <= 65534 bytes
38    OverflowCipherSuites,
39    /// One of the extensions is invalid
40    Extensions(ExtensionsError),
41    /// One of the Cipher Suites is invalid
42    CipherSuites(CipherSuitesError),
43}
44
45#[derive(Debug, PartialEq)]
46pub enum ExtensionsError {
47    /// Extension length field overflows
48    OverflowExtensionLen,
49}
50
51#[derive(Debug, PartialEq)]
52pub enum CipherSuitesError {
53    /// Provided Cipher Suites were invalid length. Must be % 4 == 0
54    InvalidLength,
55}
56
57use zerocopy::{error::TryCastError, TryFromBytes};
58
59impl RecordError {
60    pub(crate) fn from_zero_copy<Src, Dst: ?Sized + TryFromBytes>(
61        e: TryCastError<Src, Dst>,
62    ) -> Self {
63        match e {
64            TryCastError::Alignment(..) => Self::Alignment,
65            TryCastError::Validity(..) => Self::Validity,
66            TryCastError::Size(..) => Self::Size,
67        }
68    }
69}
70
71#[derive(Debug, PartialEq)]
72pub enum BuilderError {
73    /// Static buffer is either not long enough to hold the buffered record
74    /// or length of payload part is overflowing maximum possible.
75    Overflow,
76    /// Session Id length is one byte but size was > 255
77    SessionIdOverflow,
78    /// Error getting disjoint mut
79    DisjointMutError,
80}