Skip to content

Commit 7ee4cc0

Browse files
committed
refactor: use TlsOptions::into_config to convert to rustls::ClientConfig
1 parent 7e46336 commit 7ee4cc0

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/client/mod.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,18 @@ impl TlsOptions {
15981598
fn take_roots(&mut self) -> RootCertStore {
15991599
std::mem::replace(&mut self.ca_certs, RootCertStore::empty())
16001600
}
1601+
1602+
fn into_config(mut self) -> Result<ClientConfig> {
1603+
let builder = ClientConfig::builder().with_root_certificates(self.take_roots());
1604+
if let Some((client_cert, client_key)) = self.identity.take() {
1605+
match builder.with_client_auth_cert(client_cert, client_key) {
1606+
Ok(config) => Ok(config),
1607+
Err(err) => Err(Error::other(format!("invalid client private key {err}"), err)),
1608+
}
1609+
} else {
1610+
Ok(builder.with_no_client_auth())
1611+
}
1612+
}
16011613
}
16021614

16031615
/// A builder for [Client].
@@ -1705,16 +1717,7 @@ impl Connector {
17051717
} else if self.connection_timeout < Duration::ZERO {
17061718
return Err(Error::BadArguments(&"connection timeout must not be negative"));
17071719
}
1708-
let mut tls_options = self.tls.take().unwrap_or_default();
1709-
let tls_builder = ClientConfig::builder().with_root_certificates(tls_options.take_roots());
1710-
let tls_config = if let Some((client_cert, client_key)) = tls_options.identity.take() {
1711-
match tls_builder.with_client_auth_cert(client_cert, client_key) {
1712-
Ok(config) => config,
1713-
Err(err) => return Err(Error::other(format!("invalid client private key {err}"), err)),
1714-
}
1715-
} else {
1716-
tls_builder.with_no_client_auth()
1717-
};
1720+
let tls_config = self.tls.take().unwrap_or_default().into_config()?;
17181721
let (mut session, state_receiver) = Session::new(
17191722
self.session.take(),
17201723
&self.authes,

0 commit comments

Comments
 (0)