From 25fd0b8617f5ec47602c8f04f9c04a03663dd109 Mon Sep 17 00:00:00 2001 From: Dominik Nakamura Date: Sat, 6 Feb 2021 12:11:12 +0900 Subject: [PATCH] Rename TLS feature flags from "use-*" to "*-tls" --- Cargo.toml | 9 +++++---- README.md | 4 ++-- src/client.rs | 14 +++++++------- src/error.rs | 8 ++++---- src/stream.rs | 10 +++++----- tests/connection_reset.rs | 8 ++++---- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 36fd643..93a0637 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,9 +17,9 @@ all-features = true [features] default = [] -use-native-tls = ["native-tls"] -use-native-tls-vendored = ["use-native-tls", "native-tls/vendored"] -use-rustls = ["rustls", "webpki", "webpki-roots"] +native-tls = ["native-tls-crate"] +native-tls-vendored = ["native-tls", "native-tls-crate/vendored"] +rustls-tls = ["rustls", "webpki", "webpki-roots"] [dependencies] base64 = "0.13.0" @@ -35,8 +35,9 @@ thiserror = "1.0.23" url = "2.1.0" utf-8 = "0.7.5" -[dependencies.native-tls] +[dependencies.native-tls-crate] optional = true +package = "native-tls" version = "0.2.3" [dependencies.rustls] diff --git a/README.md b/README.md index 1a85643..430f3b7 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,8 @@ Features -------- Tungstenite provides a complete implementation of the WebSocket specification. -TLS is supported on all platforms using native-tls or rustls available through the `use-native-tls` -and `use-rustls` feature flags. +TLS is supported on all platforms using native-tls or rustls available through the `native-tls` +and `rustls-tls` feature flags. There is no support for permessage-deflate at the moment. It's planned. diff --git a/src/client.rs b/src/client.rs index 0b20201..096663a 100644 --- a/src/client.rs +++ b/src/client.rs @@ -16,10 +16,10 @@ use crate::{ protocol::WebSocketConfig, }; -#[cfg(feature = "use-native-tls")] +#[cfg(feature = "native-tls")] mod encryption { - pub use native_tls::TlsStream; - use native_tls::{HandshakeError as TlsHandshakeError, TlsConnector}; + pub use native_tls_crate::TlsStream; + use native_tls_crate::{HandshakeError as TlsHandshakeError, TlsConnector}; use std::net::TcpStream; pub use crate::stream::Stream as StreamSwitcher; @@ -47,7 +47,7 @@ mod encryption { } } -#[cfg(all(feature = "use-rustls", not(feature = "use-native-tls")))] +#[cfg(all(feature = "rustls-tls", not(feature = "native-tls")))] mod encryption { use rustls::ClientConfig; pub use rustls::{ClientSession, StreamOwned}; @@ -80,7 +80,7 @@ mod encryption { } } -#[cfg(not(any(feature = "use-native-tls", feature = "use-rustls")))] +#[cfg(not(any(feature = "native-tls", feature = "rustls-tls")))] mod encryption { use std::net::TcpStream; @@ -116,7 +116,7 @@ use crate::{ /// equal to calling `connect()` function. /// /// The URL may be either ws:// or wss://. -/// To support wss:// URLs, feature `use-native-tls` or `use-rustls` must be turned on. +/// To support wss:// URLs, feature `native-tls` or `rustls-tls` must be turned on. /// /// This function "just works" for those who wants a simple blocking solution /// similar to `std::net::TcpStream`. If you want a non-blocking or other @@ -184,7 +184,7 @@ pub fn connect_with_config( /// Connect to the given WebSocket in blocking mode. /// /// The URL may be either ws:// or wss://. -/// To support wss:// URLs, feature `use-native-tls` or `use-rustls` must be turned on. +/// To support wss:// URLs, feature `native-tls` or `rustls-tls` must be turned on. /// /// This function "just works" for those who wants a simple blocking solution /// similar to `std::net::TcpStream`. If you want a non-blocking or other diff --git a/src/error.rs b/src/error.rs index 65702b2..313c929 100644 --- a/src/error.rs +++ b/src/error.rs @@ -40,15 +40,15 @@ pub enum Error { #[error("IO error: {0}")] Io(#[from] io::Error), /// TLS error - #[cfg(feature = "use-native-tls")] + #[cfg(feature = "native-tls")] #[error("TLS (native-tls) error: {0}")] - TlsNative(#[from] native_tls::Error), + TlsNative(#[from] native_tls_crate::Error), /// TLS error - #[cfg(feature = "use-rustls")] + #[cfg(feature = "rustls-tls")] #[error("TLS (rustls) error: {0}")] TlsRustls(#[from] rustls::TLSError), /// DNS name resolution error. - #[cfg(feature = "use-rustls")] + #[cfg(feature = "rustls-tls")] #[error("Invalid DNS name: {0}")] Dns(#[from] webpki::InvalidDNSNameError), /// - When reading: buffer capacity exhausted. diff --git a/src/stream.rs b/src/stream.rs index 09c3d3a..4d60405 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -8,9 +8,9 @@ use std::io::{Read, Result as IoResult, Write}; use std::net::TcpStream; -#[cfg(feature = "use-native-tls")] -use native_tls::TlsStream; -#[cfg(feature = "use-rustls")] +#[cfg(feature = "native-tls")] +use native_tls_crate::TlsStream; +#[cfg(feature = "rustls-tls")] use rustls::StreamOwned; /// Stream mode, either plain TCP or TLS. @@ -34,14 +34,14 @@ impl NoDelay for TcpStream { } } -#[cfg(feature = "use-native-tls")] +#[cfg(feature = "native-tls")] impl NoDelay for TlsStream { fn set_nodelay(&mut self, nodelay: bool) -> IoResult<()> { self.get_mut().set_nodelay(nodelay) } } -#[cfg(feature = "use-rustls")] +#[cfg(feature = "rustls-tls")] impl NoDelay for StreamOwned { fn set_nodelay(&mut self, nodelay: bool) -> IoResult<()> { self.sock.set_nodelay(nodelay) diff --git a/tests/connection_reset.rs b/tests/connection_reset.rs index b83bcb9..7f625be 100644 --- a/tests/connection_reset.rs +++ b/tests/connection_reset.rs @@ -1,6 +1,6 @@ //! Verifies that the server returns a `ConnectionClosed` error when the connection //! is closed from the server's point of view and drop the underlying tcp socket. -#![cfg(any(feature = "use-native-tls", feature = "use-rustls"))] +#![cfg(any(feature = "native-tls", feature = "rustls-tls"))] use std::{ net::{TcpListener, TcpStream}, @@ -13,9 +13,9 @@ use net2::TcpStreamExt; use tungstenite::{accept, connect, stream::Stream, Error, Message, WebSocket}; use url::Url; -#[cfg(feature = "use-native-tls")] -type Sock = WebSocket>>; -#[cfg(all(feature = "use-rustls", not(feature = "use-native-tls")))] +#[cfg(feature = "native-tls")] +type Sock = WebSocket>>; +#[cfg(all(feature = "rustls-tls", not(feature = "native-tls")))] type Sock = WebSocket>>; fn do_test(port: u16, client_task: CT, server_task: ST)