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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#![allow(
box_pointers,
clippy::module_name_repetitions,
clippy::exhaustive_structs
)]
use std::{
fmt::{self, Debug, Formatter},
io,
};
pub use bincode::ErrorKind;
pub use quinn::{ConnectError, ConnectionError, ReadError, WriteError};
use thiserror::Error;
#[cfg(feature = "trust-dns")]
#[cfg_attr(doc, doc(cfg(feature = "trust-dns")))]
pub use trust_dns_resolver::error::ResolveError;
pub use url::ParseError;
pub use webpki::Error;
pub use x509_parser::{error::X509Error, nom::Err};
use zeroize::Zeroize;
#[derive(Clone, Debug, Error, PartialEq)]
#[error("Error constructing `Certificate` from bytes: {error}")]
pub struct Certificate {
#[source]
pub error: CertificateError,
pub certificate: Vec<u8>,
}
#[allow(clippy::module_name_repetitions)]
#[derive(Clone, Debug, Error, PartialEq)]
pub enum CertificateError {
#[error(transparent)]
WebPki(Error),
#[error(transparent)]
X509(Err<X509Error>),
#[error("Found dangling bytes in `Certificate`")]
Dangling(Vec<u8>),
#[error("`Certificate` has expired")]
Expired,
#[error("`Certificate` is missing a domain name")]
Domain,
}
#[derive(Clone, Eq, Error, Hash, Ord, PartialEq, PartialOrd, Zeroize)]
#[error("Failed parsing private key")]
#[zeroize(drop)]
pub struct PrivateKey(pub Vec<u8>);
impl Debug for PrivateKey {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_tuple("PrivateKey").field(&"[[redacted]]").finish()
}
}
#[derive(Clone, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)]
#[error("Failed pairing `Certificate` and `PrivateKey`")]
pub struct KeyPair {
certificate: crate::CertificateChain,
private_key: crate::PrivateKey,
}
#[derive(Clone, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)]
#[error("Failed verifiying certificate chhain")]
pub struct CertificateChain(Vec<crate::Certificate>);
#[derive(Clone, Copy, Debug, Eq, Error, Hash, Ord, PartialEq, PartialOrd)]
#[error("This is already closed")]
pub struct AlreadyClosed;
#[derive(Debug, Error)]
#[error("Error constructing `Endpoint` with `Builder`: {error}")]
pub struct Builder {
#[source]
pub error: Config,
pub builder: crate::Builder,
}
#[derive(Debug, Error)]
pub enum Config {
#[error("Error binding socket during construction of `Endpoint`: {0}")]
Bind(io::Error),
#[error(transparent)]
NativeCert(#[from] OsStore),
#[error("Invalid timeout, can't exceed 2^62 ms")]
MaxIdleTimeout,
}
#[derive(Debug, Error)]
#[allow(variant_size_differences)]
pub enum OsStore {
#[error("Error aquiring root certificates from the OS: {0}")]
Aquire(io::Error),
#[error("Error parsing root certificates from the OS: {0}")]
Parse(Error),
}
#[derive(Debug, Error)]
pub enum Connect {
#[error(
"Using a `Certificate` with multiple domains for connecting with a pinned server \
certificate is not supported"
)]
MultipleDomains,
#[error("Error parsing URL: {0}")]
ParseUrl(ParseError),
#[error("URL without a domain is invalid")]
Domain,
#[error("URL without a port is invalid")]
Port,
#[error("Error parsing domain: {0}")]
ParseDomain(ParseError),
#[cfg(feature = "trust-dns")]
#[cfg_attr(doc, doc(cfg(feature = "trust-dns")))]
#[error("Error resolving domain with trust-dns: {0}")]
TrustDns(#[from] Box<ResolveError>),
#[error("Error resolving domain with `ToSocketAddrs`: {0}")]
StdDns(io::Error),
#[error("Found no IP address for that domain")]
NoIp,
#[error("Error in configuration to connect to server: {0}")]
ConnectConfig(#[from] ConnectError),
#[error("Error in configuration: {0}")]
Config(#[from] Config),
}
#[derive(Clone, Debug, Eq, Error, PartialEq)]
#[error("Error receiving connection from peer: {0}")]
pub struct Connection(pub ConnectionError);
#[derive(Clone, Debug, Eq, Error, PartialEq)]
#[error("Error completing connection with peer: {0}")]
pub struct Connecting(pub ConnectionError);
#[derive(Debug, Error)]
pub enum Stream {
#[error("Error opening a new stream to peer: {0}")]
Open(#[from] ConnectionError),
#[error("Error sending type information to peer: {0}")]
Sender(#[from] Sender),
}
#[derive(Debug, Error)]
pub enum Incoming {
#[error("Error receiving type information from `Incoming` stream: {0}")]
Receiver(Receiver),
#[error("Incoming stream was closed")]
Closed,
}
#[derive(Debug, Error)]
pub enum Receiver {
#[error("Error reading from `Receiver`: {0}")]
Read(#[from] ReadError),
#[error("Error deserializing a message from `Receiver`: {0}")]
Deserialize(#[from] ErrorKind),
}
#[derive(Debug, Error)]
pub enum Sender {
#[error("Error serializing a message to `Sender`: {0}")]
Serialize(ErrorKind),
#[error("Error writing to `Sender`: {0}")]
Write(#[from] WriteError),
#[error(transparent)]
Closed(#[from] AlreadyClosed),
}
impl From<Box<ErrorKind>> for Sender {
fn from(error: Box<ErrorKind>) -> Self {
Self::Serialize(*error)
}
}