Skip to content

Commit

Permalink
Expose and forward rustls default features
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
g2p committed Nov 7, 2021
1 parent bc8023b commit 05f5a0b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ homepage = "https://github.com/ctz/hyper-rustls"
repository = "https://github.com/ctz/hyper-rustls"

[dependencies]
log = "0.4.4"
log = { version = "0.4.4", optional = true }
http = "0.2"
hyper = { version = "0.14", default-features = false, features = ["client"] }
rustls = "0.20"
rustls = { version = "0.20", default-features = false }
rustls-native-certs = { version = "0.6", optional = true }
tokio = "1.0"
tokio-rustls = "0.23"
tokio-rustls = { version = "0.23", default-features = false }
webpki-roots = { version = "0.22", optional = true }

[dev-dependencies]
Expand All @@ -27,12 +27,14 @@ futures-util = { version = "0.3.1", default-features = false }
rustls-pemfile = "0.2.1"

[features]
default = ["native-tokio", "http1"]
default = ["native-tokio", "http1", "tls12", "logging"]
http1 = ["hyper/http1"]
http2 = ["hyper/http2"]
webpki-tokio = ["tokio-runtime", "webpki-roots"]
native-tokio = ["tokio-runtime", "rustls-native-certs"]
tokio-runtime = ["hyper/runtime"]
tls12 = ["tokio-rustls/tls12", "rustls/tls12"]
logging = ["log", "tokio-rustls/logging", "rustls/logging"]

[[example]]
name = "client"
Expand Down
7 changes: 4 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub trait ConfigBuilderExt {
impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
#[cfg(feature = "rustls-native-certs")]
#[cfg_attr(docsrs, doc(cfg(feature = "rustls-native-certs")))]
#[cfg_attr(not(feature = "logging"), allow(unused_variables))]
fn with_native_roots(self) -> ClientConfig {
let mut roots = rustls::RootCertStore::empty();
let mut valid_count = 0;
Expand All @@ -32,13 +33,13 @@ impl ConfigBuilderExt for ConfigBuilder<ClientConfig, WantsVerifier> {
match roots.add(&cert) {
Ok(_) => valid_count += 1,
Err(err) => {
log::trace!("invalid cert der {:?}", cert.0);
log::debug!("certificate parsing failed: {:?}", err);
crate::log::trace!("invalid cert der {:?}", cert.0);
crate::log::debug!("certificate parsing failed: {:?}", err);
invalid_count += 1
}
}
}
log::debug!(
crate::log::debug!(
"with_native_roots processed {} valid and {} invalid certs",
valid_count, invalid_count
);
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ mod config;
mod connector;
mod stream;

#[cfg(feature = "logging")]
mod log {
pub use log::{debug, trace};
}

#[cfg(not(feature = "logging"))]
mod log {
macro_rules! trace ( ($($tt:tt)*) => {{}} );
macro_rules! debug ( ($($tt:tt)*) => {{}} );
pub(crate) use {debug, trace};
}

pub use crate::config::ConfigBuilderExt;
pub use crate::connector::builder::ConnectorBuilder as HttpsConnectorBuilder;
pub use crate::connector::HttpsConnector;
Expand Down

0 comments on commit 05f5a0b

Please sign in to comment.