1use thiserror::Error;
4
5#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum TlsError {
9 #[error("TLS handshake failed: {0}")]
11 HandshakeFailed(String),
12
13 #[error("certificate validation failed: {0}")]
15 CertificateValidation(String),
16
17 #[error("hostname verification failed: expected {expected}, got {actual}")]
19 HostnameVerification {
20 expected: String,
22 actual: String,
24 },
25
26 #[error("invalid certificate: {0}")]
28 InvalidCertificate(String),
29
30 #[error("invalid private key: {0}")]
32 InvalidPrivateKey(String),
33
34 #[error("TLS configuration error: {0}")]
36 Configuration(String),
37
38 #[error("IO error: {0}")]
40 Io(#[from] std::io::Error),
41
42 #[error("rustls error: {0}")]
44 Rustls(#[from] rustls::Error),
45
46 #[error("server requires encryption")]
48 EncryptionRequired,
49
50 #[error("server does not support encryption")]
52 EncryptionNotSupported,
53
54 #[error("TDS 8.0 strict mode required")]
56 StrictModeRequired,
57
58 #[error("connection closed during TLS negotiation")]
60 ConnectionClosed,
61}
62
63impl TlsError {
64 #[must_use]
69 pub fn is_transient(&self) -> bool {
70 matches!(self, Self::Io(_) | Self::ConnectionClosed)
71 }
72
73 #[must_use]
78 pub fn is_terminal(&self) -> bool {
79 !self.is_transient()
80 }
81}