diff --git a/Cargo.toml b/Cargo.toml index fa4a672..2d54ab2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,29 +10,32 @@ homepage = "https://github.com/ctz/hyper-rustls" repository = "https://github.com/ctz/hyper-rustls" [dependencies] -log = "0.4.4" http = "0.2" hyper = { version = "0.14", default-features = false, features = ["client"] } -rustls = "0.20" +log = { version = "0.4.4", optional = true } rustls-native-certs = { version = "0.6", optional = true } +rustls = { version = "0.20", default-features = false } tokio = "1.0" -tokio-rustls = "0.23" +tokio-rustls = { version = "0.23", default-features = false } webpki-roots = { version = "0.22", optional = true } [dev-dependencies] async-stream = "0.3.0" -tokio = { version = "1.0", features = ["io-std", "macros", "net", "rt-multi-thread"] } -hyper = { version = "0.14", features = ["full"] } futures-util = { version = "0.3.1", default-features = false } +hyper = { version = "0.14", features = ["full"] } +rustls = { version = "0.20", default-features = false, features = ["tls12"] } rustls-pemfile = "0.2.1" +tokio = { version = "1.0", features = ["io-std", "macros", "net", "rt-multi-thread"] } [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" diff --git a/src/config.rs b/src/config.rs index 38acf7b..cc27479 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,6 +21,7 @@ pub trait ConfigBuilderExt { impl ConfigBuilderExt for ConfigBuilder { #[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; @@ -32,13 +33,13 @@ impl ConfigBuilderExt for ConfigBuilder { 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 ); diff --git a/src/lib.rs b/src/lib.rs index 7f11837..9be896e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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;