Skip to content

Commit 413b73a

Browse files
committed
Expose and forward rustls default features
tls12 and logging are rustls features we enable by default, as does rustls, exposing them explicitly allows users to disable them by disabling hyper-rustls default features. Make sure tests run with tls12 by enabling it in dev-dependencies, because windows tests (at least in CI) seem to run with an outdated version of curl that doesn't support TLS 1.3.
1 parent 5ff82f0 commit 413b73a

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

Cargo.toml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,32 @@ homepage = "https://github.com/ctz/hyper-rustls"
1010
repository = "https://github.com/ctz/hyper-rustls"
1111

1212
[dependencies]
13-
log = "0.4.4"
1413
http = "0.2"
1514
hyper = { version = "0.14", default-features = false, features = ["client"] }
16-
rustls = "0.20"
15+
log = { version = "0.4.4", optional = true }
1716
rustls-native-certs = { version = "0.6", optional = true }
17+
rustls = { version = "0.20", default-features = false }
1818
tokio = "1.0"
19-
tokio-rustls = "0.23"
19+
tokio-rustls = { version = "0.23", default-features = false }
2020
webpki-roots = { version = "0.22", optional = true }
2121

2222
[dev-dependencies]
2323
async-stream = "0.3.0"
24-
tokio = { version = "1.0", features = ["io-std", "macros", "net", "rt-multi-thread"] }
25-
hyper = { version = "0.14", features = ["full"] }
2624
futures-util = { version = "0.3.1", default-features = false }
25+
hyper = { version = "0.14", features = ["full"] }
26+
rustls = { version = "0.20", default-features = false, features = ["tls12"] }
2727
rustls-pemfile = "0.2.1"
28+
tokio = { version = "1.0", features = ["io-std", "macros", "net", "rt-multi-thread"] }
2829

2930
[features]
30-
default = ["native-tokio", "http1"]
31+
default = ["native-tokio", "http1", "tls12", "logging"]
3132
http1 = ["hyper/http1"]
3233
http2 = ["hyper/http2"]
3334
webpki-tokio = ["tokio-runtime", "webpki-roots"]
3435
native-tokio = ["tokio-runtime", "rustls-native-certs"]
3536
tokio-runtime = ["hyper/runtime"]
37+
tls12 = ["tokio-rustls/tls12", "rustls/tls12"]
38+
logging = ["log", "tokio-rustls/logging", "rustls/logging"]
3639

3740
[[example]]
3841
name = "client"

src/config.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub trait ConfigBuilderExt {
2121
impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
2222
#[cfg(feature = "rustls-native-certs")]
2323
#[cfg_attr(docsrs, doc(cfg(feature = "rustls-native-certs")))]
24+
#[cfg_attr(not(feature = "logging"), allow(unused_variables))]
2425
fn with_native_roots(self) -> ClientConfig {
2526
let mut roots = rustls::RootCertStore::empty();
2627
let mut valid_count = 0;
@@ -32,13 +33,13 @@ impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
3233
match roots.add(&cert) {
3334
Ok(_) => valid_count += 1,
3435
Err(err) => {
35-
log::trace!("invalid cert der {:?}", cert.0);
36-
log::debug!("certificate parsing failed: {:?}", err);
36+
crate::log::trace!("invalid cert der {:?}", cert.0);
37+
crate::log::debug!("certificate parsing failed: {:?}", err);
3738
invalid_count += 1
3839
}
3940
}
4041
}
41-
log::debug!(
42+
crate::log::debug!(
4243
"with_native_roots processed {} valid and {} invalid certs",
4344
valid_count, invalid_count
4445
);

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ mod config;
3434
mod connector;
3535
mod stream;
3636

37+
#[cfg(feature = "logging")]
38+
mod log {
39+
pub use log::{debug, trace};
40+
}
41+
42+
#[cfg(not(feature = "logging"))]
43+
mod log {
44+
macro_rules! trace ( ($($tt:tt)*) => {{}} );
45+
macro_rules! debug ( ($($tt:tt)*) => {{}} );
46+
pub(crate) use {debug, trace};
47+
}
48+
3749
pub use crate::config::ConfigBuilderExt;
3850
pub use crate::connector::builder::ConnectorBuilder as HttpsConnectorBuilder;
3951
pub use crate::connector::HttpsConnector;

0 commit comments

Comments
 (0)