pub struct TlsConfig { /* private fields */ }tls-native-tls or tls-rustls only.Expand description
TLS configuration for connecting to Redis.
Supports two backends via feature flags:
tls-native-tls: Uses the platform’s native TLS (OpenSSL on Linux, Secure Transport on macOS, SChannel on Windows).tls-rustls: Uses rustls (pure Rust, no system dependencies).
§Example
Each constructor is available only when its own backend feature is enabled; this example shows both together.
use redis_tower_core::tls::TlsConfig;
// Use platform defaults (system root certs, verify hostname).
let native = TlsConfig::default_native_tls();
// Or with rustls:
let rustls = TlsConfig::default_rustls();
// Disable certificate verification (DANGEROUS, for testing only).
let insecure = TlsConfig::default_native_tls().danger_accept_invalid_certs(true);Implementations§
Source§impl TlsConfig
impl TlsConfig
Sourcepub fn default_native_tls() -> TlsConfig
Available on crate feature tls-native-tls only.
pub fn default_native_tls() -> TlsConfig
tls-native-tls only.Create a TLS config using the native-tls backend with platform defaults.
Sourcepub fn default_rustls() -> TlsConfig
Available on crate feature tls-rustls only.
pub fn default_rustls() -> TlsConfig
tls-rustls only.Create a TLS config using the rustls backend with system root certs.
Sourcepub fn from_rustls_config(config: Arc<ClientConfig>) -> TlsConfig
Available on crate feature tls-rustls only.
pub fn from_rustls_config(config: Arc<ClientConfig>) -> TlsConfig
tls-rustls only.Create from a pre-built rustls ClientConfig.
This allows full control over the TLS configuration (custom root
certs, client certificates, protocol versions, etc.). The
danger_accept_invalid_certs and danger_accept_invalid_hostnames
settings are ignored when using a custom config since the caller
controls verification through the provided ClientConfig.
Sourcepub fn from_native_tls_connector(connector: TlsConnector) -> TlsConfig
Available on crate feature tls-native-tls only.
pub fn from_native_tls_connector(connector: TlsConnector) -> TlsConfig
tls-native-tls only.Create from a pre-built native-tls TlsConnector.
This allows full control over the TLS configuration (custom root
certs, client certificates, protocol versions, etc.). The
danger_accept_invalid_certs and danger_accept_invalid_hostnames
settings are ignored when using a custom connector since the caller
controls verification through the provided TlsConnector.
Sourcepub fn danger_accept_invalid_certs(self, accept: bool) -> TlsConfig
pub fn danger_accept_invalid_certs(self, accept: bool) -> TlsConfig
Accept invalid TLS certificates.
DANGEROUS: This disables certificate verification. Only use for testing with self-signed certificates.
Sourcepub fn danger_accept_invalid_hostnames(self, accept: bool) -> TlsConfig
pub fn danger_accept_invalid_hostnames(self, accept: bool) -> TlsConfig
Accept invalid hostnames in TLS certificates.
DANGEROUS: This disables hostname verification.
Sourcepub fn with_root_ca_pem(self, pem: impl Into<Vec<u8>>) -> TlsConfig
pub fn with_root_ca_pem(self, pem: impl Into<Vec<u8>>) -> TlsConfig
Trust a custom root CA, given its certificate(s) in PEM.
Replaces the default trust roots (system store + webpki bundle) with the
provided CA(s) – the standard private-CA / enterprise posture. Works
with either backend. Ignored if the config was built from a pre-made
ClientConfig / TlsConnector.
§Example
use redis_tower_core::tls::TlsConfig;
let tls = TlsConfig::default_rustls()
.with_root_ca_pem(std::fs::read("ca.pem")?);Sourcepub fn with_client_auth_pem(
self,
cert_pem: impl Into<Vec<u8>>,
key_pem: impl Into<Vec<u8>>,
) -> TlsConfig
pub fn with_client_auth_pem( self, cert_pem: impl Into<Vec<u8>>, key_pem: impl Into<Vec<u8>>, ) -> TlsConfig
Present a client certificate for mutual TLS (mTLS).
cert_pem is the client certificate chain and key_pem its PKCS#8
private key, both in PEM. Works with either backend. Combine with
with_root_ca_pem for the typical
custom-CA + mTLS enterprise posture.
§Example
use redis_tower_core::tls::TlsConfig;
let tls = TlsConfig::default_rustls()
.with_root_ca_pem(std::fs::read("ca.pem")?)
.with_client_auth_pem(std::fs::read("client.pem")?, std::fs::read("client.key")?);