From 1aa770c2dec995d6927453dae4905719721ba11c Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 30 May 2023 10:47:10 +0200 Subject: [PATCH] Make hyper-rustls dependency optional --- Cargo.toml | 11 +++++++++-- src/lib.rs | 9 ++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 468369d..cda0fa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,13 @@ keywords = ["letsencrypt", "acme"] categories = ["web-programming", "api-bindings"] rust-version = "1.60.0" +[features] +default = ["hyper-rustls"] + [dependencies] base64 = "0.21.0" hyper = { version = "0.14.18", features = ["client", "http1", "http2"] } -hyper-rustls = { version = "0.24", default-features = false, features = ["http1", "http2", "native-tokio", "tls12"] } +hyper-rustls = { version = "0.24", default-features = false, features = ["http1", "http2", "native-tokio", "tls12"], optional = true } ring = { version = "0.16.20", features = ["std"] } serde = { version = "1.0.104", features = ["derive"] } serde_json = "1.0.78" @@ -24,6 +27,10 @@ thiserror = "1.0.30" anyhow = "1.0.66" clap = { version = "4.0.29", features = ["derive"] } rcgen = "0.10.0" -tokio = { version = "1.22.0", features = ["rt", "macros", "rt-multi-thread"] } +tokio = { version = "1.22.0", features = ["macros", "rt", "rt-multi-thread", "time"] } tracing = "0.1.37" tracing-subscriber = "0.3.16" + +[[example]] +name = "provision" +required-features = ["hyper-rustls"] diff --git a/src/lib.rs b/src/lib.rs index c1643c4..53ed652 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,9 @@ use std::fmt; use std::sync::Arc; use base64::prelude::{Engine, BASE64_URL_SAFE_NO_PAD}; -use hyper::client::{HttpConnector, ResponseFuture}; +#[cfg(feature = "hyper-rustls")] +use hyper::client::HttpConnector; +use hyper::client::ResponseFuture; use hyper::header::{CONTENT_TYPE, LOCATION}; use hyper::{Body, Method, Request, Response}; use ring::digest::{digest, SHA256}; @@ -198,6 +200,7 @@ impl Account { /// Restore an existing account from the given credentials /// /// The [`AccountCredentials`] type is opaque, but supports deserialization. + #[cfg(feature = "hyper-rustls")] pub fn from_credentials(credentials: AccountCredentials<'_>) -> Result { Ok(Self { inner: Arc::new(AccountInner::from_credentials( @@ -220,6 +223,7 @@ impl Account { } /// Create a new account on the `server_url` with the information in [`NewAccount`] + #[cfg(feature = "hyper-rustls")] pub async fn create( account: &NewAccount<'_>, server_url: &str, @@ -589,14 +593,17 @@ fn nonce_from_response(rsp: &Response) -> Option { .and_then(|hv| String::from_utf8(hv.as_ref().to_vec()).ok()) } +#[cfg(feature = "hyper-rustls")] struct DefaultClient(hyper::Client>); +#[cfg(feature = "hyper-rustls")] impl HttpClient for DefaultClient { fn request(&self, req: Request) -> ResponseFuture { self.0.request(req) } } +#[cfg(feature = "hyper-rustls")] impl Default for DefaultClient { fn default() -> Self { Self(