4848#![ doc( html_root_url = "https://docs.rs/postgres-native-tls/0.3" ) ]
4949#![ warn( rust_2018_idioms, clippy:: all, missing_docs) ]
5050
51- use bytes:: { Buf , BufMut } ;
5251use std:: future:: Future ;
5352use std:: io;
54- use std:: mem:: MaybeUninit ;
5553use std:: pin:: Pin ;
5654use std:: task:: { Context , Poll } ;
57- use tokio:: io:: { AsyncRead , AsyncWrite } ;
55+ use tokio:: io:: { AsyncRead , AsyncWrite , ReadBuf } ;
5856use tokio_postgres:: tls;
5957#[ cfg( feature = "runtime" ) ]
6058use tokio_postgres:: tls:: MakeTlsConnect ;
@@ -94,15 +92,15 @@ where
9492
9593/// A `TlsConnect` implementation using the `native-tls` crate.
9694pub struct TlsConnector {
97- connector : tokio_tls :: TlsConnector ,
95+ connector : tokio_native_tls :: TlsConnector ,
9896 domain : String ,
9997}
10098
10199impl TlsConnector {
102100 /// Creates a new connector configured to connect to the specified domain.
103101 pub fn new ( connector : native_tls:: TlsConnector , domain : & str ) -> TlsConnector {
104102 TlsConnector {
105- connector : tokio_tls :: TlsConnector :: from ( connector) ,
103+ connector : tokio_native_tls :: TlsConnector :: from ( connector) ,
106104 domain : domain. to_string ( ) ,
107105 }
108106 }
@@ -129,34 +127,19 @@ where
129127}
130128
131129/// The stream returned by `TlsConnector`.
132- pub struct TlsStream < S > ( tokio_tls :: TlsStream < S > ) ;
130+ pub struct TlsStream < S > ( tokio_native_tls :: TlsStream < S > ) ;
133131
134132impl < S > AsyncRead for TlsStream < S >
135133where
136134 S : AsyncRead + AsyncWrite + Unpin ,
137135{
138- unsafe fn prepare_uninitialized_buffer ( & self , buf : & mut [ MaybeUninit < u8 > ] ) -> bool {
139- self . 0 . prepare_uninitialized_buffer ( buf)
140- }
141-
142136 fn poll_read (
143137 mut self : Pin < & mut Self > ,
144138 cx : & mut Context < ' _ > ,
145- buf : & mut [ u8 ] ,
146- ) -> Poll < io:: Result < usize > > {
139+ buf : & mut ReadBuf < ' _ > ,
140+ ) -> Poll < io:: Result < ( ) > > {
147141 Pin :: new ( & mut self . 0 ) . poll_read ( cx, buf)
148142 }
149-
150- fn poll_read_buf < B : BufMut > (
151- mut self : Pin < & mut Self > ,
152- cx : & mut Context < ' _ > ,
153- buf : & mut B ,
154- ) -> Poll < io:: Result < usize > >
155- where
156- Self : Sized ,
157- {
158- Pin :: new ( & mut self . 0 ) . poll_read_buf ( cx, buf)
159- }
160143}
161144
162145impl < S > AsyncWrite for TlsStream < S >
@@ -178,25 +161,16 @@ where
178161 fn poll_shutdown ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < io:: Result < ( ) > > {
179162 Pin :: new ( & mut self . 0 ) . poll_shutdown ( cx)
180163 }
181-
182- fn poll_write_buf < B : Buf > (
183- mut self : Pin < & mut Self > ,
184- cx : & mut Context < ' _ > ,
185- buf : & mut B ,
186- ) -> Poll < io:: Result < usize > >
187- where
188- Self : Sized ,
189- {
190- Pin :: new ( & mut self . 0 ) . poll_write_buf ( cx, buf)
191- }
192164}
193165
194166impl < S > tls:: TlsStream for TlsStream < S >
195167where
196168 S : AsyncRead + AsyncWrite + Unpin ,
197169{
198170 fn channel_binding ( & self ) -> ChannelBinding {
199- // FIXME https://github.com/tokio-rs/tokio/issues/1383
200- ChannelBinding :: none ( )
171+ match self . 0 . get_ref ( ) . tls_server_end_point ( ) . ok ( ) . flatten ( ) {
172+ Some ( buf) => ChannelBinding :: tls_server_end_point ( buf) ,
173+ None => ChannelBinding :: none ( ) ,
174+ }
201175 }
202176}
0 commit comments