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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use aes_ctr::stream_cipher::LoopError;
use std::error;
use std::fmt;
use std::io::Error as IoError;
#[derive(Debug)]
pub enum SecioError {
IoError(IoError),
ProtobufError(prost::DecodeError),
HandshakeParsingFailure,
NoSupportIntersection,
NonceGenerationFailed,
EphemeralKeyGenerationFailed,
SigningFailure,
SignatureVerificationFailed,
SecretGenerationFailed,
NonceVerificationFailed,
CipherError(LoopError),
FrameTooShort,
HmacNotMatching,
InvalidProposition(&'static str),
#[doc(hidden)]
__Nonexhaustive
}
impl error::Error for SecioError {
fn cause(&self) -> Option<&dyn error::Error> {
match *self {
SecioError::IoError(ref err) => Some(err),
SecioError::ProtobufError(ref err) => Some(err),
_ => None,
}
}
}
impl fmt::Display for SecioError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
SecioError::IoError(e) =>
write!(f, "I/O error: {}", e),
SecioError::ProtobufError(e) =>
write!(f, "Protobuf error: {}", e),
SecioError::HandshakeParsingFailure =>
f.write_str("Failed to parse one of the handshake protobuf messages"),
SecioError::NoSupportIntersection =>
f.write_str("There is no protocol supported by both the local and remote hosts"),
SecioError::NonceGenerationFailed =>
f.write_str("Failed to generate nonce"),
SecioError::EphemeralKeyGenerationFailed =>
f.write_str("Failed to generate ephemeral key"),
SecioError::SigningFailure =>
f.write_str("Failed to sign a message with our local private key"),
SecioError::SignatureVerificationFailed =>
f.write_str("The signature of the exchange packet doesn't verify the remote public key"),
SecioError::SecretGenerationFailed =>
f.write_str("Failed to generate the secret shared key from the ephemeral key"),
SecioError::NonceVerificationFailed =>
f.write_str("The final check of the handshake failed"),
SecioError::CipherError(e) =>
write!(f, "Error while decoding/encoding data: {:?}", e),
SecioError::FrameTooShort =>
f.write_str("The received frame was of invalid length"),
SecioError::HmacNotMatching =>
f.write_str("The hashes of the message didn't match"),
SecioError::InvalidProposition(msg) =>
write!(f, "invalid proposition: {}", msg),
SecioError::__Nonexhaustive =>
f.write_str("__Nonexhaustive")
}
}
}
impl From<LoopError> for SecioError {
fn from(err: LoopError) -> SecioError {
SecioError::CipherError(err)
}
}
impl From<IoError> for SecioError {
fn from(err: IoError) -> SecioError {
SecioError::IoError(err)
}
}
impl From<prost::DecodeError> for SecioError {
fn from(err: prost::DecodeError) -> SecioError {
SecioError::ProtobufError(err)
}
}