From feb2374c55c109abac706133041bcbf48292b0aa Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Thu, 20 Jun 2024 11:45:26 -0400 Subject: [PATCH] feat: add use-rustls-ring feature --- Cargo.toml | 5 +++-- src/lib.rs | 14 ++++++++++---- src/raw_client.rs | 10 +++++----- src/types.rs | 11 ++++++++--- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3324983..5d4461b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ serde_json = { version = "^1.0" } # Optional dependencies openssl = { version = "0.10", optional = true } -rustls = { version = "0.23", optional = true } +rustls = { version = "0.23", optional = true, default-features = false } webpki-roots = { version = "0.25", optional = true } byteorder = { version = "1.0", optional = true } @@ -41,5 +41,6 @@ default = ["proxy", "use-rustls"] minimal = [] debug-calls = [] proxy = ["byteorder", "winapi", "libc"] -use-rustls = ["webpki-roots", "rustls"] +use-rustls = ["webpki-roots", "rustls/default"] +use-rustls-ring = ["proxy", "webpki-roots", "rustls/ring", "rustls/logging", "rustls/std", "rustls/tls12"] use-openssl = ["openssl"] diff --git a/src/lib.rs b/src/lib.rs index b4f8379..f5e3f71 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,14 +25,18 @@ extern crate log; #[cfg(feature = "use-openssl")] extern crate openssl; #[cfg(all( - any(feature = "default", feature = "use-rustls"), + any(feature = "default", feature = "use-rustls", feature = "use-rustls-ring"), not(feature = "use-openssl") ))] extern crate rustls; extern crate serde; extern crate serde_json; -#[cfg(any(feature = "use-rustls", feature = "default"))] +#[cfg(any( + feature = "default", + feature = "use-rustls", + feature = "use-rustls-ring" +))] extern crate webpki_roots; #[cfg(any(feature = "default", feature = "proxy"))] @@ -51,7 +55,8 @@ mod batch; #[cfg(any( all(feature = "proxy", feature = "use-openssl"), - all(feature = "proxy", feature = "use-rustls") + all(feature = "proxy", feature = "use-rustls"), + all(feature = "proxy", feature = "use-rustls-ring") ))] pub mod client; @@ -66,7 +71,8 @@ pub use api::ElectrumApi; pub use batch::Batch; #[cfg(any( all(feature = "proxy", feature = "use-openssl"), - all(feature = "proxy", feature = "use-rustls") + all(feature = "proxy", feature = "use-rustls"), + all(feature = "proxy", feature = "use-rustls-ring") ))] pub use client::*; pub use config::{Config, ConfigBuilder, Socks5Config}; diff --git a/src/raw_client.rs b/src/raw_client.rs index 98cfbe9..196dedb 100644 --- a/src/raw_client.rs +++ b/src/raw_client.rs @@ -23,7 +23,7 @@ use bitcoin::{Script, Txid}; use openssl::ssl::{SslConnector, SslMethod, SslStream, SslVerifyMode}; #[cfg(all( - any(feature = "default", feature = "use-rustls"), + any(feature = "default", feature = "use-rustls", feature = "use-rustls-ring"), not(feature = "use-openssl") ))] use rustls::{ @@ -286,7 +286,7 @@ impl RawClient { } #[cfg(all( - any(feature = "default", feature = "use-rustls"), + any(feature = "default", feature = "use-rustls", feature = "use-rustls-ring"), not(feature = "use-openssl") ))] mod danger { @@ -336,13 +336,13 @@ mod danger { } #[cfg(all( - any(feature = "default", feature = "use-rustls"), + any(feature = "default", feature = "use-rustls", feature = "use-rustls-ring"), not(feature = "use-openssl") ))] /// Transport type used to establish a Rustls TLS encrypted/authenticated connection with the server pub type ElectrumSslStream = StreamOwned; #[cfg(all( - any(feature = "default", feature = "use-rustls"), + any(feature = "default", feature = "use-rustls", feature = "use-rustls-ring"), not(feature = "use-openssl") ))] impl RawClient { @@ -451,7 +451,7 @@ impl RawClient { Ok(stream.into()) } - #[cfg(any(feature = "use-openssl", feature = "use-rustls"))] + #[cfg(any(feature = "use-openssl", feature = "use-rustls", feature = "use-rustls-ring"))] /// Creates a new TLS client that connects to `target_addr` using `proxy_addr` as a socks proxy /// server. The DNS resolution of `target_addr`, if required, is done through the proxy. This /// allows to specify, for instance, `.onion` addresses. diff --git a/src/types.rs b/src/types.rs index 728e8f6..353716f 100644 --- a/src/types.rs +++ b/src/types.rs @@ -315,8 +315,10 @@ pub enum Error { CouldntLockReader, /// Broken IPC communication channel: the other thread probably has exited Mpsc, - - #[cfg(feature = "use-rustls")] + #[cfg(any( + feature = "use-rustls", + feature = "use-rustls-ring" + ))] /// Could not create a rustls client connection CouldNotCreateConnection(rustls::Error), @@ -340,7 +342,10 @@ impl Display for Error { Error::SslHandshakeError(e) => Display::fmt(e, f), #[cfg(feature = "use-openssl")] Error::InvalidSslMethod(e) => Display::fmt(e, f), - #[cfg(feature = "use-rustls")] + #[cfg(any( + feature = "use-rustls", + feature = "use-rustls-ring", + ))] Error::CouldNotCreateConnection(e) => Display::fmt(e, f), Error::Message(e) => f.write_str(e),