Rename TLS feature flags from "use-*" to "*-tls"

pull/166/head
Dominik Nakamura 4 years ago
parent 8d1b6b73c6
commit 25fd0b8617
No known key found for this signature in database
GPG Key ID: E4C6A749B2491910
  1. 9
      Cargo.toml
  2. 4
      README.md
  3. 14
      src/client.rs
  4. 8
      src/error.rs
  5. 10
      src/stream.rs
  6. 8
      tests/connection_reset.rs

@ -17,9 +17,9 @@ all-features = true
[features] [features]
default = [] default = []
use-native-tls = ["native-tls"] native-tls = ["native-tls-crate"]
use-native-tls-vendored = ["use-native-tls", "native-tls/vendored"] native-tls-vendored = ["native-tls", "native-tls-crate/vendored"]
use-rustls = ["rustls", "webpki", "webpki-roots"] rustls-tls = ["rustls", "webpki", "webpki-roots"]
[dependencies] [dependencies]
base64 = "0.13.0" base64 = "0.13.0"
@ -35,8 +35,9 @@ thiserror = "1.0.23"
url = "2.1.0" url = "2.1.0"
utf-8 = "0.7.5" utf-8 = "0.7.5"
[dependencies.native-tls] [dependencies.native-tls-crate]
optional = true optional = true
package = "native-tls"
version = "0.2.3" version = "0.2.3"
[dependencies.rustls] [dependencies.rustls]

@ -54,8 +54,8 @@ Features
-------- --------
Tungstenite provides a complete implementation of the WebSocket specification. 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` TLS is supported on all platforms using native-tls or rustls available through the `native-tls`
and `use-rustls` feature flags. and `rustls-tls` feature flags.
There is no support for permessage-deflate at the moment. It's planned. There is no support for permessage-deflate at the moment. It's planned.

@ -16,10 +16,10 @@ use crate::{
protocol::WebSocketConfig, protocol::WebSocketConfig,
}; };
#[cfg(feature = "use-native-tls")] #[cfg(feature = "native-tls")]
mod encryption { mod encryption {
pub use native_tls::TlsStream; pub use native_tls_crate::TlsStream;
use native_tls::{HandshakeError as TlsHandshakeError, TlsConnector}; use native_tls_crate::{HandshakeError as TlsHandshakeError, TlsConnector};
use std::net::TcpStream; use std::net::TcpStream;
pub use crate::stream::Stream as StreamSwitcher; 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 { mod encryption {
use rustls::ClientConfig; use rustls::ClientConfig;
pub use rustls::{ClientSession, StreamOwned}; 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 { mod encryption {
use std::net::TcpStream; use std::net::TcpStream;
@ -116,7 +116,7 @@ use crate::{
/// equal to calling `connect()` function. /// equal to calling `connect()` function.
/// ///
/// The URL may be either ws:// or wss://. /// 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 /// 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 /// similar to `std::net::TcpStream`. If you want a non-blocking or other
@ -184,7 +184,7 @@ pub fn connect_with_config<Req: IntoClientRequest>(
/// Connect to the given WebSocket in blocking mode. /// Connect to the given WebSocket in blocking mode.
/// ///
/// The URL may be either ws:// or wss://. /// 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 /// 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 /// similar to `std::net::TcpStream`. If you want a non-blocking or other

@ -40,15 +40,15 @@ pub enum Error {
#[error("IO error: {0}")] #[error("IO error: {0}")]
Io(#[from] io::Error), Io(#[from] io::Error),
/// TLS error /// TLS error
#[cfg(feature = "use-native-tls")] #[cfg(feature = "native-tls")]
#[error("TLS (native-tls) error: {0}")] #[error("TLS (native-tls) error: {0}")]
TlsNative(#[from] native_tls::Error), TlsNative(#[from] native_tls_crate::Error),
/// TLS error /// TLS error
#[cfg(feature = "use-rustls")] #[cfg(feature = "rustls-tls")]
#[error("TLS (rustls) error: {0}")] #[error("TLS (rustls) error: {0}")]
TlsRustls(#[from] rustls::TLSError), TlsRustls(#[from] rustls::TLSError),
/// DNS name resolution error. /// DNS name resolution error.
#[cfg(feature = "use-rustls")] #[cfg(feature = "rustls-tls")]
#[error("Invalid DNS name: {0}")] #[error("Invalid DNS name: {0}")]
Dns(#[from] webpki::InvalidDNSNameError), Dns(#[from] webpki::InvalidDNSNameError),
/// - When reading: buffer capacity exhausted. /// - When reading: buffer capacity exhausted.

@ -8,9 +8,9 @@ use std::io::{Read, Result as IoResult, Write};
use std::net::TcpStream; use std::net::TcpStream;
#[cfg(feature = "use-native-tls")] #[cfg(feature = "native-tls")]
use native_tls::TlsStream; use native_tls_crate::TlsStream;
#[cfg(feature = "use-rustls")] #[cfg(feature = "rustls-tls")]
use rustls::StreamOwned; use rustls::StreamOwned;
/// Stream mode, either plain TCP or TLS. /// 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<S: Read + Write + NoDelay> NoDelay for TlsStream<S> { impl<S: Read + Write + NoDelay> NoDelay for TlsStream<S> {
fn set_nodelay(&mut self, nodelay: bool) -> IoResult<()> { fn set_nodelay(&mut self, nodelay: bool) -> IoResult<()> {
self.get_mut().set_nodelay(nodelay) self.get_mut().set_nodelay(nodelay)
} }
} }
#[cfg(feature = "use-rustls")] #[cfg(feature = "rustls-tls")]
impl<S: rustls::Session, T: Read + Write + NoDelay> NoDelay for StreamOwned<S, T> { impl<S: rustls::Session, T: Read + Write + NoDelay> NoDelay for StreamOwned<S, T> {
fn set_nodelay(&mut self, nodelay: bool) -> IoResult<()> { fn set_nodelay(&mut self, nodelay: bool) -> IoResult<()> {
self.sock.set_nodelay(nodelay) self.sock.set_nodelay(nodelay)

@ -1,6 +1,6 @@
//! Verifies that the server returns a `ConnectionClosed` error when the connection //! 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. //! 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::{ use std::{
net::{TcpListener, TcpStream}, net::{TcpListener, TcpStream},
@ -13,9 +13,9 @@ use net2::TcpStreamExt;
use tungstenite::{accept, connect, stream::Stream, Error, Message, WebSocket}; use tungstenite::{accept, connect, stream::Stream, Error, Message, WebSocket};
use url::Url; use url::Url;
#[cfg(feature = "use-native-tls")] #[cfg(feature = "native-tls")]
type Sock = WebSocket<Stream<TcpStream, native_tls::TlsStream<TcpStream>>>; type Sock = WebSocket<Stream<TcpStream, native_tls_crate::TlsStream<TcpStream>>>;
#[cfg(all(feature = "use-rustls", not(feature = "use-native-tls")))] #[cfg(all(feature = "rustls-tls", not(feature = "native-tls")))]
type Sock = WebSocket<Stream<TcpStream, rustls::StreamOwned<rustls::ClientSession, TcpStream>>>; type Sock = WebSocket<Stream<TcpStream, rustls::StreamOwned<rustls::ClientSession, TcpStream>>>;
fn do_test<CT, ST>(port: u16, client_task: CT, server_task: ST) fn do_test<CT, ST>(port: u16, client_task: CT, server_task: ST)

Loading…
Cancel
Save