Skip to content

Commit 64b20d1

Browse files
committed
build: move away from "use-" feature naming
Introduce simpler feature names "openssl", "rustls", and "rustls-ring". The original "use-" style names are still available for backwards compatibility.
1 parent b4fac80 commit 64b20d1

File tree

4 files changed

+34
-41
lines changed

4 files changed

+34
-41
lines changed

Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ libc = { version = "0.2", optional = true }
3838
winapi = { version="0.3.9", features=["winsock2"], optional = true }
3939

4040
[features]
41-
default = ["proxy", "use-rustls"]
41+
default = ["proxy", "rustls"]
4242
minimal = []
4343
debug-calls = []
4444
proxy = ["byteorder", "winapi", "libc"]
45-
use-rustls = ["webpki-roots", "rustls/default"]
46-
use-rustls-ring = ["webpki-roots", "rustls/ring", "rustls/logging", "rustls/std", "rustls/tls12"]
45+
rustls = ["webpki-roots", "dep:rustls", "rustls/default"]
46+
rustls-ring = ["webpki-roots", "dep:rustls", "rustls/ring", "rustls/logging", "rustls/std", "rustls/tls12"]
47+
openssl = ["dep:openssl"]
48+
49+
# Old feature names
50+
use-rustls = ["rustls"]
51+
use-rustls-ring = ["rustls-ring"]
4752
use-openssl = ["openssl"]

src/lib.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
pub extern crate bitcoin;
2323
extern crate core;
2424
extern crate log;
25-
#[cfg(feature = "use-openssl")]
25+
#[cfg(feature = "openssl")]
2626
extern crate openssl;
27-
#[cfg(any(feature = "use-rustls", feature = "use-rustls-ring"))]
27+
#[cfg(any(feature = "rustls", feature = "rustls-ring"))]
2828
extern crate rustls;
2929
extern crate serde;
3030
extern crate serde_json;
3131

32-
#[cfg(any(feature = "use-rustls", feature = "use-rustls-ring"))]
32+
#[cfg(any(feature = "rustls", feature = "rustls-ring"))]
3333
extern crate webpki_roots;
3434

3535
#[cfg(feature = "proxy")]
@@ -46,11 +46,7 @@ pub mod socks;
4646
mod api;
4747
mod batch;
4848

49-
#[cfg(any(
50-
feature = "use-openssl",
51-
feature = "use-rustls",
52-
feature = "use-rustls-ring",
53-
))]
49+
#[cfg(any(feature = "openssl", feature = "rustls", feature = "rustls-ring"))]
5450
pub mod client;
5551

5652
mod config;
@@ -62,11 +58,7 @@ pub mod utils;
6258

6359
pub use api::ElectrumApi;
6460
pub use batch::Batch;
65-
#[cfg(any(
66-
feature = "use-openssl",
67-
feature = "use-rustls",
68-
feature = "use-rustls-ring",
69-
))]
61+
#[cfg(any(feature = "openssl", feature = "rustls", feature = "rustls-ring"))]
7062
pub use client::*;
7163
pub use config::{Config, ConfigBuilder, Socks5Config};
7264
pub use types::*;

src/raw_client.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ use bitcoin::consensus::encode::deserialize;
1919
use bitcoin::hex::{DisplayHex, FromHex};
2020
use bitcoin::{Script, Txid};
2121

22-
#[cfg(feature = "use-openssl")]
22+
#[cfg(feature = "openssl")]
2323
use openssl::ssl::{SslConnector, SslMethod, SslStream, SslVerifyMode};
2424

25-
#[cfg(any(feature = "use-rustls", feature = "use-rustls-ring"))]
25+
#[cfg(any(feature = "rustls", feature = "rustls-ring"))]
2626
#[allow(unused_imports)]
2727
use rustls::{
2828
pki_types::ServerName,
@@ -222,10 +222,10 @@ fn connect_with_total_timeout<A: ToSocketAddrs>(
222222
Err(Error::AllAttemptsErrored(errors))
223223
}
224224

225-
#[cfg(feature = "use-openssl")]
225+
#[cfg(feature = "openssl")]
226226
/// Transport type used to establish an OpenSSL TLS encrypted/authenticated connection with the server
227227
pub type ElectrumSslStream = SslStream<TcpStream>;
228-
#[cfg(feature = "use-openssl")]
228+
#[cfg(feature = "openssl")]
229229
impl RawClient<ElectrumSslStream> {
230230
/// Creates a new SSL client and tries to connect to `socket_addr`. Optionally, if
231231
/// `validate_domain` is `true`, validate the server's certificate.
@@ -283,7 +283,7 @@ impl RawClient<ElectrumSslStream> {
283283
}
284284
}
285285

286-
#[cfg(any(feature = "use-rustls", feature = "use-rustls-ring"))]
286+
#[cfg(any(feature = "rustls", feature = "rustls-ring"))]
287287
#[allow(unused)]
288288
mod danger {
289289
use crate::raw_client::ServerName;
@@ -338,14 +338,14 @@ mod danger {
338338
}
339339

340340
#[cfg(all(
341-
any(feature = "use-rustls", feature = "use-rustls-ring"),
342-
not(feature = "use-openssl")
341+
any(feature = "rustls", feature = "rustls-ring"),
342+
not(feature = "openssl")
343343
))]
344344
/// Transport type used to establish a Rustls TLS encrypted/authenticated connection with the server
345345
pub type ElectrumSslStream = StreamOwned<ClientConnection, TcpStream>;
346346
#[cfg(all(
347-
any(feature = "use-rustls", feature = "use-rustls-ring"),
348-
not(feature = "use-openssl")
347+
any(feature = "rustls", feature = "rustls-ring"),
348+
not(feature = "openssl")
349349
))]
350350
impl RawClient<ElectrumSslStream> {
351351
/// Creates a new SSL client and tries to connect to `socket_addr`. Optionally, if
@@ -388,7 +388,7 @@ impl RawClient<ElectrumSslStream> {
388388

389389
if rustls::crypto::CryptoProvider::get_default().is_none() {
390390
// We install a crypto provider depending on the set feature.
391-
#[cfg(all(feature = "use-rustls", not(feature = "use-rustls-ring")))]
391+
#[cfg(all(feature = "rustls", not(feature = "rustls-ring")))]
392392
rustls::crypto::CryptoProvider::install_default(
393393
rustls::crypto::aws_lc_rs::default_provider(),
394394
)
@@ -398,7 +398,7 @@ impl RawClient<ElectrumSslStream> {
398398
))
399399
})?;
400400

401-
#[cfg(feature = "use-rustls-ring")]
401+
#[cfg(feature = "rustls-ring")]
402402
rustls::crypto::CryptoProvider::install_default(
403403
rustls::crypto::ring::default_provider(),
404404
)
@@ -429,9 +429,9 @@ impl RawClient<ElectrumSslStream> {
429429
builder
430430
.dangerous()
431431
.with_custom_certificate_verifier(std::sync::Arc::new(
432-
#[cfg(all(feature = "use-rustls", not(feature = "use-rustls-ring")))]
432+
#[cfg(all(feature = "rustls", not(feature = "rustls-ring")))]
433433
danger::NoCertificateVerification::new(rustls::crypto::aws_lc_rs::default_provider()),
434-
#[cfg(feature = "use-rustls-ring")]
434+
#[cfg(feature = "rustls-ring")]
435435
danger::NoCertificateVerification::new(rustls::crypto::ring::default_provider()),
436436
))
437437
.with_no_client_auth()
@@ -480,11 +480,7 @@ impl RawClient<ElectrumProxyStream> {
480480
}
481481

482482
#[cfg(all(
483-
any(
484-
feature = "use-openssl",
485-
feature = "use-rustls",
486-
feature = "use-rustls-ring",
487-
),
483+
any(feature = "openssl", feature = "rustls", feature = "rustls-ring",),
488484
feature = "proxy",
489485
))]
490486
/// Creates a new TLS client that connects to `target_addr` using `proxy_addr` as a socks proxy

src/types.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,14 @@ pub enum Error {
326326
CouldntLockReader,
327327
/// Broken IPC communication channel: the other thread probably has exited
328328
Mpsc,
329-
#[cfg(any(feature = "use-rustls", feature = "use-rustls-ring"))]
329+
#[cfg(any(feature = "rustls", feature = "rustls-ring"))]
330330
/// Could not create a rustls client connection
331331
CouldNotCreateConnection(rustls::Error),
332332

333-
#[cfg(feature = "use-openssl")]
333+
#[cfg(feature = "openssl")]
334334
/// Invalid OpenSSL method used
335335
InvalidSslMethod(openssl::error::ErrorStack),
336-
#[cfg(feature = "use-openssl")]
336+
#[cfg(feature = "openssl")]
337337
/// SSL Handshake failed with the server
338338
SslHandshakeError(openssl::ssl::HandshakeError<std::net::TcpStream>),
339339
}
@@ -346,13 +346,13 @@ impl Display for Error {
346346
Error::Hex(e) => Display::fmt(e, f),
347347
Error::Bitcoin(e) => Display::fmt(e, f),
348348
Error::SharedIOError(e) => Display::fmt(e, f),
349-
#[cfg(feature = "use-openssl")]
349+
#[cfg(feature = "openssl")]
350350
Error::SslHandshakeError(e) => Display::fmt(e, f),
351-
#[cfg(feature = "use-openssl")]
351+
#[cfg(feature = "openssl")]
352352
Error::InvalidSslMethod(e) => Display::fmt(e, f),
353353
#[cfg(any(
354-
feature = "use-rustls",
355-
feature = "use-rustls-ring",
354+
feature = "rustls",
355+
feature = "rustls-ring",
356356
))]
357357
Error::CouldNotCreateConnection(e) => Display::fmt(e, f),
358358

0 commit comments

Comments
 (0)