@@ -1598,6 +1598,18 @@ impl TlsOptions {
1598
1598
fn take_roots ( & mut self ) -> RootCertStore {
1599
1599
std:: mem:: replace ( & mut self . ca_certs , RootCertStore :: empty ( ) )
1600
1600
}
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
+ }
1601
1613
}
1602
1614
1603
1615
/// A builder for [Client].
@@ -1705,16 +1717,7 @@ impl Connector {
1705
1717
} else if self . connection_timeout < Duration :: ZERO {
1706
1718
return Err ( Error :: BadArguments ( & "connection timeout must not be negative" ) ) ;
1707
1719
}
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 ( ) ?;
1718
1721
let ( mut session, state_receiver) = Session :: new (
1719
1722
self . session . take ( ) ,
1720
1723
& self . authes ,
0 commit comments