1
- #![ warn( rust_2018_idioms, clippy:: all) ]
1
+ //! TLS support for `tokio-postgres` via `native-tls.
2
+ //!
3
+ //! # Example
4
+ //!
5
+ //! ```no_run
6
+ //! use native_tls::{Certificate, TlsConnector};
7
+ //! use tokio_postgres_native_tls::MakeTlsConnector;
8
+ //! use std::fs;
9
+ //!
10
+ //! let cert = fs::read("database_cert.pem").unwrap();
11
+ //! let cert = Certificate::from_pem(&cert).unwrap();
12
+ //! let connector = TlsConnector::builder()
13
+ //! .add_root_certificate(cert)
14
+ //! .build()
15
+ //! .unwrap();
16
+ //! let connector = MakeTlsConnector::new(connector);
17
+ //!
18
+ //! let connect_future = tokio_postgres::connect(
19
+ //! "host=localhost user=postgres sslmode=require",
20
+ //! connector,
21
+ //! );
22
+ //!
23
+ //! // ...
24
+ //! ```
25
+
26
+ #![ warn( rust_2018_idioms, clippy:: all, missing_docs) ]
2
27
3
28
use futures:: { try_ready, Async , Future , Poll } ;
4
29
use tokio_io:: { AsyncRead , AsyncWrite } ;
@@ -10,12 +35,16 @@ use tokio_tls::{Connect, TlsStream};
10
35
#[ cfg( test) ]
11
36
mod test;
12
37
38
+ /// A `MakeTlsConnect` implementation using the `native-tls` crate.
39
+ ///
40
+ /// Requires the `runtime` Cargo feature (enabled by default).
13
41
#[ cfg( feature = "runtime" ) ]
14
42
#[ derive( Clone ) ]
15
43
pub struct MakeTlsConnector ( native_tls:: TlsConnector ) ;
16
44
17
45
#[ cfg( feature = "runtime" ) ]
18
46
impl MakeTlsConnector {
47
+ /// Creates a new connector.
19
48
pub fn new ( connector : native_tls:: TlsConnector ) -> MakeTlsConnector {
20
49
MakeTlsConnector ( connector)
21
50
}
@@ -35,12 +64,14 @@ where
35
64
}
36
65
}
37
66
67
+ /// A `TlsConnect` implementation using the `native-tls` crate.
38
68
pub struct TlsConnector {
39
69
connector : tokio_tls:: TlsConnector ,
40
70
domain : String ,
41
71
}
42
72
43
73
impl TlsConnector {
74
+ /// Creates a new connector configured to connect to the specified domain.
44
75
pub fn new ( connector : native_tls:: TlsConnector , domain : & str ) -> TlsConnector {
45
76
TlsConnector {
46
77
connector : tokio_tls:: TlsConnector :: from ( connector) ,
62
93
}
63
94
}
64
95
96
+ /// The future returned by `TlsConnector`.
65
97
pub struct TlsConnectFuture < S > ( Connect < S > ) ;
66
98
67
99
impl < S > Future for TlsConnectFuture < S >
0 commit comments