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