style/fix: cleanup ClientBuilder by removing Option from tls_versions

This commit is contained in:
DarkCat09 2024-08-30 15:59:05 +04:00
parent 71140fb18a
commit 42a43f175e
Signed by: DarkCat09
GPG key ID: BD3CE9B65916CD82

View file

@ -18,7 +18,7 @@ use tokio_rustls::{
/// Builder for creating configured [`Client`] instance /// Builder for creating configured [`Client`] instance
pub struct ClientBuilder { pub struct ClientBuilder {
ss_verifier: Option<Arc<dyn SelfsignedCertVerifier>>, ss_verifier: Option<Arc<dyn SelfsignedCertVerifier>>,
tls_versions: Option<&'static [&'static SupportedProtocolVersion]>, tls_versions: &'static [&'static SupportedProtocolVersion],
#[cfg(feature = "hickory")] #[cfg(feature = "hickory")]
dns: Option<DnsClient>, dns: Option<DnsClient>,
} }
@ -36,7 +36,7 @@ impl ClientBuilder {
pub fn new() -> Self { pub fn new() -> Self {
ClientBuilder { ClientBuilder {
ss_verifier: None, ss_verifier: None,
tls_versions: None, tls_versions: rustls::DEFAULT_VERSIONS,
#[cfg(feature = "hickory")] #[cfg(feature = "hickory")]
dns: None, dns: None,
} }
@ -49,11 +49,7 @@ impl ClientBuilder {
.unwrap_or_else(|| Arc::new(rustls::crypto::ring::default_provider())); .unwrap_or_else(|| Arc::new(rustls::crypto::ring::default_provider()));
let tls_config = rustls::ClientConfig::builder_with_provider(provider.clone()) let tls_config = rustls::ClientConfig::builder_with_provider(provider.clone())
.with_protocol_versions(if let Some(versions) = self.tls_versions { .with_protocol_versions(self.tls_versions)
versions
} else {
rustls::DEFAULT_VERSIONS
})
.unwrap() .unwrap()
.dangerous() .dangerous()
.with_custom_certificate_verifier(Arc::new(InternalCertVerifier::from(provider))); .with_custom_certificate_verifier(Arc::new(InternalCertVerifier::from(provider)));
@ -75,7 +71,7 @@ impl ClientBuilder {
mut self, mut self,
versions: &'static [&'static SupportedProtocolVersion], versions: &'static [&'static SupportedProtocolVersion],
) -> Self { ) -> Self {
self.tls_versions = Some(versions); self.tls_versions = versions;
self self
} }