From cf9ca1ffae89678a2b55d46cba305aa10da7f103 Mon Sep 17 00:00:00 2001 From: Constantin Nickel Date: Fri, 16 Oct 2020 14:14:35 +0200 Subject: [PATCH] Bring tokio's async-tls and rustls impls in line with the others --- src/tokio/async_tls.rs | 23 +++++++++++++++-------- src/tokio/rustls.rs | 8 ++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/tokio/async_tls.rs b/src/tokio/async_tls.rs index d233172..f2c156a 100644 --- a/src/tokio/async_tls.rs +++ b/src/tokio/async_tls.rs @@ -1,6 +1,19 @@ -use super::{Error, IntoClientRequest, Response, TokioAdapter, WebSocketConfig, WebSocketStream}; +use real_async_tls::client::TlsStream; +use real_async_tls::TlsConnector; + +use tungstenite::client::IntoClientRequest; +use tungstenite::Error; + use crate::stream::Stream as StreamSwitcher; -use std::marker::Unpin; +use crate::{Response, WebSocketConfig, WebSocketStream}; + +use super::TokioAdapter; + +pub type MaybeTlsStream = StreamSwitcher>; + +pub type AutoStream = MaybeTlsStream>; + +pub type Connector = TlsConnector; /// Creates a WebSocket handshake from a request and a stream, /// upgrading the stream to TLS if required and using the given @@ -24,9 +37,3 @@ where ) .await } - -pub type Connector = real_async_tls::TlsConnector; - -pub type MaybeTlsStream = StreamSwitcher>; - -pub type AutoStream = MaybeTlsStream>; diff --git a/src/tokio/rustls.rs b/src/tokio/rustls.rs index 7bfbd28..9c7d885 100644 --- a/src/tokio/rustls.rs +++ b/src/tokio/rustls.rs @@ -1,6 +1,6 @@ use real_tokio_rustls::rustls::ClientConfig; use real_tokio_rustls::webpki::DNSNameRef; -use real_tokio_rustls::{client::TlsStream, TlsConnector as AsyncTlsConnector}; +use real_tokio_rustls::{client::TlsStream, TlsConnector}; use tungstenite::client::{uri_mode, IntoClientRequest}; use tungstenite::handshake::client::Request; @@ -17,7 +17,7 @@ pub type MaybeTlsStream = StreamSwitcher, TokioAdapter = MaybeTlsStream; -pub type Connector = AsyncTlsConnector; +pub type Connector = TlsConnector; async fn wrap_stream( socket: S, @@ -39,7 +39,7 @@ where config .root_store .add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS); - AsyncTlsConnector::from(std::sync::Arc::new(config)) + TlsConnector::from(std::sync::Arc::new(config)) }; let domain = DNSNameRef::try_from_ascii_str(&domain) .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?; @@ -59,7 +59,7 @@ where pub async fn client_async_tls_with_connector_and_config( request: R, stream: S, - connector: Option, + connector: Option, config: Option, ) -> Result<(WebSocketStream>, Response), Error> where