native: Upgrade tokio and prepare 0.2 release (#31)

This commit is contained in:
Lucio Franco 2020-10-16 11:02:29 -04:00 committed by GitHub
parent e6ef54641b
commit a517e1d0a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 23 deletions

View File

@ -1,3 +1,7 @@
# 0.2.0 (October 16, 2020)
- Upgrade to `tokio 0.3`.
# 0.1.0 (January 9th, 2019) # 0.1.0 (January 9th, 2019)
- Initial release from `tokio-tls 0.3` - Initial release from `tokio-tls 0.3`

View File

@ -8,13 +8,13 @@ name = "tokio-native-tls"
# - README.md # - README.md
# - Update CHANGELOG.md. # - Update CHANGELOG.md.
# - Create "v0.1.x" git tag. # - Create "v0.1.x" git tag.
version = "0.1.0" version = "0.2.0"
edition = "2018" edition = "2018"
authors = ["Tokio Contributors <team@tokio.rs>"] authors = ["Tokio Contributors <team@tokio.rs>"]
license = "MIT" license = "MIT"
repository = "https://github.com/tokio-rs/tls" repository = "https://github.com/tokio-rs/tls"
homepage = "https://tokio.rs" 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 = """ description = """
An implementation of TLS/SSL streams for Tokio using native-tls giving an implementation of TLS An implementation of TLS/SSL streams for Tokio using native-tls giving an implementation of TLS
for nonblocking I/O streams. for nonblocking I/O streams.
@ -23,11 +23,11 @@ categories = ["asynchronous", "network-programming"]
[dependencies] [dependencies]
native-tls = "0.2" native-tls = "0.2"
tokio = { version = "0.2.0" } tokio = "0.3"
[dev-dependencies] [dev-dependencies]
tokio = { version = "0.2.0", features = ["macros", "stream", "rt-core", "io-util", "net"] } tokio = { version = "0.3.0", features = ["macros", "stream", "rt", "rt-multi-thread", "io-util", "net"] }
tokio-util = { version = "0.2.0", features = ["full"] } tokio-util = { version = "0.4.0", features = ["full"] }
cfg-if = "0.1" cfg-if = "0.1"
env_logger = { version = "0.6", default-features = false } env_logger = { version = "0.6", default-features = false }

View File

@ -16,7 +16,7 @@ wget https://127.0.0.1:12345 --no-check-certificate
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Bind the server's socket // Bind the server's socket
let addr = "127.0.0.1:12345".to_string(); 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. // Create the TLS acceptor.
let der = include_bytes!("identity.p12"); let der = include_bytes!("identity.p12");

View File

@ -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( #![warn(
missing_debug_implementations, missing_debug_implementations,
missing_docs, missing_docs,
@ -28,14 +28,13 @@
//! built. Configuration of TLS parameters is still primarily done through the //! built. Configuration of TLS parameters is still primarily done through the
//! `native-tls` crate. //! `native-tls` crate.
use tokio::io::{AsyncRead, AsyncWrite}; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use crate::native_tls::{Error, HandshakeError, MidHandshakeTlsStream}; use crate::native_tls::{Error, HandshakeError, MidHandshakeTlsStream};
use std::fmt; use std::fmt;
use std::future::Future; use std::future::Future;
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
use std::marker::Unpin; use std::marker::Unpin;
use std::mem::MaybeUninit;
use std::pin::Pin; use std::pin::Pin;
use std::ptr::null_mut; use std::ptr::null_mut;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
@ -133,7 +132,9 @@ where
S: AsyncRead + Unpin, S: AsyncRead + Unpin,
{ {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
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<S> AsyncRead for TlsStream<S>
where where
S: AsyncRead + AsyncWrite + Unpin, S: AsyncRead + AsyncWrite + Unpin,
{ {
unsafe fn prepare_uninitialized_buffer(&self, _: &mut [MaybeUninit<u8>]) -> 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( fn poll_read(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
ctx: &mut Context<'_>, ctx: &mut Context<'_>,
buf: &mut [u8], buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<usize>> { ) -> Poll<io::Result<()>> {
self.with_context(ctx, |s| s.read(buf)) self.with_context(ctx, |s| {
let n = s.read(buf.initialize_unfilled())?;
buf.advance(n);
Ok(())
})
} }
} }

View File

@ -29,7 +29,7 @@ lazy_static! {
#[tokio::test] #[tokio::test]
async fn client_to_server() { 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 addr = srv.local_addr().unwrap();
let (server_tls, client_tls) = context(); let (server_tls, client_tls) = context();
@ -69,7 +69,7 @@ async fn client_to_server() {
#[tokio::test] #[tokio::test]
async fn server_to_client() { async fn server_to_client() {
// Create a server listening on a port, then figure out what that port is // 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 addr = srv.local_addr().unwrap();
let (server_tls, client_tls) = context(); let (server_tls, client_tls) = context();
@ -97,7 +97,7 @@ async fn server_to_client() {
async fn one_byte_at_a_time() { async fn one_byte_at_a_time() {
const AMT: usize = 1024; 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 addr = srv.local_addr().unwrap();
let (server_tls, client_tls) = context(); let (server_tls, client_tls) = context();