From 0fd832efdd26ba66796c23c99a24b83641614c9e Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 20 May 2023 14:34:45 +0200 Subject: [PATCH] clippy suggestions --- TODO | 1 + src/domain/acme/certificate.rs | 2 +- src/domain/acme/manager.rs | 4 ++-- src/domain/acme/private_key.rs | 3 ++- src/domain/acme/store.rs | 10 +++------- src/domain/config.rs | 2 +- src/domain/manager.rs | 6 +++--- src/main.rs | 2 +- 8 files changed, 14 insertions(+), 16 deletions(-) diff --git a/TODO b/TODO index fa0ff8d..035c319 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,4 @@ - logging - expect statements (pretend it's "expected", not "expect") - map_unexpected annotation string +- clean up main a lot diff --git a/src/domain/acme/certificate.rs b/src/domain/acme/certificate.rs index 1b92b47..57d641b 100644 --- a/src/domain/acme/certificate.rs +++ b/src/domain/acme/certificate.rs @@ -34,7 +34,7 @@ impl TryFrom<&Certificate> for openssl::x509::X509 { type Error = openssl::error::ErrorStack; fn try_from(c: &Certificate) -> Result { - Ok(openssl::x509::X509::from_der(&c.0)?) + openssl::x509::X509::from_der(&c.0) } } diff --git a/src/domain/acme/manager.rs b/src/domain/acme/manager.rs index dfbc30d..9a52d9d 100644 --- a/src/domain/acme/manager.rs +++ b/src/domain/acme/manager.rs @@ -4,7 +4,7 @@ use crate::domain::{self, acme}; use crate::error; use crate::error::{MapUnexpected, ToUnexpected}; -const LETS_ENCRYPT_URL: &'static str = "https://acme-v02.api.letsencrypt.org/directory"; +const LETS_ENCRYPT_URL: &str = "https://acme-v02.api.letsencrypt.org/directory"; pub type GetHttp01ChallengeKeyError = acme::store::GetHttp01ChallengeKeyError; @@ -149,7 +149,7 @@ where // no matter what the result is, clean up the challenge key self.store - .del_http01_challenge_key(&challenge_token) + .del_http01_challenge_key(challenge_token) .map_unexpected()?; let challenge = challenge_res.map_unexpected()?; diff --git a/src/domain/acme/private_key.rs b/src/domain/acme/private_key.rs index 7365ec9..e7b1104 100644 --- a/src/domain/acme/private_key.rs +++ b/src/domain/acme/private_key.rs @@ -9,6 +9,7 @@ use serde_with::{DeserializeFromStr, SerializeDisplay}; pub struct PrivateKey(Vec); impl PrivateKey { + #[allow(clippy::new_without_default)] pub fn new() -> PrivateKey { acme2::gen_rsa_private_key(4096) .expect("RSA private key generated") @@ -44,7 +45,7 @@ impl TryFrom<&PrivateKey> for openssl::pkey::PKey { type Error = openssl::error::ErrorStack; fn try_from(k: &PrivateKey) -> Result { - Ok(openssl::pkey::PKey::private_key_from_der(&k.0)?) + openssl::pkey::PKey::private_key_from_der(&k.0) } } diff --git a/src/domain/acme/store.rs b/src/domain/acme/store.rs index 8589dfe..1f4097c 100644 --- a/src/domain/acme/store.rs +++ b/src/domain/acme/store.rs @@ -164,7 +164,7 @@ impl Store for BoxedFSStore { ) -> Result<(), error::Unexpected> { let to_store = StoredPKeyCert { private_key: key, - cert: cert, + cert, }; let cert_file = fs::File::create(self.certificate_path(domain)).map_unexpected()?; @@ -194,11 +194,7 @@ impl rustls::server::ResolvesServerCert for BoxedFSStore { &self, client_hello: rustls::server::ClientHello<'_>, ) -> Option> { - let domain = if let Some(domain) = client_hello.server_name() { - domain - } else { - return None; - }; + let domain = client_hello.server_name()?; match self.get_certificate(domain) { Err(GetCertificateError::NotFound) => Ok(None), @@ -208,7 +204,7 @@ impl rustls::server::ResolvesServerCert for BoxedFSStore { Err(err) => Err(err), Ok(key) => Ok(Some(sync::Arc::new(rustls::sign::CertifiedKey { cert: cert.into_iter().map(|cert| cert.into()).collect(), - key: key, + key, ocsp: None, sct_list: None, }))), diff --git a/src/domain/config.rs b/src/domain/config.rs index 8a69ed1..42069f3 100644 --- a/src/domain/config.rs +++ b/src/domain/config.rs @@ -105,7 +105,7 @@ impl Store for sync::Arc { error::Unexpected::from("couldn't convert os string to &str") })?; - Ok(domain::Name::from_str(domain).map_unexpected()?) + domain::Name::from_str(domain).map_unexpected() }, ) .collect()) diff --git a/src/domain/manager.rs b/src/domain/manager.rs index 26db366..b926148 100644 --- a/src/domain/manager.rs +++ b/src/domain/manager.rs @@ -188,7 +188,7 @@ where origin_store, domain_config_store, domain_checker, - acme_manager: acme_manager, + acme_manager, }) } @@ -261,7 +261,7 @@ where Ok(Box::from(iter.filter_map(|descr| { if let Err(err) = descr { - return Some((None, err.to_unexpected().into())); + return Some((None, err.to_unexpected())); } let descr = descr.unwrap(); @@ -270,7 +270,7 @@ where .origin_store .sync(descr.clone(), origin::store::Limits {}) { - return Some((Some(descr), err.to_unexpected().into())); + return Some((Some(descr), err.to_unexpected())); } None diff --git a/src/main.rs b/src/main.rs index 0fc6ba3..552a4ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -312,7 +312,7 @@ async fn main() { }) } - while let Some(_) = wait_group.next().await {} + while wait_group.next().await.is_some() {} println!("Graceful shutdown complete"); }