@@ -10,8 +10,8 @@ use DigestAlgorithm::{Sha1, Sha256, Sha384, Sha512};
10
10
11
11
use futures:: future:: { FutureExt , TryFutureExt } ;
12
12
use ring:: digest;
13
- use rustls:: ClientConfig ;
14
13
use rustls:: pki_types:: ServerName ;
14
+ use rustls:: ClientConfig ;
15
15
use tokio:: io:: { AsyncRead , AsyncWrite , ReadBuf } ;
16
16
use tokio_postgres:: tls:: { ChannelBinding , MakeTlsConnect , TlsConnect } ;
17
17
use tokio_rustls:: { client:: TlsStream , TlsConnector } ;
@@ -39,21 +39,19 @@ where
39
39
{
40
40
type Stream = RustlsStream < S > ;
41
41
type TlsConnect = RustlsConnect ;
42
- type Error = io :: Error ;
42
+ type Error = rustls :: pki_types :: InvalidDnsNameError ;
43
43
44
- fn make_tls_connect ( & mut self , hostname : & str ) -> io:: Result < RustlsConnect > {
45
- ServerName :: try_from ( hostname)
46
- . map ( |dns_name| {
47
- RustlsConnect ( Some ( RustlsConnectData {
48
- hostname : dns_name. to_owned ( ) ,
49
- connector : Arc :: clone ( & self . config ) . into ( ) ,
50
- } ) )
44
+ fn make_tls_connect ( & mut self , hostname : & str ) -> Result < RustlsConnect , Self :: Error > {
45
+ ServerName :: try_from ( hostname) . map ( |dns_name| {
46
+ RustlsConnect ( RustlsConnectData {
47
+ hostname : dns_name. to_owned ( ) ,
48
+ connector : Arc :: clone ( & self . config ) . into ( ) ,
51
49
} )
52
- . or ( Ok ( RustlsConnect ( None ) ) )
50
+ } )
53
51
}
54
52
}
55
53
56
- pub struct RustlsConnect ( Option < RustlsConnectData > ) ;
54
+ pub struct RustlsConnect ( RustlsConnectData ) ;
57
55
58
56
struct RustlsConnectData {
59
57
hostname : ServerName < ' static > ,
@@ -69,14 +67,11 @@ where
69
67
type Future = Pin < Box < dyn Future < Output = io:: Result < RustlsStream < S > > > + Send > > ;
70
68
71
69
fn connect ( self , stream : S ) -> Self :: Future {
72
- match self . 0 {
73
- None => Box :: pin ( core:: future:: ready ( Err ( io:: ErrorKind :: InvalidInput . into ( ) ) ) ) ,
74
- Some ( c) => c
75
- . connector
76
- . connect ( c. hostname , stream)
77
- . map_ok ( |s| RustlsStream ( Box :: pin ( s) ) )
78
- . boxed ( ) ,
79
- }
70
+ self . 0
71
+ . connector
72
+ . connect ( self . 0 . hostname , stream)
73
+ . map_ok ( |s| RustlsStream ( Box :: pin ( s) ) )
74
+ . boxed ( )
80
75
}
81
76
}
82
77
@@ -152,12 +147,12 @@ where
152
147
mod tests {
153
148
use super :: * ;
154
149
use futures:: future:: TryFutureExt ;
150
+ use rustls:: pki_types:: { CertificateDer , UnixTime } ;
155
151
use rustls:: {
156
152
client:: danger:: ServerCertVerifier ,
157
153
client:: danger:: { HandshakeSignatureValid , ServerCertVerified } ,
158
154
Error , SignatureScheme ,
159
155
} ;
160
- use rustls:: pki_types:: { CertificateDer , UnixTime } ;
161
156
162
157
#[ derive( Debug ) ]
163
158
struct AcceptAllVerifier { }
0 commit comments