Skip to content

Commit

Permalink
Merge pull request #3 from get10101/fix-compile-tls
Browse files Browse the repository at this point in the history
fix: allow TLS features to compile
  • Loading branch information
TannerRogalsky authored Feb 22, 2024
2 parents bf36e07 + d844e8e commit 5b02957
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tokio-tungstenite-wasm"
version = "0.2.0"
version = "0.2.1"
description = "A wrapper around websys and tokio-tungstenite that makes it easy to use websockets cross-platform."
repository = "https://github.com/TannerRogalsky/tokio-tungstenite-wasm"
homepage = "https://github.com/TannerRogalsky/tokio-tungstenite-wasm"
Expand All @@ -9,7 +9,7 @@ readme = "README.md"
edition = "2018"

[features]
native-tls = ["tokio-tungstenite/native-tls"]
native-tls = ["tokio-tungstenite/native-tls", "dep:native-tls"]
native-tls-vendored = ["native-tls", "tokio-tungstenite/native-tls-vendored"]
rustls-tls-native-roots = [
"__rustls-tls",
Expand All @@ -19,7 +19,7 @@ rustls-tls-webpki-roots = [
"__rustls-tls",
"tokio-tungstenite/rustls-tls-webpki-roots",
]
__rustls-tls = []
__rustls-tls = ["dep:rustls"]

[dependencies]
thiserror = "1"
Expand All @@ -30,9 +30,13 @@ futures-util = { version = "0.3", default-features = false, features = [
"std",
] }


[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio-tungstenite = "0.20"
tokio = { version = "1", default-features = false, features = ["net"] }
native-tls = { version = "0.2.11", default-features = false, optional = true }
rustls = { version = "0.21.6", default-features = false, optional = true }


[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"
Expand Down
12 changes: 4 additions & 8 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,19 +261,15 @@ pub enum UrlError {
#[non_exhaustive]
pub enum TlsError {
/// Native TLS error.
#[cfg(feature = "native-tls")]
#[cfg(all(feature = "native-tls", not(target_arch = "wasm32")))]
#[error("native-tls error: {0}")]
Native(#[from] native_tls_crate::Error),
Native(#[from] native_tls::Error),
/// Rustls error.
#[cfg(feature = "__rustls-tls")]
#[cfg(all(feature = "__rustls-tls", not(target_arch = "wasm32")))]
#[error("rustls error: {0}")]
Rustls(#[from] rustls::Error),
/// Webpki error.
#[cfg(feature = "__rustls-tls")]
#[error("webpki error: {0}")]
Webpki(#[from] webpki::Error),
/// DNS name resolution error.
#[cfg(feature = "__rustls-tls")]
#[cfg(all(feature = "__rustls-tls", not(target_arch = "wasm32")))]
#[error("Invalid DNS name")]
InvalidDnsName,
/// Unknown
Expand Down
8 changes: 3 additions & 5 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,11 @@ impl From<ProtocolError> for crate::error::ProtocolError {
impl From<TlsError> for crate::error::TlsError {
fn from(err: TlsError) -> Self {
match err {
#[cfg(feature = "native-tls")]
#[cfg(all(feature = "native-tls", not(target_arch = "wasm32")))]
TlsError::Native(inner) => crate::error::TlsError::Native(inner),
#[cfg(feature = "__rustls-tls")]
#[cfg(all(feature = "__rustls-tls", not(target_arch = "wasm32")))]
TlsError::Rustls(inner) => crate::error::TlsError::Rustls(inner),
#[cfg(feature = "__rustls-tls")]
TlsError::Webpki(inner) => crate::error::TlsError::Webpki(inner),
#[cfg(feature = "__rustls-tls")]
#[cfg(all(feature = "__rustls-tls", not(target_arch = "wasm32")))]
TlsError::InvalidDnsName => crate::error::TlsError::InvalidDnsName,
_ => crate::error::TlsError::Unknown,
}
Expand Down

0 comments on commit 5b02957

Please sign in to comment.