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