pub struct TlsConfigBuilder { /* private fields */ }Expand description
Builder for constructing a TlsConfig.
Implementations§
Source§impl TlsConfigBuilder
impl TlsConfigBuilder
Sourcepub fn trust_store(self, store: TrustStore) -> Self
pub fn trust_store(self, store: TrustStore) -> Self
Set the trust store source.
Sourcepub fn ca_certificate_path(self, path: impl AsRef<Path>) -> Result<Self>
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.
Sourcepub fn add_ca_certificate_path(self, path: impl AsRef<Path>) -> Result<Self>
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.
Sourcepub fn additional_ca_certificate_path(
self,
path: impl AsRef<Path>,
) -> Result<Self>
pub fn additional_ca_certificate_path( self, path: impl AsRef<Path>, ) -> Result<Self>
Load additional CA certificates from a PEM file or certificate
directory. Additional roots augment the selected base trust store;
unlike Self::ca_certificate_path, they do not replace it.
Existing Self::add_ca_certificate_path behavior is intentionally
unchanged: that method continues to build a replacement custom set.
§Errors
Returns an error if the path cannot be read or contains malformed certificate data. Empty directories are ignored, matching the existing path-based CA API.
Sourcepub fn ca_certificate_pem(self, pem_bytes: &[u8]) -> Result<Self>
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.
Sourcepub fn ca_certificate_der(self, der_certs: Vec<Vec<u8>>) -> Result<Self>
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.
Sourcepub fn additional_ca_certificate_pem(self, pem_bytes: &[u8]) -> Result<Self>
pub fn additional_ca_certificate_pem(self, pem_bytes: &[u8]) -> Result<Self>
Load additional CA certificates from PEM bytes. The certificates are added to the selected base trust store rather than replacing it.
§Errors
Returns an error if the PEM data is malformed or contains no certificates.
Sourcepub fn additional_ca_certificate_der(
self,
der_certs: Vec<Vec<u8>>,
) -> Result<Self>
pub fn additional_ca_certificate_der( self, der_certs: Vec<Vec<u8>>, ) -> Result<Self>
Load additional CA certificates from raw DER values. The certificates are added to the selected base trust store rather than replacing it.
§Errors
Returns an error if no certificates are supplied.
Sourcepub fn crypto_provider(self, provider: Arc<CryptoProvider>) -> Self
pub fn crypto_provider(self, provider: Arc<CryptoProvider>) -> Self
Use an explicitly supplied Rustls crypto provider for this
configuration. The provider is local to the resulting TlsConfig
and is never installed as the process-wide default.
Sourcepub fn client_identity(self, identity: ClientIdentity) -> Self
pub fn client_identity(self, identity: ClientIdentity) -> Self
Set the client identity for mTLS.
Sourcepub fn client_cert_path(
self,
cert_path: impl AsRef<Path>,
key_path: impl AsRef<Path>,
) -> Result<Self>
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.
Sourcepub fn verify_hostname(self, enabled: bool) -> Self
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.
Sourcepub fn danger_accept_invalid_certs(self, accept: bool) -> Self
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.
Sourcepub fn min_tls_version(self, version: TlsVersion) -> Self
pub fn min_tls_version(self, version: TlsVersion) -> Self
Set the minimum TLS version.
Sourcepub fn max_tls_version(self, version: TlsVersion) -> Self
pub fn max_tls_version(self, version: TlsVersion) -> Self
Set the maximum TLS version.