Skip to main content

bornera_rustls/
config_display.rs

1//! Formatting and error sources for construction-time failures.
2
3use core::fmt;
4
5use crate::{
6    RustlsClientSessionError, RustlsConfigError, RustlsConnectError, RustlsServerSessionError,
7    RustlsTransportLimitsError,
8};
9
10impl fmt::Display for RustlsTransportLimitsError {
11    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
12        formatter.write_str(match self {
13            Self::AddressSpace => "rustls logical buffer exceeds retained-byte address space",
14            Self::MissingInboundCharge => "rustls encoded-input charge must be nonzero",
15            Self::MissingProtocolCharge => "rustls protocol-state charge must be nonzero",
16            Self::EgressCharge { .. } => {
17                "rustls outbound charge is smaller than its observable TLS-egress bound"
18            }
19            Self::PlaintextCharge { .. } => {
20                "rustls plaintext charge is smaller than its logical buffer bounds"
21            }
22        })
23    }
24}
25
26impl core::error::Error for RustlsTransportLimitsError {}
27
28impl fmt::Display for RustlsConfigError {
29    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            Self::InvalidServerName => formatter.write_str("invalid TLS server name"),
32        }
33    }
34}
35
36impl core::error::Error for RustlsConfigError {}
37
38impl fmt::Display for RustlsConnectError {
39    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
40        match self {
41            Self::Capacity { .. } => {
42                formatter.write_str("rustls transport exceeds the supplied slot capacity")
43            }
44            Self::Transport(_) => {
45                formatter.write_str("initial rustls transport state exceeds its configured bound")
46            }
47            Self::Tls(source) => source.fmt(formatter),
48            Self::Io(source) => source.fmt(formatter),
49        }
50    }
51}
52
53impl core::error::Error for RustlsConnectError {
54    fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
55        match self {
56            Self::Tls(source) => Some(source),
57            Self::Io(source) => Some(source),
58            Self::Capacity { .. } | Self::Transport(_) => None,
59        }
60    }
61}
62
63impl fmt::Display for RustlsServerSessionError {
64    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
65        match self {
66            Self::Capacity { .. } => {
67                formatter.write_str("rustls server session exceeds the supplied capacity")
68            }
69            Self::Transport(_) => {
70                formatter.write_str("initial rustls server state exceeds its configured bound")
71            }
72            Self::Tls(source) => source.fmt(formatter),
73        }
74    }
75}
76
77impl core::error::Error for RustlsServerSessionError {
78    fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
79        match self {
80            Self::Tls(source) => Some(source),
81            Self::Capacity { .. } | Self::Transport(_) => None,
82        }
83    }
84}
85
86impl fmt::Display for RustlsClientSessionError {
87    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
88        match self {
89            Self::Capacity { .. } => {
90                formatter.write_str("rustls client session exceeds the supplied capacity")
91            }
92            Self::Transport(_) => {
93                formatter.write_str("initial rustls client state exceeds its configured bound")
94            }
95            Self::Tls(source) => source.fmt(formatter),
96        }
97    }
98}
99
100impl core::error::Error for RustlsClientSessionError {
101    fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
102        match self {
103            Self::Tls(source) => Some(source),
104            Self::Capacity { .. } | Self::Transport(_) => None,
105        }
106    }
107}