Skip to main content

TlsConfig

Struct TlsConfig 

Source
pub struct TlsConfig { /* private fields */ }
Available on crate features 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

Source

pub fn default_native_tls() -> TlsConfig

Available on crate feature tls-native-tls only.

Create a TLS config using the native-tls backend with platform defaults.

Source

pub fn default_rustls() -> TlsConfig

Available on crate feature tls-rustls only.

Create a TLS config using the rustls backend with system root certs.

Source

pub fn from_rustls_config(config: Arc<ClientConfig>) -> TlsConfig

Available on crate feature 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.

Source

pub fn from_native_tls_connector(connector: TlsConnector) -> TlsConfig

Available on crate feature 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.

Source

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.

Source

pub fn danger_accept_invalid_hostnames(self, accept: bool) -> TlsConfig

Accept invalid hostnames in TLS certificates.

DANGEROUS: This disables hostname verification.

Source

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")?);
Source

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")?);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more