diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c2c0161a..a9fc774a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,7 +55,7 @@ jobs: run: cargo test-all-features --verbose --lib --examples - name: Run doc tests - run: cargo test-all-features --verbose --lib --examples --doc + run: cargo test-all-features --verbose --doc - name: Run integration tests run: cargo test --verbose --features "async" --benches --tests diff --git a/Cargo.lock b/Cargo.lock index a39b2d1b..8fd4714a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,33 +112,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "aws-lc-rs" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f95446d919226d587817a7d21379e6eb099b97b45110a7f272a444ca5c54070" -dependencies = [ - "aws-lc-sys", - "mirai-annotations", - "paste", - "zeroize", -] - -[[package]] -name = "aws-lc-sys" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3ddc4a5b231dd6958b140ff3151b6412b3f4321fab354f399eec8f14b06df62" -dependencies = [ - "bindgen", - "cc", - "cmake", - "dunce", - "fs_extra", - "libc", - "paste", -] - [[package]] name = "backoff" version = "0.4.0" @@ -171,29 +144,6 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" -[[package]] -name = "bindgen" -version = "0.69.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" -dependencies = [ - "bitflags 2.6.0", - "cexpr", - "clang-sys", - "itertools", - "lazy_static", - "lazycell", - "log", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn 2.0.48", - "which", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -318,15 +268,6 @@ dependencies = [ "shlex", ] -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - [[package]] name = "cfg-if" version = "1.0.0" @@ -375,17 +316,6 @@ dependencies = [ "half", ] -[[package]] -name = "clang-sys" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" -dependencies = [ - "glob", - "libc", - "libloading", -] - [[package]] name = "clap" version = "2.34.0" @@ -426,15 +356,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" -[[package]] -name = "cmake" -version = "0.1.51" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb1e43aa7fd152b1f968787f7dbcdeb306d1867ff373c69955211876c053f91a" -dependencies = [ - "cc", -] - [[package]] name = "codespan-reporting" version = "0.11.1" @@ -696,12 +617,6 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "dunce" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" - [[package]] name = "either" version = "1.6.1" @@ -799,12 +714,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fs_extra" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" - [[package]] name = "futures" version = "0.3.17" @@ -947,12 +856,6 @@ dependencies = [ "url", ] -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - [[package]] name = "gzip-header" version = "0.3.0" @@ -1020,15 +923,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "home" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "http" version = "1.1.0" @@ -1115,7 +1009,7 @@ dependencies = [ "http", "hyper", "hyper-util", - "rustls 0.22.4", + "rustls", "rustls-pki-types", "tokio", "tokio-rustls", @@ -1289,12 +1183,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "libc" version = "0.2.158" @@ -1315,16 +1203,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "libloading" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" -dependencies = [ - "cfg-if", - "windows-targets 0.52.6", -] - [[package]] name = "libssh2-sys" version = "0.2.23" @@ -1433,12 +1311,6 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.6.2" @@ -1468,12 +1340,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "mirai-annotations" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9be0862c1b3f26a88803c4a49de6889c10e608b3ee9344e6ef5b45fb37ad3d1" - [[package]] name = "native-tls" version = "0.2.12" @@ -1504,16 +1370,6 @@ dependencies = [ "memoffset", ] -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "num-integer" version = "0.1.45" @@ -1650,12 +1506,6 @@ dependencies = [ "windows-targets 0.48.0", ] -[[package]] -name = "paste" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" - [[package]] name = "percent-encoding" version = "2.3.1" @@ -1734,16 +1584,6 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3ca011bd0129ff4ae15cd04c4eef202cadf6c51c21e47aba319b4e0501db741" -[[package]] -name = "prettyplease" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3928fb5db768cb86f891ff014f0144589297e3c6a1aba6ed7cecfdace270c7" -dependencies = [ - "proc-macro2", - "syn 2.0.48", -] - [[package]] name = "proc-macro2" version = "1.0.78" @@ -1913,7 +1753,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.22.4", + "rustls", "rustls-pemfile", "rustls-pki-types", "serde", @@ -1935,6 +1775,21 @@ dependencies = [ "winreg", ] +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin 0.5.2", + "untrusted 0.7.1", + "web-sys", + "winapi", +] + [[package]] name = "ring" version = "0.17.8" @@ -1945,8 +1800,8 @@ dependencies = [ "cfg-if", "getrandom", "libc", - "spin", - "untrusted", + "spin 0.9.8", + "untrusted 0.9.0", "windows-sys 0.52.0", ] @@ -1965,7 +1820,8 @@ dependencies = [ "lazy_static", "native-tls", "reqwest", - "rustls 0.22.4", + "rustls", + "rustls-pemfile", "serde", "serde_json", "thiserror", @@ -1973,6 +1829,7 @@ dependencies = [ "tokio-tungstenite", "tungstenite", "url", + "webpki", ] [[package]] @@ -1991,7 +1848,7 @@ dependencies = [ "native-tls", "rand", "rust_engineio", - "rustls 0.23.13", + "rustls", "serde", "serde_json", "serial_test", @@ -2006,12 +1863,6 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustc_version" version = "0.4.0" @@ -2055,22 +1906,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" dependencies = [ "log", - "ring", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls" -version = "0.23.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" -dependencies = [ - "aws-lc-rs", - "log", - "once_cell", + "ring 0.17.8", "rustls-pki-types", "rustls-webpki", "subtle", @@ -2112,10 +1948,9 @@ version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ - "aws-lc-rs", - "ring", + "ring 0.17.8", "rustls-pki-types", - "untrusted", + "untrusted 0.9.0", ] [[package]] @@ -2314,6 +2149,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "spin" version = "0.9.8" @@ -2527,7 +2368,7 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" dependencies = [ - "rustls 0.22.4", + "rustls", "rustls-pki-types", "tokio", ] @@ -2541,7 +2382,7 @@ dependencies = [ "futures-util", "log", "native-tls", - "rustls 0.22.4", + "rustls", "rustls-native-certs", "rustls-pki-types", "tokio", @@ -2673,7 +2514,7 @@ dependencies = [ "log", "native-tls", "rand", - "rustls 0.22.4", + "rustls", "rustls-pki-types", "sha1", "thiserror", @@ -2714,6 +2555,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "untrusted" version = "0.9.0" @@ -2878,24 +2725,22 @@ dependencies = [ ] [[package]] -name = "webpki-roots" -version = "0.26.6" +name = "webpki" +version = "0.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" dependencies = [ - "rustls-pki-types", + "ring 0.16.20", + "untrusted 0.7.1", ] [[package]] -name = "which" -version = "4.4.2" +name = "webpki-roots" +version = "0.26.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" dependencies = [ - "either", - "home", - "once_cell", - "rustix 0.38.25", + "rustls-pki-types", ] [[package]] diff --git a/engineio/Cargo.toml b/engineio/Cargo.toml index b091a5de..c5bf9b97 100644 --- a/engineio/Cargo.toml +++ b/engineio/Cargo.toml @@ -30,6 +30,10 @@ async-stream = "0.3.5" thiserror = "1.0" native-tls = { version = "^0.2", optional = true } rustls = { version = "^0.22", optional = true } +# rustls-pemfile is only needed for unit tests +rustls-pemfile = { version = "2", optional = true } +# webpki is only needed for unit tests +webpki = { version = "0.21", optional = true } url = "2.5.2" [dev-dependencies] @@ -61,7 +65,7 @@ rustls-tls-native-roots = ["tokio-tungstenite/rustls-tls-native-roots", "_rustls rustls-tls-webpki-roots = ["tokio-tungstenite/rustls-tls-webpki-roots", "_rustls-tls"] # These features are for internal use only _native-tls = ["dep:native-tls", "reqwest/native-tls"] -_rustls-tls = ["dep:rustls", "reqwest/rustls-tls"] +_rustls-tls = ["dep:rustls", "reqwest/rustls-tls", "dep:rustls-pemfile", "dep:webpki"] # This is an internal feature to allow us to build using cargo-all-features and guaranteing that we always have one TLS implementation # Do not use this feature directly diff --git a/engineio/src/asynchronous/async_transports/websocket_secure.rs b/engineio/src/asynchronous/async_transports/websocket_secure.rs index da13ca68..0e073152 100644 --- a/engineio/src/asynchronous/async_transports/websocket_secure.rs +++ b/engineio/src/asynchronous/async_transports/websocket_secure.rs @@ -61,7 +61,7 @@ impl WebsocketSecureTransport { #[cfg(feature = "_rustls-tls")] tls_config.map(Arc::new).map(Connector::Rustls), #[cfg(not(any(feature = "_native-tls", feature = "_rustls-tls")))] - None, + compile_error!("Either feature `_native-tls` or `_rustls-tls` must be enabled"), ) .await?; diff --git a/engineio/src/client/client.rs b/engineio/src/client/client.rs index 1c82003e..b37614de 100644 --- a/engineio/src/client/client.rs +++ b/engineio/src/client/client.rs @@ -376,7 +376,7 @@ impl<'a> Iterator for Iter<'a> { #[cfg(test)] mod test { - use crate::packet::PacketId; + use crate::{packet::PacketId, test::tls_connector}; use super::*; @@ -649,10 +649,7 @@ mod test { let _ = builder(url.clone()) .tls_config( - TlsConfig::builder() - .danger_accept_invalid_certs(true) - .build() - .unwrap(), + tls_connector()? ) .build()?; let _ = builder(url).headers(headers).build()?; diff --git a/engineio/src/lib.rs b/engineio/src/lib.rs index 467bb12e..3d92e4cc 100644 --- a/engineio/src/lib.rs +++ b/engineio/src/lib.rs @@ -99,13 +99,14 @@ pub use client::{Client, ClientBuilder}; pub use error::Error; pub use packet::{Packet, PacketId}; -// Re-export TLS configurations to make sockio integration easier +// Re-export TLS configurations. This is the same as the socket.io logic. +// Needed in both crates so the compiler can know this is a re-export. #[cfg(all(feature = "_native-tls", not(feature = "_rustls-tls")))] #[doc(hidden)] -pub use native_tls::TlsConnector as TlsConfig; +pub(crate) use native_tls::TlsConnector as TlsConfig; #[doc(hidden)] #[cfg(feature = "_rustls-tls")] -pub use rustls::ClientConfig as TlsConfig; +pub(crate) use rustls::ClientConfig as TlsConfig; // Both native-tls and rustls is not supported at the same time #[cfg(not(feature = "_fallback-tls"))] @@ -118,24 +119,39 @@ compile_error!("No TLS feature is enabled. Please enable either native-tls or ru #[cfg(test)] pub(crate) mod test { use super::*; + #[cfg(feature = "_native-tls")] use native_tls::TlsConnector; const CERT_PATH: &str = "../ci/cert/ca.crt"; + #[cfg(all(feature = "_native-tls", not(feature = "_rustls-tls")))] use native_tls::Certificate; use std::fs::File; use std::io::Read; - pub(crate) fn tls_connector() -> error::Result { + pub(crate) fn tls_connector() -> error::Result { let cert_path = std::env::var("CA_CERT_PATH").unwrap_or_else(|_| CERT_PATH.to_owned()); let mut cert_file = File::open(cert_path)?; let mut buf = vec![]; cert_file.read_to_end(&mut buf)?; - let cert: Certificate = Certificate::from_pem(&buf[..]).unwrap(); - Ok(TlsConnector::builder() - // ONLY USE FOR TESTING! - .danger_accept_invalid_hostnames(true) - .add_root_certificate(cert) - .build() - .unwrap()) + #[cfg(all(feature = "_native-tls", not(feature = "_rustls-tls")))] + { + let cert: Certificate = Certificate::from_pem(&buf[..]).unwrap(); + Ok(TlsConnector::builder() + // ONLY USE FOR TESTING! + .danger_accept_invalid_hostnames(true) + .add_root_certificate(cert) + .build() + .unwrap()) + } + #[cfg(feature = "_rustls-tls")] + { + let mut root_store = rustls::RootCertStore::empty(); + for cert in rustls_pemfile::certs(&mut buf.as_slice()) { + root_store.add(cert.expect("Invalid PEM cert")).expect("Failed to add cert to store"); + } + let mut config = rustls::ClientConfig::builder().with_root_certificates(root_store).with_no_client_auth(); + config.enable_sni = false; + Ok(config) + } } /// The `engine.io` server for testing runs on port 4201 const SERVER_URL: &str = "http://localhost:4201"; diff --git a/socketio/Cargo.toml b/socketio/Cargo.toml index 14b21913..230adbb7 100644 --- a/socketio/Cargo.toml +++ b/socketio/Cargo.toml @@ -29,7 +29,7 @@ async-stream = { version = "0.3.5", optional = true } log = "0.4.22" serde = "1.0.209" native-tls = { version = "0.2", optional = true } -rustls = { version = "0.23", optional = true } +rustls = { version = "0.22", optional = true } getrandom = "0.2.10" [dev-dependencies] @@ -61,6 +61,11 @@ name = "async" path = "examples/async.rs" required-features = ["async", "native-tls"] +[[example]] +name = "secure" +path = "examples/secure.rs" +required-features = ["native-tls"] + [lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin)'] } diff --git a/socketio/src/asynchronous/client/builder.rs b/socketio/src/asynchronous/client/builder.rs index 293bebe3..1b4f6cc1 100644 --- a/socketio/src/asynchronous/client/builder.rs +++ b/socketio/src/asynchronous/client/builder.rs @@ -3,12 +3,11 @@ use log::trace; use rust_engineio::{ asynchronous::ClientBuilder as EngineIoClientBuilder, header::{HeaderMap, HeaderValue}, - TlsConfig, }; use std::collections::HashMap; use url::Url; -use crate::{error::Result, Event, Payload, TransportType}; +use crate::{error::Result, Event, Payload, TransportType, TlsConfig}; use super::{ callback::{ diff --git a/socketio/src/client/builder.rs b/socketio/src/client/builder.rs index 6112f2a1..e7241d8e 100644 --- a/socketio/src/client/builder.rs +++ b/socketio/src/client/builder.rs @@ -1,10 +1,9 @@ use super::super::{event::Event, payload::Payload}; use super::callback::Callback; use super::client::Client; -use crate::RawClient; +use crate::{RawClient, TlsConfig}; use rust_engineio::client::ClientBuilder as EngineIoClientBuilder; use rust_engineio::header::{HeaderMap, HeaderValue}; -use rust_engineio::TlsConfig; use url::Url; use crate::client::callback::{SocketAnyCallback, SocketCallback}; diff --git a/socketio/src/client/raw_client.rs b/socketio/src/client/raw_client.rs index 0686683f..7dd93796 100644 --- a/socketio/src/client/raw_client.rs +++ b/socketio/src/client/raw_client.rs @@ -418,10 +418,24 @@ mod test { use super::*; use crate::{client::TransportType, payload::Payload, ClientBuilder}; use bytes::Bytes; - use native_tls::TlsConnector; use serde_json::json; use std::time::Duration; + #[cfg(feature = "_native-tls")] + fn tls_config() -> native_tls::TlsConnector { + native_tls::TlsConnector::builder() + .use_sni(true) + .build() + .expect("Found illegal configuration") + } + + #[cfg(feature = "_rustls-tls")] + fn tls_config() -> rustls::ClientConfig { + rustls::ClientConfig::builder() + .with_root_certificates(rustls::RootCertStore::empty()) + .with_no_client_auth() + } + #[test] fn socket_io_integration() -> Result<()> { let url = crate::test::socket_io_server(); @@ -474,14 +488,9 @@ mod test { // test socket build logic let socket_builder = ClientBuilder::new(url); - let tls_connector = TlsConnector::builder() - .use_sni(true) - .build() - .expect("Found illegal configuration"); - let socket = socket_builder .namespace("/admin") - .tls_config(tls_connector) + .tls_config(tls_config()) .opening_header("accept-encoding", "application/json") .on("test", |str, _| println!("Received: {:#?}", str)) .on("message", |payload, _| println!("{:#?}", payload)) @@ -515,14 +524,9 @@ mod test { // test socket build logic let socket_builder = ClientBuilder::new(url); - let tls_connector = TlsConnector::builder() - .use_sni(true) - .build() - .expect("Found illegal configuration"); - let socket = socket_builder .namespace("/admin") - .tls_config(tls_connector) + .tls_config(tls_config()) .opening_header("accept-encoding", "application/json") .on("test", |str, _| println!("Received: {:#?}", str)) .on("message", |payload, _| println!("{:#?}", payload)) diff --git a/socketio/src/lib.rs b/socketio/src/lib.rs index b913eb4d..f3ca50b4 100644 --- a/socketio/src/lib.rs +++ b/socketio/src/lib.rs @@ -199,6 +199,23 @@ pub use client::{ClientBuilder, RawClient, TransportType}; #[deprecated(since = "0.3.0-alpha-2", note = "Socket renamed to Client")] pub use client::{ClientBuilder as SocketBuilder, RawClient as Socket}; +// Re-export TLS configurations. This is the same as the engine.io logic. +// Needed here so it knows it's actually a re-import, not a new type. +#[cfg(all(feature = "_native-tls", not(feature = "_rustls-tls")))] +#[doc(hidden)] +pub use native_tls::TlsConnector as TlsConfig; +#[doc(hidden)] +#[cfg(feature = "_rustls-tls")] +pub use rustls::ClientConfig as TlsConfig; + +// Both native-tls and rustls is not supported at the same time +#[cfg(not(feature = "_fallback-tls"))] +#[cfg(all(feature = "_native-tls", feature = "_rustls-tls"))] +compile_error!("Both native-tls and rustls features are enabled. Please enable only one of them."); + +#[cfg(not(any(feature = "_native-tls", feature = "_rustls-tls")))] +compile_error!("No TLS feature is enabled. Please enable either native-tls or rustls."); + #[cfg(test)] pub(crate) mod test { use url::Url;