Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native: Upgrade tokio and prepare 0.2 release #31

Merged
merged 1 commit into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tokio-native-tls/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
10 changes: 5 additions & 5 deletions tokio-native-tls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't want to link to 0.2.0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should auto link right?

description = """
An implementation of TLS/SSL streams for Tokio using native-tls giving an implementation of TLS
for nonblocking I/O streams.
Expand All @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion tokio-native-tls/examples/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ wget https://127.0.0.1:12345 --no-check-certificate
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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");
Expand Down
26 changes: 12 additions & 14 deletions tokio-native-tls/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -133,7 +132,9 @@ where
S: AsyncRead + Unpin,
{
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())
}
}

Expand Down Expand Up @@ -186,19 +187,16 @@ impl<S> AsyncRead for TlsStream<S>
where
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(
mut self: Pin<&mut Self>,
ctx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
self.with_context(ctx, |s| s.read(buf))
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
self.with_context(ctx, |s| {
let n = s.read(buf.initialize_unfilled())?;
buf.advance(n);
Ok(())
})
}
}

Expand Down
6 changes: 3 additions & 3 deletions tokio-native-tls/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down