@@ -60,15 +60,37 @@ impl std::fmt::Display for CertificateInput {
6060pub struct TlsConfig < ' a > {
6161 pub accept_invalid_certs : bool ,
6262 pub accept_invalid_hostnames : bool ,
63- pub hostname : & ' a str ,
6463 pub root_cert_path : Option < & ' a CertificateInput > ,
6564 pub client_cert_path : Option < & ' a CertificateInput > ,
6665 pub client_key_path : Option < & ' a CertificateInput > ,
6766}
6867
68+ #[ cfg( feature = "_tls-native-tls" ) ]
69+ pub use self :: tls_native_tls:: NativeTlsConnector as TlsConnector ;
70+ #[ cfg( all( feature = "_tls-rustls" , not( feature = "_tls-native-tls" ) ) ) ]
71+ pub use self :: tls_rustls:: RustlsConnector as TlsConnector ;
72+ #[ cfg( not( any( feature = "_tls-native-tls" , feature = "_tls-rustls" ) ) ) ]
73+ #[ derive( Clone ) ]
74+ pub struct TlsConnector ( std:: convert:: Infallible ) ;
75+
76+ pub async fn connector ( config : TlsConfig < ' _ > ) -> crate :: Result < TlsConnector > {
77+ #[ cfg( feature = "_tls-native-tls" ) ]
78+ return Ok ( tls_native_tls:: connector ( config) . await ?) ;
79+
80+ #[ cfg( all( feature = "_tls-rustls" , not( feature = "_tls-native-tls" ) ) ) ]
81+ return Ok ( tls_rustls:: connector ( config) . await ?) ;
82+
83+ #[ cfg( not( any( feature = "_tls-native-tls" , feature = "_tls-rustls" ) ) ) ]
84+ {
85+ _ = config;
86+ panic ! ( "one of the `runtime-*-native-tls` or `runtime-*-rustls` features must be enabled" )
87+ }
88+ }
89+
6990pub async fn handshake < S , Ws > (
7091 socket : S ,
71- config : TlsConfig < ' _ > ,
92+ hostname : & str ,
93+ connector : TlsConnector ,
7294 with_socket : Ws ,
7395) -> crate :: Result < Ws :: Output >
7496where
@@ -77,18 +99,18 @@ where
7799{
78100 #[ cfg( feature = "_tls-native-tls" ) ]
79101 return Ok ( with_socket
80- . with_socket ( tls_native_tls:: handshake ( socket, config ) . await ?)
102+ . with_socket ( tls_native_tls:: handshake ( socket, hostname , connector ) . await ?)
81103 . await ) ;
82104
83105 #[ cfg( all( feature = "_tls-rustls" , not( feature = "_tls-native-tls" ) ) ) ]
84106 return Ok ( with_socket
85- . with_socket ( tls_rustls:: handshake ( socket, config ) . await ?)
107+ . with_socket ( tls_rustls:: handshake ( socket, hostname , connector ) . await ?)
86108 . await ) ;
87109
88110 #[ cfg( not( any( feature = "_tls-native-tls" , feature = "_tls-rustls" ) ) ) ]
89111 {
90- drop ( ( socket, config , with_socket) ) ;
91- panic ! ( "one of the `runtime-*-native-tls` or `runtime-*-rustls` features must be enabled" )
112+ drop ( ( socket, hostname , with_socket) ) ;
113+ match connector . 0 { }
92114 }
93115}
94116
0 commit comments