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
use crate::assert_send;
use crate::assert_sync;
use crate::TlsAcceptorType;
use std::error;
use std::fmt;
use std::io;
use std::result;
#[derive(Debug)]
pub(crate) enum CommonError {
TlsBuilderFromFromDerOrPkcs12NotSupported(&'static dyn TlsAcceptorType),
OpensslCommandFailedToConvert,
PemFromPkcs12ContainsNotSingleCertKeyPair(Vec<String>),
}
impl From<CommonError> for Error {
fn from(e: CommonError) -> Self {
Error::new(e)
}
}
impl fmt::Display for CommonError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CommonError::TlsBuilderFromFromDerOrPkcs12NotSupported(t) =>
write!(f, "implementation {} does not support construction from neither DER nor PKCS #12 keys", t),
CommonError::OpensslCommandFailedToConvert => write!(f, "openssl command to convert certificate failed"),
CommonError::PemFromPkcs12ContainsNotSingleCertKeyPair(tags) => write!(f, "PEM file created from PKCS #12 is expected to contain a single certificate and key, it actually contains {:?}", tags)
}
}
}
impl error::Error for CommonError {}
pub struct Error(Box<dyn error::Error + Send + Sync + 'static>);
fn _assert_kinds() {
assert_sync::<Error>();
assert_send::<Error>();
}
impl Error {
pub fn new<E: error::Error + 'static + Send + Sync>(e: E) -> Error {
Error(Box::new(e))
}
pub fn into_inner(self) -> Box<dyn error::Error + Send + Sync> {
self.0
}
}
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
self.0.source()
}
}
impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&self.0, f)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Error {
Error::new(err)
}
}
impl From<Error> for io::Error {
fn from(err: Error) -> io::Error {
io::Error::new(io::ErrorKind::Other, err)
}
}
pub type Result<A> = result::Result<A, Error>;