From e900138503f045fb3515b424156421a85fa62a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Sat, 28 Jan 2023 18:40:59 +0100 Subject: [PATCH] Inline the format args --- acme_common/src/crypto.rs | 4 +-- .../src/crypto/jws_signature_algorithm.rs | 4 +-- acme_common/src/crypto/key_type.rs | 7 ++--- acme_common/src/crypto/openssl_keys.rs | 6 ++-- acme_common/src/crypto/openssl_version.rs | 4 +-- acme_common/src/error.rs | 30 +++++++++---------- acme_common/src/lib.rs | 4 +-- acme_common/src/logs.rs | 2 +- acmed/src/account.rs | 17 +++++------ acmed/src/account/contact.rs | 4 +-- acmed/src/account/storage.rs | 8 ++--- acmed/src/acme_proto.rs | 4 +-- acmed/src/acme_proto/account.rs | 12 +++----- acmed/src/acme_proto/structs/authorization.rs | 15 ++++------ acmed/src/acme_proto/structs/error.rs | 6 ++-- acmed/src/acme_proto/structs/order.rs | 2 +- acmed/src/certificate.rs | 13 ++++---- acmed/src/config.rs | 18 ++++------- acmed/src/duration.rs | 4 +-- acmed/src/hooks.rs | 21 ++++--------- acmed/src/http.rs | 8 ++--- acmed/src/identifier.rs | 14 ++++----- acmed/src/jws.rs | 6 ++-- acmed/src/main.rs | 7 ++--- acmed/src/main_event_loop.rs | 2 +- acmed/src/storage.rs | 26 ++++++++-------- tacd/build.rs | 2 +- tacd/src/main.rs | 12 ++++---- tacd/src/openssl_server.rs | 4 +-- 29 files changed, 115 insertions(+), 151 deletions(-) diff --git a/acme_common/src/crypto.rs b/acme_common/src/crypto.rs index dfe6be0..e0fdd5f 100644 --- a/acme_common/src/crypto.rs +++ b/acme_common/src/crypto.rs @@ -63,7 +63,7 @@ impl FromStr for BaseHashFunction { "sha256" => Ok(BaseHashFunction::Sha256), "sha384" => Ok(BaseHashFunction::Sha384), "sha512" => Ok(BaseHashFunction::Sha512), - _ => Err(format!("{}: unknown hash function.", s).into()), + _ => Err(format!("{s}: unknown hash function.").into()), } } } @@ -75,7 +75,7 @@ impl fmt::Display for BaseHashFunction { BaseHashFunction::Sha384 => "sha384", BaseHashFunction::Sha512 => "sha512", }; - write!(f, "{}", s) + write!(f, "{s}") } } diff --git a/acme_common/src/crypto/jws_signature_algorithm.rs b/acme_common/src/crypto/jws_signature_algorithm.rs index 26bcf44..8c5eb49 100644 --- a/acme_common/src/crypto/jws_signature_algorithm.rs +++ b/acme_common/src/crypto/jws_signature_algorithm.rs @@ -33,7 +33,7 @@ impl FromStr for JwsSignatureAlgorithm { "ed25519" => Ok(JwsSignatureAlgorithm::Ed25519), #[cfg(ed448)] "ed448" => Ok(JwsSignatureAlgorithm::Ed448), - _ => Err(format!("{}: unknown algorithm.", s).into()), + _ => Err(format!("{s}: unknown algorithm.").into()), } } } @@ -53,7 +53,7 @@ impl fmt::Display for JwsSignatureAlgorithm { #[cfg(ed448)] JwsSignatureAlgorithm::Ed448 => "Ed448", }; - write!(f, "{}", s) + write!(f, "{s}") } } diff --git a/acme_common/src/crypto/key_type.rs b/acme_common/src/crypto/key_type.rs index 513afc2..1603225 100644 --- a/acme_common/src/crypto/key_type.rs +++ b/acme_common/src/crypto/key_type.rs @@ -45,8 +45,7 @@ impl KeyType { Ok(()) } else { let err_msg = format!( - "incompatible signature algorithm: {} cannot be used with an {} key", - alg, self + "incompatible signature algorithm: {alg} cannot be used with an {self} key" ); Err(err_msg.into()) } @@ -81,7 +80,7 @@ impl FromStr for KeyType { "ed25519" => Ok(KeyType::Ed25519), #[cfg(ed448)] "ed448" => Ok(KeyType::Ed448), - _ => Err(format!("{}: unknown algorithm", s).into()), + _ => Err(format!("{s}: unknown algorithm").into()), } } } @@ -99,6 +98,6 @@ impl fmt::Display for KeyType { #[cfg(ed448)] KeyType::Ed448 => "ed448", }; - write!(f, "{}", s) + write!(f, "{s}") } } diff --git a/acme_common/src/crypto/openssl_keys.rs b/acme_common/src/crypto/openssl_keys.rs index 96ebfb0..8231f28 100644 --- a/acme_common/src/crypto/openssl_keys.rs +++ b/acme_common/src/crypto/openssl_keys.rs @@ -104,8 +104,8 @@ impl KeyPair { JwsSignatureAlgorithm::Hs256 | JwsSignatureAlgorithm::Hs384 | JwsSignatureAlgorithm::Hs512 => Err(format!( - "{} key pair cannot be used for the {} signature algorithm", - self.key_type, alg + "{} key pair cannot be used for the {alg} signature algorithm", + self.key_type ) .into()), JwsSignatureAlgorithm::Rs256 => self.sign_rsa(&MessageDigest::sha256(), data), @@ -336,7 +336,7 @@ pub fn gen_keypair(key_type: KeyType) -> Result { #[cfg(ed448)] KeyType::Ed448 => gen_ed448_pair(), } - .map_err(|_| Error::from(format!("unable to generate a {} key pair", key_type)))?; + .map_err(|_| Error::from(format!("unable to generate a {key_type} key pair")))?; let key_pair = KeyPair { key_type, inner_key: priv_key, diff --git a/acme_common/src/crypto/openssl_version.rs b/acme_common/src/crypto/openssl_version.rs index 40de2e6..682f019 100644 --- a/acme_common/src/crypto/openssl_version.rs +++ b/acme_common/src/crypto/openssl_version.rs @@ -7,14 +7,14 @@ pub fn get_lib_version() -> String { let mut version = vec![]; for i in 0..3 { let n = get_openssl_version_unit(v, i); - version.push(format!("{}", n)); + version.push(format!("{n}")); } let version = version.join("."); let p = get_openssl_version_unit(v, 3); if p != 0 { let p = p + 0x60; let p = std::char::from_u32(p as u32).unwrap(); - format!("{}{}", version, p) + format!("{version}{p}") } else { version } diff --git a/acme_common/src/error.rs b/acme_common/src/error.rs index f64997d..44cf1c0 100644 --- a/acme_common/src/error.rs +++ b/acme_common/src/error.rs @@ -8,7 +8,7 @@ pub struct Error { impl Error { pub fn prefix(&self, prefix: &str) -> Self { Error { - message: format!("{}: {}", prefix, &self.message), + message: format!("{prefix}: {}", &self.message), } } } @@ -41,25 +41,25 @@ impl From<&String> for Error { impl From for Error { fn from(error: std::io::Error) -> Self { - format!("IO error: {}", error).into() + format!("IO error: {error}").into() } } impl From for Error { fn from(error: std::net::AddrParseError) -> Self { - format!("{}", error).into() + format!("{error}").into() } } impl From for Error { fn from(error: std::string::FromUtf8Error) -> Self { - format!("UTF-8 error: {}", error).into() + format!("UTF-8 error: {error}").into() } } impl From for Error { fn from(error: std::sync::mpsc::RecvError) -> Self { - format!("MSPC receiver error: {}", error).into() + format!("MSPC receiver error: {error}").into() } } @@ -71,63 +71,63 @@ impl From for Error { impl From for Error { fn from(error: base64::DecodeError) -> Self { - format!("base 64 decode error: {}", error).into() + format!("base 64 decode error: {error}").into() } } impl From for Error { fn from(error: syslog::Error) -> Self { - format!("syslog error: {}", error).into() + format!("syslog error: {error}").into() } } impl From for Error { fn from(error: toml::de::Error) -> Self { - format!("IO error: {}", error).into() + format!("IO error: {error}").into() } } impl From for Error { fn from(error: serde_json::error::Error) -> Self { - format!("IO error: {}", error).into() + format!("IO error: {error}").into() } } impl From for Error { fn from(error: attohttpc::Error) -> Self { - format!("HTTP error: {}", error).into() + format!("HTTP error: {error}").into() } } impl From for Error { fn from(error: glob::PatternError) -> Self { - format!("pattern error: {}", error).into() + format!("pattern error: {error}").into() } } impl From for Error { fn from(error: tinytemplate::error::Error) -> Self { - format!("template error: {}", error).into() + format!("template error: {error}").into() } } #[cfg(feature = "crypto_openssl")] impl From for Error { fn from(error: native_tls::Error) -> Self { - format!("{}", error).into() + format!("{error}").into() } } #[cfg(feature = "crypto_openssl")] impl From for Error { fn from(error: openssl::error::ErrorStack) -> Self { - format!("{}", error).into() + format!("{error}").into() } } #[cfg(unix)] impl From for Error { fn from(error: nix::Error) -> Self { - format!("{}", error).into() + format!("{error}").into() } } diff --git a/acme_common/src/lib.rs b/acme_common/src/lib.rs index 6d6e287..86c3fe0 100644 --- a/acme_common/src/lib.rs +++ b/acme_common/src/lib.rs @@ -15,7 +15,7 @@ macro_rules! exit_match { match $e { Ok(_) => {} Err(e) => { - log::error!("error: {}", e); + log::error!("error: {e}"); std::process::exit(3); } } @@ -32,7 +32,7 @@ pub fn to_idna(domain_name: &str) -> Result { } else { let idna_name = punycode::encode(&raw_name) .map_err(|_| error::Error::from("IDNA encoding failed."))?; - format!("xn--{}", idna_name) + format!("xn--{idna_name}") }; idna_parts.push(idna_name); } diff --git a/acme_common/src/logs.rs b/acme_common/src/logs.rs index 89ec246..eacede0 100644 --- a/acme_common/src/logs.rs +++ b/acme_common/src/logs.rs @@ -21,7 +21,7 @@ fn get_loglevel(log_level: Option<&str>) -> Result { "debug" => LevelFilter::Debug, "trace" => LevelFilter::Trace, _ => { - return Err(format!("{}: invalid log level", v).into()); + return Err(format!("{v}: invalid log level").into()); } }, None => DEFAULT_LOG_LEVEL, diff --git a/acmed/src/account.rs b/acmed/src/account.rs index 836119b..5582807 100644 --- a/acmed/src/account.rs +++ b/acmed/src/account.rs @@ -30,7 +30,7 @@ impl FromStr for AccountContactType { fn from_str(s: &str) -> Result { match s.to_lowercase().as_str() { "mailfrom" => Ok(AccountContactType::Mailfrom), - _ => Err(format!("{}: unknown contact type.", s).into()), + _ => Err(format!("{s}: unknown contact type.").into()), } } } @@ -40,7 +40,7 @@ impl fmt::Display for AccountContactType { let s = match self { AccountContactType::Mailfrom => "mailfrom", }; - write!(f, "{}", s) + write!(f, "{s}") } } @@ -97,19 +97,19 @@ pub struct Account { impl HasLogger for Account { fn warn(&self, msg: &str) { - log::warn!("account \"{}\": {}", &self.name, msg); + log::warn!("account \"{}\": {msg}", &self.name); } fn info(&self, msg: &str) { - log::info!("account \"{}\": {}", &self.name, msg); + log::info!("account \"{}\": {msg}", &self.name); } fn debug(&self, msg: &str) { - log::debug!("account \"{}\": {}", &self.name, msg); + log::debug!("account \"{}\": {msg}", &self.name); } fn trace(&self, msg: &str) { - log::trace!("account \"{}\": {}", &self.name, msg); + log::trace!("account \"{}\": {msg}", &self.name); } } @@ -288,10 +288,7 @@ impl Account { self.past_keys.push(self.current_key.to_owned()); self.current_key = AccountKey::new(key_type, signature_algorithm)?; self.save()?; - let msg = format!( - "new {} account key created, using {} as signing algorithm", - key_type, signature_algorithm - ); + let msg = format!("new {key_type} account key created, using {signature_algorithm} as signing algorithm"); self.info(&msg); } else { self.trace("account key is up to date"); diff --git a/acmed/src/account/contact.rs b/acmed/src/account/contact.rs index f4cb127..2a6b5f2 100644 --- a/acmed/src/account/contact.rs +++ b/acmed/src/account/contact.rs @@ -36,7 +36,7 @@ impl FromStr for ContactType { fn from_str(s: &str) -> Result { match s.to_lowercase().as_str() { "mailto" => Ok(ContactType::Mailto), - _ => Err(format!("{}: unknown contact type.", s).into()), + _ => Err(format!("{s}: unknown contact type.").into()), } } } @@ -46,7 +46,7 @@ impl fmt::Display for ContactType { let s = match self { ContactType::Mailto => "mailto", }; - write!(f, "{}", s) + write!(f, "{s}") } } diff --git a/acmed/src/account/storage.rs b/acmed/src/account/storage.rs index 0fa485e..226a7dc 100644 --- a/acmed/src/account/storage.rs +++ b/acmed/src/account/storage.rs @@ -175,14 +175,10 @@ fn do_save(file_manager: &FileManager, account: &Account) -> Result<(), Error> { pub fn fetch(file_manager: &FileManager, name: &str) -> Result, Error> { do_fetch(file_manager, name).map_err(|_| { - format!( - "account \"{}\": unable to load account file: file may be corrupted", - name - ) - .into() + format!("account \"{name}\": unable to load account file: file may be corrupted").into() }) } pub fn save(file_manager: &FileManager, account: &Account) -> Result<(), Error> { - do_save(file_manager, account).map_err(|e| format!("unable to save account file: {}", e).into()) + do_save(file_manager, account).map_err(|e| format!("unable to save account file: {e}").into()) } diff --git a/acmed/src/acme_proto.rs b/acmed/src/acme_proto.rs index 88c0626..a0253c6 100644 --- a/acmed/src/acme_proto.rs +++ b/acmed/src/acme_proto.rs @@ -32,7 +32,7 @@ impl Challenge { "http-01" => Ok(Challenge::Http01), "dns-01" => Ok(Challenge::Dns01), "tls-alpn-01" => Ok(Challenge::TlsAlpn01), - _ => Err(format!("{}: unknown challenge.", s).into()), + _ => Err(format!("{s}: unknown challenge.").into()), } } } @@ -44,7 +44,7 @@ impl fmt::Display for Challenge { Challenge::Dns01 => "dns-01", Challenge::TlsAlpn01 => "tls-alpn-01", }; - write!(f, "{}", s) + write!(f, "{s}") } } diff --git a/acmed/src/acme_proto/account.rs b/acmed/src/acme_proto/account.rs index 4a7d483..3b68ab3 100644 --- a/acmed/src/acme_proto/account.rs +++ b/acmed/src/acme_proto/account.rs @@ -82,8 +82,7 @@ pub fn update_account_contacts( ) -> Result<(), Error> { let endpoint_name = endpoint.name.clone(); account.debug(&format!( - "updating account contacts on endpoint \"{}\"...", - &endpoint_name + "updating account contacts on endpoint \"{endpoint_name}\"..." )); let new_contacts: Vec = account.contacts.iter().map(|c| c.to_string()).collect(); let acc_up_struct = AccountUpdate::new(&new_contacts); @@ -98,8 +97,7 @@ pub fn update_account_contacts( account.update_contacts_hash(&endpoint_name)?; account.save()?; account.info(&format!( - "account contacts updated on endpoint \"{}\"", - &endpoint_name + "account contacts updated on endpoint \"{endpoint_name}\"" )); Ok(()) } @@ -107,8 +105,7 @@ pub fn update_account_contacts( pub fn update_account_key(endpoint: &mut Endpoint, account: &mut BaseAccount) -> Result<(), Error> { let endpoint_name = endpoint.name.clone(); account.debug(&format!( - "updating account key on endpoint \"{}\"...", - &endpoint_name + "updating account key on endpoint \"{endpoint_name}\"..." )); let url = endpoint.dir.key_change.clone(); let ep = account.get_endpoint(&endpoint_name)?; @@ -142,8 +139,7 @@ pub fn update_account_key(endpoint: &mut Endpoint, account: &mut BaseAccount) -> account.update_key_hash(&endpoint_name)?; account.save()?; account.info(&format!( - "account key updated on endpoint \"{}\"", - &endpoint_name + "account key updated on endpoint \"{endpoint_name}\"" )); Ok(()) } diff --git a/acmed/src/acme_proto/structs/authorization.rs b/acmed/src/acme_proto/structs/authorization.rs index bf3a317..b74bdc2 100644 --- a/acmed/src/acme_proto/structs/authorization.rs +++ b/acmed/src/acme_proto/structs/authorization.rs @@ -63,7 +63,7 @@ impl fmt::Display for AuthorizationStatus { AuthorizationStatus::Expired => "expired", AuthorizationStatus::Revoked => "revoked", }; - write!(f, "{}", s) + write!(f, "{s}") } } @@ -102,22 +102,19 @@ impl Challenge { Ok(a) } Challenge::TlsAlpn01(tc) => { - let acme_ext_name = format!("{}.{}", ACME_OID, ID_PE_ACME_ID); + let acme_ext_name = format!("{ACME_OID}.{ID_PE_ACME_ID}"); let ka = tc.key_authorization(key_pair)?; let proof = HashFunction::Sha256.hash(ka.as_bytes()); let proof_str = proof .iter() - .map(|e| format!("{:02x}", e)) + .map(|e| format!("{e:02x}")) .collect::>() .join(":"); let value = format!( - "critical,{}:{:02x}:{:02x}:{}", - DER_STRUCT_NAME, - DER_OCTET_STRING_ID, + "critical,{DER_STRUCT_NAME}:{DER_OCTET_STRING_ID:02x}:{:02x}:{proof_str}", proof.len(), - proof_str ); - let acme_ext = format!("{}={}", acme_ext_name, value); + let acme_ext = format!("{acme_ext_name}={value}"); Ok(acme_ext) } Challenge::Unknown => Ok(String::new()), @@ -158,7 +155,7 @@ impl TokenChallenge { let thumbprint = key_pair.jwk_public_key_thumbprint()?; let thumbprint = HashFunction::Sha256.hash(thumbprint.to_string().as_bytes()); let thumbprint = b64_encode(&thumbprint); - let auth = format!("{}.{}", self.token, thumbprint); + let auth = format!("{}.{thumbprint}", self.token); Ok(auth) } } diff --git a/acmed/src/acme_proto/structs/error.rs b/acmed/src/acme_proto/structs/error.rs index fbfb461..972b9aa 100644 --- a/acmed/src/acme_proto/structs/error.rs +++ b/acmed/src/acme_proto/structs/error.rs @@ -99,7 +99,7 @@ impl fmt::Display for AcmeError { AcmeError::UserActionRequired => "visit the \"instance\" URL and take actions specified there", AcmeError::Unknown => "unknown error", }; - write!(f, "{}", msg) + write!(f, "{msg}") } } @@ -147,10 +147,10 @@ impl fmt::Display for HttpApiError { .to_owned() .unwrap_or_else(|| self.get_acme_type().to_string()); let msg = match self.status { - Some(s) => format!("status {}: {}", s, msg), + Some(s) => format!("status {s}: {msg}"), None => msg, }; - write!(f, "{}", msg) + write!(f, "{msg}") } } diff --git a/acmed/src/acme_proto/structs/order.rs b/acmed/src/acme_proto/structs/order.rs index d10dc8e..e778526 100644 --- a/acmed/src/acme_proto/structs/order.rs +++ b/acmed/src/acme_proto/structs/order.rs @@ -66,7 +66,7 @@ impl fmt::Display for OrderStatus { OrderStatus::Valid => "valid", OrderStatus::Invalid => "invalid", }; - write!(f, "{}", s) + write!(f, "{s}") } } diff --git a/acmed/src/certificate.rs b/acmed/src/certificate.rs index bc69c8c..1b0391e 100644 --- a/acmed/src/certificate.rs +++ b/acmed/src/certificate.rs @@ -34,19 +34,19 @@ impl fmt::Display for Certificate { impl HasLogger for Certificate { fn warn(&self, msg: &str) { - warn!("certificate \"{}\": {}", &self, msg); + warn!("certificate \"{self}\": {msg}"); } fn info(&self, msg: &str) { - info!("certificate \"{}\": {}", &self, msg); + info!("certificate \"{self}\": {msg}"); } fn debug(&self, msg: &str) { - debug!("certificate \"{}\": {}", &self, msg); + debug!("certificate \"{self}\": {msg}"); } fn trace(&self, msg: &str) { - trace!("certificate \"{}\": {}", &self, msg); + trace!("certificate \"{self}\": {msg}"); } } @@ -67,7 +67,7 @@ impl Certificate { return Ok(d.clone()); } } - Err(format!("{}: identifier not found", identifier).into()) + Err(format!("{identifier}: identifier not found").into()) } fn is_expiring(&self, cert: &X509Certificate) -> Result { @@ -95,8 +95,7 @@ impl Certificate { .collect::>() .join(", "); self.debug(&format!( - "the certificate does not include the following domains: {}", - domains + "the certificate does not include the following domains: {domains}" )); } has_miss diff --git a/acmed/src/config.rs b/acmed/src/config.rs index 9f509cf..afa1a80 100644 --- a/acmed/src/config.rs +++ b/acmed/src/config.rs @@ -78,7 +78,7 @@ impl Config { return Ok((rl.number, rl.period.to_owned())); } } - Err(format!("{}: rate limit not found", name).into()) + Err(format!("{name}: rate limit not found").into()) } pub fn get_account_dir(&self) -> String { @@ -120,7 +120,7 @@ impl Config { return Ok(ret); } } - Err(format!("{}: hook not found", name).into()) + Err(format!("{name}: hook not found").into()) } pub fn get_cert_file_mode(&self) -> u32 { @@ -341,11 +341,7 @@ impl ExternalAccount { | JwsSignatureAlgorithm::Hs384 | JwsSignatureAlgorithm::Hs512 => {} _ => { - return Err(format!( - "{}: invalid signature algorithm for external account binding", - signature_algorithm - ) - .into()); + return Err(format!("{signature_algorithm}: invalid signature algorithm for external account binding").into()); } }; Ok(crate::account::ExternalAccount { @@ -584,7 +580,7 @@ impl fmt::Display for Identifier { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let s = String::new(); let msg = self.dns.as_ref().or(self.ip.as_ref()).unwrap_or(&s); - write!(f, "{}", msg) + write!(f, "{msg}") } } @@ -666,16 +662,14 @@ fn get_cnf_path(from: &Path, file: &str) -> Result, Error> { let mut path = from.to_path_buf().canonicalize()?; path.pop(); path.push(file); - let err = format!("{:?}: invalid UTF-8 path", path); + let err = format!("{path:?}: invalid UTF-8 path"); let raw_path = path.to_str().ok_or(err)?; let g = glob(raw_path)? .filter_map(Result::ok) .collect::>(); if g.is_empty() { log::warn!( - "pattern `{}` (expanded as `{}`): no matching configuration file found", - file, - raw_path + "pattern `{file}` (expanded as `{raw_path}`): no matching configuration file found" ); } Ok(g) diff --git a/acmed/src/duration.rs b/acmed/src/duration.rs index 983c267..bcaa986 100644 --- a/acmed/src/duration.rs +++ b/acmed/src/duration.rs @@ -44,8 +44,8 @@ pub fn parse_duration(input: &str) -> Result { match get_duration(input) { Ok((r, d)) => match r.len() { 0 => Ok(d), - _ => Err(format!("{}: invalid duration", input).into()), + _ => Err(format!("{input}: invalid duration").into()), }, - Err(_) => Err(format!("{}: invalid duration", input).into()), + Err(_) => Err(format!("{input}: invalid duration").into()), } } diff --git a/acmed/src/hooks.rs b/acmed/src/hooks.rs index 26de269..675511e 100644 --- a/acmed/src/hooks.rs +++ b/acmed/src/hooks.rs @@ -106,10 +106,7 @@ macro_rules! get_hook_output { match $out { Some(path) => { let path = render_template(path, $data)?; - $logger.trace(&format!( - "hook \"{}\": {}: {}", - $hook_name, $out_name, &path - )); + $logger.trace(&format!("hook \"{}\": {}: {path}", $hook_name, $out_name)); let file = File::create(&path)?; Stdio::from(file) } @@ -136,7 +133,7 @@ where None => &[], }; logger.trace(&format!("hook \"{}\": cmd: {}", hook.name, hook.cmd)); - logger.trace(&format!("hook \"{}\": args: {:?}", hook.name, args)); + logger.trace(&format!("hook \"{}\": args: {args:?}", hook.name)); let mut cmd = Command::new(&hook.cmd) .envs(data.get_env()) .args(args) @@ -162,19 +159,13 @@ where match &hook.stdin { HookStdin::Str(s) => { let data_in = render_template(s, &data)?; - logger.trace(&format!( - "hook \"{}\": string stdin: {}", - hook.name, &data_in - )); + logger.trace(&format!("hook \"{}\": string stdin: {data_in}", hook.name)); let stdin = cmd.stdin.as_mut().ok_or("stdin not found")?; stdin.write_all(data_in.as_bytes())?; } HookStdin::File(f) => { let file_name = render_template(f, &data)?; - logger.trace(&format!( - "hook \"{}\": file stdin: {}", - hook.name, &file_name - )); + logger.trace(&format!("hook \"{}\": file stdin: {file_name}", hook.name)); let stdin = cmd.stdin.as_mut().ok_or("stdin not found")?; let file = File::open(&file_name).map_err(|e| Error::from(e).prefix(&file_name))?; let buf_reader = BufReader::new(file); @@ -189,13 +180,13 @@ where let status = cmd.wait()?; if !status.success() && !hook.allow_failure { let msg = match status.code() { - Some(code) => format!("unrecoverable failure: code {}", code).into(), + Some(code) => format!("unrecoverable failure: code {code}").into(), None => "unrecoverable failure".into(), }; return Err(msg); } match status.code() { - Some(code) => logger.debug(&format!("hook \"{}\": exited: code {}", hook.name, code)), + Some(code) => logger.debug(&format!("hook \"{}\": exited: code {code}", hook.name)), None => logger.debug(&format!("hook \"{}\": exited", hook.name)), }; Ok(()) diff --git a/acmed/src/http.rs b/acmed/src/http.rs index 7e7eb7a..7b0c048 100644 --- a/acmed/src/http.rs +++ b/acmed/src/http.rs @@ -41,8 +41,8 @@ impl ValidHttpResponse { fn from_response(response: Response) -> Result { let (_status, headers, body) = response.split(); let body = body.text()?; - log::trace!("HTTP response headers: {:?}", headers); - log::trace!("HTTP response body: {}", body); + log::trace!("HTTP response headers: {headers:?}"); + log::trace!("HTTP response body: {body}"); Ok(ValidHttpResponse { headers, body }) } } @@ -117,7 +117,7 @@ fn update_nonce(endpoint: &mut Endpoint, response: &Response) -> Result<(), Erro if let Some(nonce) = response.headers().get(HEADER_NONCE) { let nonce = header_to_string(nonce)?; if !is_nonce(&nonce) { - let msg = format!("{}: invalid nonce.", &nonce); + let msg = format!("{nonce}: invalid nonce."); return Err(msg.into()); } endpoint.nonce = Some(nonce); @@ -202,7 +202,7 @@ where let nonce = &endpoint.nonce.clone().unwrap_or_default(); let body = data_builder(nonce, url)?; rate_limit(endpoint); - log::trace!("POST request body: {}", body); + log::trace!("POST request body: {body}"); let response = session.post(url).text(&body).send()?; update_nonce(endpoint, &response)?; match check_status(&response) { diff --git a/acmed/src/identifier.rs b/acmed/src/identifier.rs index 7713c1e..94b6c8b 100644 --- a/acmed/src/identifier.rs +++ b/acmed/src/identifier.rs @@ -12,7 +12,7 @@ fn u8_to_nibbles_string(value: &u8) -> String { let bytes = value.to_ne_bytes(); let first = bytes[0] & 0x0f; let second = (bytes[0] >> 4) & 0x0f; - format!("{:x}.{:x}", first, second) + format!("{first:x}.{second:x}") } #[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] @@ -38,7 +38,7 @@ impl fmt::Display for IdentifierType { IdentifierType::Dns => "dns", IdentifierType::Ip => "ip", }; - write!(f, "{}", name) + write!(f, "{name}") } } @@ -63,10 +63,8 @@ impl Identifier { }; let challenge = Challenge::from_str(challenge)?; if !id_type.supported_challenges().contains(&challenge) { - let msg = format!( - "challenge {} cannot be used with identifier of type {}", - challenge, id_type - ); + let msg = + format!("challenge {challenge} cannot be used with identifier of type {id_type}"); return Err(msg.into()); } Ok(Identifier { @@ -89,7 +87,7 @@ impl Identifier { .map(|v| v.to_string()) .collect::>() .join("."); - let dn = format!("{}.in-addr.arpa", dn); + let dn = format!("{dn}.in-addr.arpa"); Ok(dn) } IpAddr::V6(ip) => { @@ -100,7 +98,7 @@ impl Identifier { .map(u8_to_nibbles_string) .collect::>() .join("."); - let dn = format!("{}.ip6.arpa", dn); + let dn = format!("{dn}.ip6.arpa"); Ok(dn) } }, diff --git a/acmed/src/jws.rs b/acmed/src/jws.rs index cc07d39..8035dc8 100644 --- a/acmed/src/jws.rs +++ b/acmed/src/jws.rs @@ -31,7 +31,7 @@ fn get_jws_data( ) -> Result { let protected = b64_encode(protected); let payload = b64_encode(payload); - let signing_input = format!("{}.{}", protected, payload); + let signing_input = format!("{protected}.{payload}"); let signature = key_pair.sign(sign_alg, signing_input.as_bytes())?; let signature = b64_encode(&signature); let data = JwsData { @@ -97,13 +97,13 @@ pub fn encode_kid_mac( let protected = serde_json::to_string(&protected)?; let protected = b64_encode(&protected); let payload = b64_encode(payload); - let signing_input = format!("{}.{}", protected, payload); + let signing_input = format!("{protected}.{payload}"); let hash_func = match sign_alg { JwsSignatureAlgorithm::Hs256 => HashFunction::Sha256, JwsSignatureAlgorithm::Hs384 => HashFunction::Sha384, JwsSignatureAlgorithm::Hs512 => HashFunction::Sha512, _ => { - return Err(format!("{}: not a HMAC-based signature algorithm", sign_alg).into()); + return Err(format!("{sign_alg}: not a HMAC-based signature algorithm").into()); } }; let signature = hash_func.hmac(key, signing_input.as_bytes())?; diff --git a/acmed/src/main.rs b/acmed/src/main.rs index 151ade7..7776ab6 100644 --- a/acmed/src/main.rs +++ b/acmed/src/main.rs @@ -50,8 +50,7 @@ pub const MIN_RATE_LIMIT_SLEEP_MILISEC: u64 = 100; fn main() { let full_version = format!( - "{} built for {}\n\nCryptographic library:\n - {} {}\nHTTP client library:\n - {} {}", - APP_VERSION, + "{APP_VERSION} built for {}\n\nCryptographic library:\n - {} {}\nHTTP client library:\n - {} {}", env!("ACMED_TARGET"), get_lib_name(), get_lib_version(), @@ -135,7 +134,7 @@ fn main() { ) { Ok(_) => {} Err(e) => { - eprintln!("Error: {}", e); + eprintln!("Error: {e}"); std::process::exit(2); } }; @@ -156,7 +155,7 @@ fn main() { let mut srv = match MainEventLoop::new(config_file, &root_certs) { Ok(s) => s, Err(e) => { - error!("{}", e); + error!("{e}"); let _ = clean_pid_file(pid_file); std::process::exit(1); } diff --git a/acmed/src/main_event_loop.rs b/acmed/src/main_event_loop.rs index 35285cc..b554c91 100644 --- a/acmed/src/main_event_loop.rs +++ b/acmed/src/main_event_loop.rs @@ -137,7 +137,7 @@ impl MainEventLoop { }; let crt_id = cert.get_id(); if certs.iter().any(|c| c.get_id() == crt_id) { - let msg = format!("{}: duplicate certificate id", crt_id); + let msg = format!("{crt_id}: duplicate certificate id"); return Err(msg.into()); } match accounts.get_mut(&crt.account) { diff --git a/acmed/src/storage.rs b/acmed/src/storage.rs index c42a65a..78c7f35 100644 --- a/acmed/src/storage.rs +++ b/acmed/src/storage.rs @@ -34,19 +34,19 @@ pub struct FileManager { impl HasLogger for FileManager { fn warn(&self, msg: &str) { - log::warn!("{}: {}", self, msg); + log::warn!("{self}: {msg}"); } fn info(&self, msg: &str) { - log::info!("{}: {}", self, msg); + log::info!("{self}: {msg}"); } fn debug(&self, msg: &str) { - log::debug!("{}: {}", self, msg); + log::debug!("{self}: {msg}"); } fn trace(&self, msg: &str) { - log::trace!("{}: {}", self, msg); + log::trace!("{self}: {msg}"); } } @@ -57,7 +57,7 @@ impl fmt::Display for FileManager { } else { format!("account \"{}\"", self.account_name) }; - write!(f, "{}", s) + write!(f, "{s}") } } @@ -75,7 +75,7 @@ impl fmt::Display for FileType { FileType::PrivateKey => "pk", FileType::Certificate => "crt", }; - write!(f, "{}", s) + write!(f, "{s}") } } @@ -124,7 +124,7 @@ fn get_file_path(fm: &FileManager, file_type: FileType) -> Result Result, Error> { - fm.trace(&format!("reading file {:?}", path)); + fm.trace(&format!("reading file {path:?}")); let mut file = File::open(path).map_err(|e| Error::from(e).prefix(&path.display().to_string()))?; let mut contents = vec![]; @@ -173,16 +173,16 @@ fn set_owner(fm: &FileManager, path: &Path, file_type: FileType) -> Result<(), E None => None, }; match uid { - Some(u) => fm.trace(&format!("{:?}: setting the uid to {}", path, u.as_raw())), - None => fm.trace(&format!("{:?}: uid unchanged", path)), + Some(u) => fm.trace(&format!("{path:?}: setting the uid to {}", u.as_raw())), + None => fm.trace(&format!("{path:?}: uid unchanged")), }; match gid { - Some(g) => fm.trace(&format!("{:?}: setting the gid to {}", path, g.as_raw())), - None => fm.trace(&format!("{:?}: gid unchanged", path)), + Some(g) => fm.trace(&format!("{path:?}: setting the gid to {}", g.as_raw())), + None => fm.trace(&format!("{path:?}: gid unchanged")), }; match nix::unistd::chown(path, uid, gid) { Ok(_) => Ok(()), - Err(e) => Err(format!("{}", e).into()), + Err(e) => Err(format!("{e}").into()), } } @@ -203,7 +203,7 @@ fn write_file(fm: &FileManager, file_type: FileType, data: &[u8]) -> Result<(), hooks::call(fm, &fm.hooks, &hook_data, HookType::FilePreEdit)?; } - fm.trace(&format!("writing file {:?}", path)); + fm.trace(&format!("writing file {path:?}")); let mut file = if cfg!(unix) { let mut options = OpenOptions::new(); options.mode(match &file_type { diff --git a/tacd/build.rs b/tacd/build.rs index 0aa9929..75370d7 100644 --- a/tacd/build.rs +++ b/tacd/build.rs @@ -33,7 +33,7 @@ macro_rules! set_runstate_path_if_absent { fn main() { if let Ok(target) = env::var("TARGET") { - println!("cargo:rustc-env=TACD_TARGET={}", target); + println!("cargo:rustc-env=TACD_TARGET={target}"); }; set_runstate_path_if_absent!("TACD_DEFAULT_PID_FILE", "tacd.pid"); diff --git a/tacd/src/main.rs b/tacd/src/main.rs index 6e91be7..3dc714a 100644 --- a/tacd/src/main.rs +++ b/tacd/src/main.rs @@ -36,8 +36,7 @@ fn get_acme_value(cnf: &ArgMatches, opt: &str, opt_file: &str) -> Result Ok(v.to_string()), None => { debug!( - "reading {} from {}", - opt, + "reading {opt} from {}", cnf.get_one::(opt_file) .map(|e| e.as_str()) .unwrap_or("stdin") @@ -68,15 +67,14 @@ fn init(cnf: &ArgMatches) -> Result<(), Error> { None => DEFAULT_CRT_DIGEST, }; let (pk, cert) = X509Certificate::from_acme_ext(&domain, &ext, crt_signature_alg, crt_digest)?; - info!("starting {} on {} for {}", APP_NAME, listen_addr, domain); + info!("starting {APP_NAME} on {listen_addr} for {domain}"); server_start(listen_addr, &cert, &pk)?; Ok(()) } fn main() { let full_version = format!( - "{} built for {}\n\nCryptographic library:\n - {} {}", - APP_VERSION, + "{APP_VERSION} built for {}\n\nCryptographic library:\n - {} {}", env!("TACD_TARGET"), get_lib_name(), get_lib_version(), @@ -204,7 +202,7 @@ fn main() { ) { Ok(_) => {} Err(e) => { - eprintln!("Error: {}", e); + eprintln!("Error: {e}"); std::process::exit(2); } }; @@ -212,7 +210,7 @@ fn main() { match init(&matches) { Ok(_) => {} Err(e) => { - error!("{}", e); + error!("{e}"); let pid_file = matches.get_one::("pid-file").map(|e| e.as_str()); let _ = clean_pid_file(pid_file); std::process::exit(1); diff --git a/tacd/src/openssl_server.rs b/tacd/src/openssl_server.rs index df26cb1..8999869 100644 --- a/tacd/src/openssl_server.rs +++ b/tacd/src/openssl_server.rs @@ -45,10 +45,10 @@ pub fn start( let acceptor = Arc::new(acceptor.build()); if cfg!(unix) && listen_addr.starts_with("unix:") { let listen_addr = &listen_addr[5..]; - debug!("listening on unix socket {}", listen_addr); + debug!("listening on unix socket {listen_addr}"); listen_and_accept!(UnixListener, listen_addr, acceptor); } else { - debug!("listening on {}", listen_addr); + debug!("listening on {listen_addr}"); listen_and_accept!(TcpListener, listen_addr, acceptor); } Err("main thread loop unexpectedly exited".into())