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    /// Missing an implementation - Implementation, extra information
20    NotImplemented(&'static str, &'static str),
21}
22
23#[derive(Debug, PartialEq)]
24pub enum ClientHelloError {
25    /// Session Id <= 32 bytes
26    OverflowSesId,
27    /// Cipher Suites <= 65534 bytes
28    OverflowCipherSuites,
29    /// One of the extensions is invalid
30    Extensions(ExtensionsError),
31    /// One of the Cipher Suites is invalid
32    CipherSuites(CipherSuitesError),
33}
34
35#[derive(Debug, PartialEq)]
36pub enum ServerHelloError {
37    /// Session Id <= 32 bytes
38    OverflowSesId,
39    /// Cipher Suites <= 65534 bytes
40    OverflowCipherSuites,
41    /// One of the extensions is invalid
42    Extensions(ExtensionsError),
43    /// One of the Cipher Suites is invalid
44    CipherSuites(CipherSuitesError),
45}
46
47#[derive(Debug, PartialEq)]
48pub enum ExtensionsError {
49    /// Extension length field overflows
50    OverflowExtensionLen,
51}
52
53#[derive(Debug, PartialEq)]
54pub enum CipherSuitesError {
55    /// Provided Cipher Suites were invalid length. Must be % 4 == 0
56    InvalidLength,
57}
58
59use zerocopy::{error::TryCastError, TryFromBytes};
60
61impl RecordError {
62    pub(crate) fn from_zero_copy<Src, Dst: ?Sized + TryFromBytes>(
63        e: TryCastError<Src, Dst>,
64    ) -> Self {
65        match e {
66            TryCastError::Alignment(..) => Self::Alignment,
67            TryCastError::Validity(..) => Self::Validity,
68            TryCastError::Size(..) => Self::Size,
69        }
70    }
71}
72
73#[derive(Debug, PartialEq)]
74pub enum BuilderError {
75    /// Static buffer is either not long enough to hold the buffered record
76    /// or length of payload part is overflowing maximum possible.
77    Overflow,
78    /// Session Id length is one byte but size was > 255
79    SessionIdOverflow,
80    /// Error getting disjoint mut
81    DisjointMutError,
82}