tokio-rustls: release 0.14.0 (#17)
* tokio-rustls: release 0.14.0 * Fix writev * Fix fmt
This commit is contained in:
parent
fc90b3f378
commit
c2dd82e323
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tokio-rustls"
|
||||
version = "0.13.1"
|
||||
version = "0.14.0"
|
||||
authors = ["quininer kel <quininer@live.com>"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/tokio-rs/tls"
|
||||
@ -14,7 +14,7 @@ edition = "2018"
|
||||
[dependencies]
|
||||
tokio = "0.2.0"
|
||||
futures-core = "0.3.1"
|
||||
rustls = "0.17"
|
||||
rustls = "0.18"
|
||||
webpki = "0.21"
|
||||
|
||||
bytes = { version = "0.5", optional = true }
|
||||
@ -28,4 +28,4 @@ unstable = ["bytes"]
|
||||
tokio = { version = "0.2.0", features = ["macros", "net", "io-util", "rt-core", "time"] }
|
||||
futures-util = "0.3.1"
|
||||
lazy_static = "1"
|
||||
webpki-roots = "0.19"
|
||||
webpki-roots = "0.20"
|
||||
|
@ -107,6 +107,7 @@ where
|
||||
let mut stream =
|
||||
Stream::new(&mut this.io, &mut this.session).set_eof(!this.state.readable());
|
||||
|
||||
#[allow(clippy::match_single_binding)]
|
||||
match this.state {
|
||||
#[cfg(feature = "early-data")]
|
||||
TlsState::EarlyData(ref mut pos, ref mut data) => {
|
||||
|
@ -6,7 +6,7 @@ mod vecbuf;
|
||||
use futures_core as futures;
|
||||
pub(crate) use handshake::{IoSession, MidHandshake};
|
||||
use rustls::Session;
|
||||
use std::io::{self, Read};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
@ -103,6 +103,7 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> Stream<'a, IO, S> {
|
||||
}
|
||||
|
||||
impl<'a, 'b, T: AsyncRead + Unpin> Read for Reader<'a, 'b, T> {
|
||||
#[inline]
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
match Pin::new(&mut self.io).poll_read(self.cx, buf) {
|
||||
Poll::Ready(result) => result,
|
||||
@ -131,9 +132,9 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> Stream<'a, IO, S> {
|
||||
Poll::Ready(Ok(n))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "unstable"))]
|
||||
pub fn write_io(&mut self, cx: &mut Context) -> Poll<io::Result<usize>> {
|
||||
use std::io::Write;
|
||||
#[cfg(feature = "unstable")]
|
||||
use std::io::IoSlice;
|
||||
|
||||
struct Writer<'a, 'b, T> {
|
||||
io: &'a mut T,
|
||||
@ -141,6 +142,7 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> Stream<'a, IO, S> {
|
||||
}
|
||||
|
||||
impl<'a, 'b, T: AsyncWrite + Unpin> Write for Writer<'a, 'b, T> {
|
||||
#[inline]
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
match Pin::new(&mut self.io).poll_write(self.cx, buf) {
|
||||
Poll::Ready(result) => result,
|
||||
@ -148,6 +150,19 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> Stream<'a, IO, S> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[inline]
|
||||
fn write_vectored(&mut self, bufs: &[IoSlice]) -> io::Result<usize> {
|
||||
use vecbuf::VecBuf;
|
||||
|
||||
let mut vbuf = VecBuf::new(bufs);
|
||||
|
||||
match Pin::new(&mut self.io).poll_write_buf(self.cx, &mut vbuf) {
|
||||
Poll::Ready(result) => result,
|
||||
Poll::Pending => Err(io::ErrorKind::WouldBlock.into()),
|
||||
}
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> io::Result<()> {
|
||||
match Pin::new(&mut self.io).poll_flush(self.cx) {
|
||||
Poll::Ready(result) => result,
|
||||
@ -164,36 +179,6 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> Stream<'a, IO, S> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
pub fn write_io(&mut self, cx: &mut Context) -> Poll<io::Result<usize>> {
|
||||
use rustls::WriteV;
|
||||
|
||||
struct Writer<'a, 'b, T> {
|
||||
io: &'a mut T,
|
||||
cx: &'a mut Context<'b>,
|
||||
}
|
||||
|
||||
impl<'a, 'b, T: AsyncWrite + Unpin> WriteV for Writer<'a, 'b, T> {
|
||||
fn writev(&mut self, vbuf: &[&[u8]]) -> io::Result<usize> {
|
||||
use vecbuf::VecBuf;
|
||||
|
||||
let mut vbuf = VecBuf::new(vbuf);
|
||||
|
||||
match Pin::new(&mut self.io).poll_write_buf(self.cx, &mut vbuf) {
|
||||
Poll::Ready(result) => result,
|
||||
Poll::Pending => Err(io::ErrorKind::WouldBlock.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut writer = Writer { io: self.io, cx };
|
||||
|
||||
match self.session.writev_tls(&mut writer) {
|
||||
Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => Poll::Pending,
|
||||
result => Poll::Ready(result),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handshake(&mut self, cx: &mut Context) -> Poll<io::Result<(usize, usize)>> {
|
||||
let mut wrlen = 0;
|
||||
let mut rdlen = 0;
|
||||
|
@ -2,14 +2,14 @@ use bytes::Buf;
|
||||
use std::cmp::{self, Ordering};
|
||||
use std::io::IoSlice;
|
||||
|
||||
pub struct VecBuf<'a, 'b: 'a> {
|
||||
pub struct VecBuf<'a> {
|
||||
pos: usize,
|
||||
cur: usize,
|
||||
inner: &'a [&'b [u8]],
|
||||
inner: &'a [IoSlice<'a>],
|
||||
}
|
||||
|
||||
impl<'a, 'b> VecBuf<'a, 'b> {
|
||||
pub fn new(vbytes: &'a [&'b [u8]]) -> Self {
|
||||
impl<'a> VecBuf<'a> {
|
||||
pub fn new(vbytes: &'a [IoSlice<'a>]) -> Self {
|
||||
VecBuf {
|
||||
pos: 0,
|
||||
cur: 0,
|
||||
@ -18,7 +18,7 @@ impl<'a, 'b> VecBuf<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> Buf for VecBuf<'a, 'b> {
|
||||
impl<'a> Buf for VecBuf<'a> {
|
||||
fn remaining(&self) -> usize {
|
||||
let sum = self
|
||||
.inner
|
||||
@ -56,6 +56,7 @@ impl<'a, 'b> Buf for VecBuf<'a, 'b> {
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_range_loop)]
|
||||
#[inline]
|
||||
fn bytes_vectored<'c>(&'c self, dst: &mut [IoSlice<'c>]) -> usize {
|
||||
let len = cmp::min(self.inner.len() - self.pos, dst.len());
|
||||
|
||||
@ -64,7 +65,7 @@ impl<'a, 'b> Buf for VecBuf<'a, 'b> {
|
||||
}
|
||||
|
||||
for i in 1..len {
|
||||
dst[i] = IoSlice::new(&self.inner[self.pos + i]);
|
||||
dst[i] = self.inner[self.pos + i];
|
||||
}
|
||||
|
||||
len
|
||||
@ -77,7 +78,8 @@ mod test_vecbuf {
|
||||
|
||||
#[test]
|
||||
fn test_fresh_cursor_vec() {
|
||||
let mut buf = VecBuf::new(&[b"he", b"llo"]);
|
||||
let buf = [IoSlice::new(b"he"), IoSlice::new(b"llo")];
|
||||
let mut buf = VecBuf::new(&buf);
|
||||
|
||||
assert_eq!(buf.remaining(), 5);
|
||||
assert_eq!(buf.bytes(), b"he");
|
||||
@ -100,28 +102,33 @@ mod test_vecbuf {
|
||||
|
||||
#[test]
|
||||
fn test_get_u8() {
|
||||
let mut buf = VecBuf::new(&[b"\x21z", b"omg"]);
|
||||
let buf = [IoSlice::new(b"\x21z"), IoSlice::new(b"omg")];
|
||||
let mut buf = VecBuf::new(&buf);
|
||||
assert_eq!(0x21, buf.get_u8());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_u16() {
|
||||
let mut buf = VecBuf::new(&[b"\x21\x54z", b"omg"]);
|
||||
let buf = [IoSlice::new(b"\x21\x54z"), IoSlice::new(b"omg")];
|
||||
let mut buf = VecBuf::new(&buf);
|
||||
assert_eq!(0x2154, buf.get_u16());
|
||||
let mut buf = VecBuf::new(&[b"\x21\x54z", b"omg"]);
|
||||
let buf = [IoSlice::new(b"\x21\x54z"), IoSlice::new(b"omg")];
|
||||
let mut buf = VecBuf::new(&buf);
|
||||
assert_eq!(0x5421, buf.get_u16_le());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_get_u16_buffer_underflow() {
|
||||
let mut buf = VecBuf::new(&[b"\x21"]);
|
||||
let buf = [IoSlice::new(b"\x21")];
|
||||
let mut buf = VecBuf::new(&buf);
|
||||
buf.get_u16();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bufs_vec() {
|
||||
let buf = VecBuf::new(&[b"he", b"llo"]);
|
||||
let buf = [IoSlice::new(b"he"), IoSlice::new(b"llo")];
|
||||
let buf = VecBuf::new(&buf);
|
||||
|
||||
let b1: &[u8] = &mut [0];
|
||||
let b2: &[u8] = &mut [0];
|
||||
|
Loading…
Reference in New Issue
Block a user