1use std::fmt;
2
3#[derive(Debug)]
5pub enum TlsError {
6 Rustls(rustls::Error),
8 Io(std::io::Error),
10 InvalidHostname(String),
12 NoRootCerts,
14}
15
16impl fmt::Display for TlsError {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 match self {
19 Self::Rustls(e) => write!(f, "TLS error: {e}"),
20 Self::Io(e) => write!(f, "TLS I/O error: {e}"),
21 Self::InvalidHostname(h) => write!(f, "invalid TLS hostname: {h}"),
22 Self::NoRootCerts => write!(f, "no system root certificates found"),
23 }
24 }
25}
26
27impl std::error::Error for TlsError {
28 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
29 match self {
30 Self::Rustls(e) => Some(e),
31 Self::Io(e) => Some(e),
32 _ => None,
33 }
34 }
35}
36
37impl From<rustls::Error> for TlsError {
38 fn from(e: rustls::Error) -> Self {
39 Self::Rustls(e)
40 }
41}
42
43impl From<std::io::Error> for TlsError {
44 fn from(e: std::io::Error) -> Self {
45 Self::Io(e)
46 }
47}