use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum TlsError {
#[error("TLS handshake failed: {0}")]
HandshakeFailed(String),
#[error("certificate validation failed: {0}")]
CertificateValidation(String),
#[error("hostname verification failed: expected {expected}, got {actual}")]
HostnameVerification {
expected: String,
actual: String,
},
#[error("invalid certificate: {0}")]
InvalidCertificate(String),
#[error("invalid private key: {0}")]
InvalidPrivateKey(String),
#[error("TLS configuration error: {0}")]
Configuration(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("rustls error: {0}")]
Rustls(#[from] rustls::Error),
#[error("server requires encryption")]
EncryptionRequired,
#[error("server does not support encryption")]
EncryptionNotSupported,
#[error("TDS 8.0 strict mode required")]
StrictModeRequired,
#[error("connection closed during TLS negotiation")]
ConnectionClosed,
}
impl TlsError {
#[must_use]
pub fn is_transient(&self) -> bool {
matches!(self, Self::Io(_) | Self::ConnectionClosed)
}
#[must_use]
pub fn is_terminal(&self) -> bool {
!self.is_transient()
}
}