diff --git a/tokio-native-tls/CHANGELOG.md b/tokio-native-tls/CHANGELOG.md index bd1aa9d..1c00514 100644 --- a/tokio-native-tls/CHANGELOG.md +++ b/tokio-native-tls/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.2.0 (October 16, 2020) + +- Upgrade to `tokio 0.3`. + # 0.1.0 (January 9th, 2019) - Initial release from `tokio-tls 0.3` diff --git a/tokio-native-tls/Cargo.toml b/tokio-native-tls/Cargo.toml index f69c2b3..86fe751 100644 --- a/tokio-native-tls/Cargo.toml +++ b/tokio-native-tls/Cargo.toml @@ -8,13 +8,13 @@ name = "tokio-native-tls" # - README.md # - Update CHANGELOG.md. # - Create "v0.1.x" git tag. -version = "0.1.0" +version = "0.2.0" edition = "2018" authors = ["Tokio Contributors "] license = "MIT" repository = "https://github.com/tokio-rs/tls" homepage = "https://tokio.rs" -documentation = "https://docs.rs/tokio-native-tls/0.1.0/tokio_native_tls/" +documentation = "https://docs.rs/tokio-native-tls" description = """ An implementation of TLS/SSL streams for Tokio using native-tls giving an implementation of TLS for nonblocking I/O streams. @@ -23,11 +23,11 @@ categories = ["asynchronous", "network-programming"] [dependencies] native-tls = "0.2" -tokio = { version = "0.2.0" } +tokio = "0.3" [dev-dependencies] -tokio = { version = "0.2.0", features = ["macros", "stream", "rt-core", "io-util", "net"] } -tokio-util = { version = "0.2.0", features = ["full"] } +tokio = { version = "0.3.0", features = ["macros", "stream", "rt", "rt-multi-thread", "io-util", "net"] } +tokio-util = { version = "0.4.0", features = ["full"] } cfg-if = "0.1" env_logger = { version = "0.6", default-features = false } diff --git a/tokio-native-tls/examples/echo.rs b/tokio-native-tls/examples/echo.rs index 2887c6f..c97207d 100644 --- a/tokio-native-tls/examples/echo.rs +++ b/tokio-native-tls/examples/echo.rs @@ -16,7 +16,7 @@ wget https://127.0.0.1:12345 --no-check-certificate async fn main() -> Result<(), Box> { // Bind the server's socket let addr = "127.0.0.1:12345".to_string(); - let mut tcp: TcpListener = TcpListener::bind(&addr).await?; + let tcp: TcpListener = TcpListener::bind(&addr).await?; // Create the TLS acceptor. let der = include_bytes!("identity.p12"); diff --git a/tokio-native-tls/src/lib.rs b/tokio-native-tls/src/lib.rs index 6b64280..030b611 100644 --- a/tokio-native-tls/src/lib.rs +++ b/tokio-native-tls/src/lib.rs @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/tokio-native-tls/0.1.0")] +#![doc(html_root_url = "https://docs.rs/tokio-native-tls/0.2.0")] #![warn( missing_debug_implementations, missing_docs, @@ -28,14 +28,13 @@ //! built. Configuration of TLS parameters is still primarily done through the //! `native-tls` crate. -use tokio::io::{AsyncRead, AsyncWrite}; +use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; use crate::native_tls::{Error, HandshakeError, MidHandshakeTlsStream}; use std::fmt; use std::future::Future; use std::io::{self, Read, Write}; use std::marker::Unpin; -use std::mem::MaybeUninit; use std::pin::Pin; use std::ptr::null_mut; use std::task::{Context, Poll}; @@ -133,7 +132,9 @@ where S: AsyncRead + Unpin, { fn read(&mut self, buf: &mut [u8]) -> io::Result { - self.with_context(|ctx, stream| stream.poll_read(ctx, buf)) + let mut buf = ReadBuf::new(buf); + self.with_context(|ctx, stream| stream.poll_read(ctx, &mut buf))?; + Ok(buf.filled().len()) } } @@ -186,19 +187,16 @@ impl AsyncRead for TlsStream where S: AsyncRead + AsyncWrite + Unpin, { - unsafe fn prepare_uninitialized_buffer(&self, _: &mut [MaybeUninit]) -> bool { - // Note that this does not forward to `S` because the buffer is - // unconditionally filled in by OpenSSL, not the actual object `S`. - // We're decrypting bytes from `S` into the buffer above! - false - } - fn poll_read( mut self: Pin<&mut Self>, ctx: &mut Context<'_>, - buf: &mut [u8], - ) -> Poll> { - self.with_context(ctx, |s| s.read(buf)) + buf: &mut ReadBuf<'_>, + ) -> Poll> { + self.with_context(ctx, |s| { + let n = s.read(buf.initialize_unfilled())?; + buf.advance(n); + Ok(()) + }) } } diff --git a/tokio-native-tls/tests/smoke.rs b/tokio-native-tls/tests/smoke.rs index 058179a..f7fe60e 100644 --- a/tokio-native-tls/tests/smoke.rs +++ b/tokio-native-tls/tests/smoke.rs @@ -29,7 +29,7 @@ lazy_static! { #[tokio::test] async fn client_to_server() { - let mut srv = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let srv = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = srv.local_addr().unwrap(); let (server_tls, client_tls) = context(); @@ -69,7 +69,7 @@ async fn client_to_server() { #[tokio::test] async fn server_to_client() { // Create a server listening on a port, then figure out what that port is - let mut srv = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let srv = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = srv.local_addr().unwrap(); let (server_tls, client_tls) = context(); @@ -97,7 +97,7 @@ async fn server_to_client() { async fn one_byte_at_a_time() { const AMT: usize = 1024; - let mut srv = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let srv = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = srv.local_addr().unwrap(); let (server_tls, client_tls) = context();