@@ -9,38 +9,55 @@ pub(crate) mod private {
9
9
pub struct ForcePrivateApi ;
10
10
}
11
11
12
+ /// Channel binding information returned from a TLS handshake.
12
13
pub struct ChannelBinding {
13
14
pub ( crate ) tls_server_end_point : Option < Vec < u8 > > ,
14
15
}
15
16
16
17
impl ChannelBinding {
18
+ /// Creates a `ChannelBinding` containing no information.
17
19
pub fn none ( ) -> ChannelBinding {
18
20
ChannelBinding {
19
21
tls_server_end_point : None ,
20
22
}
21
23
}
22
24
25
+ /// Creates a `ChannelBinding` containing `tls-server-end-point` channel binding information.
23
26
pub fn tls_server_end_point ( tls_server_end_point : Vec < u8 > ) -> ChannelBinding {
24
27
ChannelBinding {
25
28
tls_server_end_point : Some ( tls_server_end_point) ,
26
29
}
27
30
}
28
31
}
29
32
33
+ /// A constructor of `TlsConnect`ors.
34
+ ///
35
+ /// Requires the `runtime` Cargo feature (enabled by default).
30
36
#[ cfg( feature = "runtime" ) ]
31
37
pub trait MakeTlsConnect < S > {
38
+ /// The stream type created by the `TlsConnect` implementation.
32
39
type Stream : AsyncRead + AsyncWrite ;
40
+ /// The `TlsConnect` implementation created by this type.
33
41
type TlsConnect : TlsConnect < S , Stream = Self :: Stream > ;
42
+ /// The error type retured by the `TlsConnect` implementation.
34
43
type Error : Into < Box < dyn Error + Sync + Send > > ;
35
44
45
+ /// Creates a new `TlsConnect`or.
46
+ ///
47
+ /// The domain name is provided for certificate verification and SNI.
36
48
fn make_tls_connect ( & mut self , domain : & str ) -> Result < Self :: TlsConnect , Self :: Error > ;
37
49
}
38
50
51
+ /// An asynchronous function wrapping a stream in a TLS session.
39
52
pub trait TlsConnect < S > {
53
+ /// The stream returned by the future.
40
54
type Stream : AsyncRead + AsyncWrite ;
55
+ /// The error type returned by the future.
41
56
type Error : Into < Box < dyn Error + Sync + Send > > ;
57
+ /// The future returned by the connector.
42
58
type Future : Future < Item = ( Self :: Stream , ChannelBinding ) , Error = Self :: Error > ;
43
59
60
+ /// Returns a future performing a TLS handshake over the stream.
44
61
fn connect ( self , stream : S ) -> Self :: Future ;
45
62
46
63
#[ doc( hidden) ]
@@ -49,6 +66,9 @@ pub trait TlsConnect<S> {
49
66
}
50
67
}
51
68
69
+ /// A `MakeTlsConnect` and `TlsConnect` implementation which simply returns an error.
70
+ ///
71
+ /// This can be used when `sslmode` is `none` or `prefer`.
52
72
#[ derive( Debug , Copy , Clone ) ]
53
73
pub struct NoTls ;
54
74
@@ -77,6 +97,9 @@ impl<S> TlsConnect<S> for NoTls {
77
97
}
78
98
}
79
99
100
+ /// The TLS "stream" type produced by the `NoTls` connector.
101
+ ///
102
+ /// Since `NoTls` doesn't support TLS, this type is uninhabited.
80
103
pub enum NoTlsStream { }
81
104
82
105
impl Read for NoTlsStream {
@@ -103,6 +126,7 @@ impl AsyncWrite for NoTlsStream {
103
126
}
104
127
}
105
128
129
+ /// The error returned by `NoTls`.
106
130
#[ derive( Debug ) ]
107
131
pub struct NoTlsError ( ( ) ) ;
108
132
0 commit comments