Skip to main content

TlsConfigBuilder

Struct TlsConfigBuilder 

Source
pub struct TlsConfigBuilder { /* private fields */ }
Expand description

Builder for constructing a TlsConfig.

Implementations§

Source§

impl TlsConfigBuilder

Source

pub fn new() -> Self

Create a new builder with secure defaults.

Source

pub fn trust_store(self, store: TrustStore) -> Self

Set the trust store source.

Source

pub fn ca_certificate_path(self, path: impl AsRef<Path>) -> Result<Self>

Load CA certificates from a PEM file, replacing any existing trust store configuration.

§Errors

Returns an error if the file cannot be read or the PEM data is malformed.

Source

pub fn add_ca_certificate_path(self, path: impl AsRef<Path>) -> Result<Self>

Add CA certificates from a PEM file or certificate directory to the configured custom trust store, replacing the default trust store if this is the first custom source.

Duplicate certificates are ignored. This is useful when multiple environment-provided CA sources are combined.

§Errors

Returns an error if the path cannot be read or contains no PEM certificates. Empty directories are ignored.

Source

pub fn ca_certificate_pem(self, pem_bytes: &[u8]) -> Result<Self>

Load CA certificates from PEM bytes, replacing any existing trust store configuration.

§Errors

Returns an error if the PEM data is malformed or empty.

Source

pub fn ca_certificate_der(self, der_certs: Vec<Vec<u8>>) -> Result<Self>

Load CA certificates from DER bytes, replacing any existing trust store configuration.

Each certificate is expected as raw DER-encoded X.509 data (without PEM framing).

§Errors

Returns an error if no certificates are provided.

Source

pub fn client_identity(self, identity: ClientIdentity) -> Self

Set the client identity for mTLS.

Source

pub fn client_cert_path( self, cert_path: impl AsRef<Path>, key_path: impl AsRef<Path>, ) -> Result<Self>

Load a client certificate and private key from PEM files.

§Errors

Returns an error if the files cannot be read or the PEM data is malformed.

Source

pub fn verify_hostname(self, enabled: bool) -> Self

Enable or disable hostname verification.

When disabled, the client does not verify that the server’s certificate matches the requested hostname. This is insecure and should only be used for testing.

Source

pub fn danger_accept_invalid_certs(self, accept: bool) -> Self

Enable or disable certificate verification.

When disabled (danger_accept_invalid_certs(true)), the client does not verify the server’s certificate chain or hostname. This is insecure and should only be used for testing against known self-signed certificates.

Source

pub fn min_tls_version(self, version: TlsVersion) -> Self

Set the minimum TLS version.

Source

pub fn max_tls_version(self, version: TlsVersion) -> Self

Set the maximum TLS version.

Source

pub fn sni(self, enabled: bool) -> Self

Enable or disable SNI (Server Name Indication).

Disabling SNI can break hostname verification and virtual-host routing. It should rarely be necessary.

Source

pub fn build(self) -> TlsConfig

Build the TlsConfig.

Trait Implementations§

Source§

impl Default for TlsConfigBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<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, 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<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