diff --git a/card-functionality/src/import.rs b/card-functionality/src/import.rs index 42bb2d4..da2346e 100644 --- a/card-functionality/src/import.rs +++ b/card-functionality/src/import.rs @@ -29,7 +29,7 @@ fn main() -> Result<()> { print!("Set user data"); let userdata_out = run_test(&mut card, test_set_user_data, &[])?; - println!(" {:x?}", userdata_out); + println!(" {userdata_out:x?}"); let key_files = { let config = card.get_config(); @@ -42,20 +42,20 @@ fn main() -> Result<()> { for key_file in &key_files { // upload keys - print!("Upload key '{}'", key_file); + print!("Upload key '{key_file}'"); let upload_res = run_test(&mut card, test_upload_keys, &[key_file]); if let Err(TestError::KeyUploadError(_file, err)) = &upload_res { // The card doesn't support this key type, so skip to the // next key - don't try to decrypt/sign for this key. - println!(" => Upload failed ({:?}), skip tests", err); + println!(" => Upload failed ({err:?}), skip tests"); continue; } let upload_out = upload_res?; - println!(" {:x?}", upload_out); + println!(" {upload_out:x?}"); let key = std::fs::read_to_string(key_file).expect("Unable to read ciphertext"); @@ -66,13 +66,13 @@ fn main() -> Result<()> { let ciphertext = util::encrypt_to("Hello world!\n", &c)?; let dec_out = run_test(&mut card, test_decrypt, &[&key, &ciphertext])?; - println!(" {:x?}", dec_out); + println!(" {dec_out:x?}"); // sign print!(" Sign"); let sign_out = run_test(&mut card, test_sign, &[&key])?; - println!(" {:x?}", sign_out); + println!(" {sign_out:x?}"); } // FIXME: import key with password diff --git a/card-functionality/src/keygen.rs b/card-functionality/src/keygen.rs index a561488..2cce5b5 100644 --- a/card-functionality/src/keygen.rs +++ b/card-functionality/src/keygen.rs @@ -53,7 +53,7 @@ fn main() -> Result<()> { }; for algo in algos { - println!("Generate key [{}]", algo); + println!("Generate key [{algo}]"); let res = run_test(&mut card, test_keygen, &[&algo])?; @@ -61,7 +61,7 @@ fn main() -> Result<()> { // sign print!(" Sign"); let sign_out = run_test(&mut card, test_sign, &[cert])?; - println!(" {:x?}", sign_out); + println!(" {sign_out:x?}"); // decrypt let c = Cert::from_str(cert)?; @@ -69,7 +69,7 @@ fn main() -> Result<()> { print!(" Decrypt"); let dec_out = run_test(&mut card, test_decrypt, &[cert, &ciphertext])?; - println!(" {:x?}", dec_out); + println!(" {dec_out:x?}"); } else { panic!("Didn't get back a Cert from test_keygen"); }; diff --git a/card-functionality/src/tests.rs b/card-functionality/src/tests.rs index 236c9a1..ca9f53b 100644 --- a/card-functionality/src/tests.rs +++ b/card-functionality/src/tests.rs @@ -114,15 +114,15 @@ fn check_key_upload_metadata( let card_fp = ard.fingerprints()?; let sig = card_fp.signature().expect("signature fingerprint"); - assert_eq!(format!("{:X}", sig), meta[0].0); + assert_eq!(format!("{sig:X}"), meta[0].0); let dec = card_fp.decryption().expect("decryption fingerprint"); - assert_eq!(format!("{:X}", dec), meta[1].0); + assert_eq!(format!("{dec:X}"), meta[1].0); let auth = card_fp .authentication() .expect("authentication fingerprint"); - assert_eq!(format!("{:X}", auth), meta[2].0); + assert_eq!(format!("{auth:X}"), meta[2].0); // get_key_generation_times let card_kg = ard.key_generation_times()?; @@ -154,16 +154,16 @@ pub fn test_print_caps(pgp: &mut OpenPgp, _param: &[&str]) -> Result Result Result {:x?}", key); + println!(" sig key data from card -> {key:x?}"); // -- @@ -289,7 +289,7 @@ pub fn test_get_pub(pgp: &mut OpenPgp, _param: &[&str]) -> Result {:x?}", key); + println!(" dec key data from card -> {key:x?}"); // -- @@ -302,7 +302,7 @@ pub fn test_get_pub(pgp: &mut OpenPgp, _param: &[&str]) -> Result {:x?}", key); + println!(" auth key data from card -> {key:x?}"); Ok(vec![]) } @@ -360,7 +360,7 @@ pub fn test_private_data(pgp: &mut OpenPgp, _param: &[&str]) -> Result Result Result Result Result<(), Box> { // card metadata let app_id = transaction.application_identifier()?; - println!("{:x?}\n", app_id); + println!("{app_id:x?}\n"); let eli = transaction.extended_length_information()?; - println!("extended_length_info: {:?}\n", eli); + println!("extended_length_info: {eli:?}\n"); let hist = transaction.historical_bytes()?; - println!("{:#x?}\n", hist); + println!("{hist:#x?}\n"); let ext = transaction.extended_capabilities()?; - println!("{:#x?}\n", ext); + println!("{ext:#x?}\n"); let pws = transaction.pw_status_bytes()?; - println!("{:#x?}\n", pws); + println!("{pws:#x?}\n"); // cardholder let ch = transaction.cardholder_related_data()?; - println!("{:#x?}\n", ch); + println!("{ch:#x?}\n"); // crypto-ish metadata let fp = transaction.fingerprints()?; - println!("Fingerprint {:#x?}\n", fp); + println!("Fingerprint {fp:#x?}\n"); match transaction.algorithm_information() { - Ok(Some(ai)) => println!("Algorithm information:\n{}", ai), + Ok(Some(ai)) => println!("Algorithm information:\n{ai}"), Ok(None) => println!("No Algorithm information found"), - Err(e) => println!("Error getting Algorithm information: {:?}", e), + Err(e) => println!("Error getting Algorithm information: {e:?}"), } println!("Current algorithm attributes on card:"); let algo = transaction.algorithm_attributes(KeyType::Signing)?; - println!("Sig: {}", algo); + println!("Sig: {algo}"); let algo = transaction.algorithm_attributes(KeyType::Decryption)?; - println!("Dec: {}", algo); + println!("Dec: {algo}"); let algo = transaction.algorithm_attributes(KeyType::Authentication)?; - println!("Aut: {}", algo); + println!("Aut: {algo}"); println!(); @@ -87,7 +87,7 @@ fn main() -> Result<(), Box> { assert_eq!(app_id.ident(), test_card_ident.to_ascii_uppercase()); let check = transaction.check_admin_verified(); - println!("has admin (pw3) been verified yet?\n{:x?}\n", check); + println!("has admin (pw3) been verified yet?\n{check:x?}\n"); println!("factory reset\n"); transaction.factory_reset()?; @@ -96,7 +96,7 @@ fn main() -> Result<(), Box> { println!("verify for admin ok"); let check = transaction.check_user_verified(); - println!("has user (pw1/82) been verified yet? {:x?}", check); + println!("has user (pw1/82) been verified yet? {check:x?}"); // Use Admin access to card let mut admin = transaction.admin_card().expect("just verified"); @@ -148,13 +148,13 @@ fn main() -> Result<(), Box> { assert_eq!(app_id.ident(), test_card_ident.to_ascii_uppercase()); let check = transaction.check_user_verified(); - println!("has user (pw1/82) been verified yet?\n{:x?}\n", check); + println!("has user (pw1/82) been verified yet?\n{check:x?}\n"); transaction.verify_user(b"123456")?; println!("verify for user (pw1/82) ok"); let check = transaction.check_user_verified(); - println!("has user (pw1/82) been verified yet?\n{:x?}\n", check); + println!("has user (pw1/82) been verified yet?\n{check:x?}\n"); // Use User access to card let mut user = transaction @@ -164,14 +164,14 @@ fn main() -> Result<(), Box> { let _cert = Cert::from_file(TEST_KEY_PATH)?; let msg = std::fs::read_to_string(TEST_ENC_MSG).expect("Unable to read file"); - println!("Encrypted message:\n{}", msg); + println!("Encrypted message:\n{msg}"); let sp = StandardPolicy::new(); let d = user.decryptor(&|| println!("Touch confirmation needed for decryption"))?; let res = sq_util::decryption_helper(d, msg.into_bytes(), &sp)?; let plain = String::from_utf8_lossy(&res); - println!("Decrypted plaintext: {}", plain); + println!("Decrypted plaintext: {plain}"); assert_eq!(plain, "Hello world!\n"); @@ -197,7 +197,7 @@ fn main() -> Result<(), Box> { let signer = sign.signer(&|| {})?; let sig = sq_util::sign_helper(signer, &mut text.as_bytes())?; - println!("Signature from card:\n{}", sig) + println!("Signature from card:\n{sig}") // FIXME: validate sig } else { diff --git a/openpgp-card-sequoia/src/privkey.rs b/openpgp-card-sequoia/src/privkey.rs index 6c9337b..c537609 100644 --- a/openpgp-card-sequoia/src/privkey.rs +++ b/openpgp-card-sequoia/src/privkey.rs @@ -53,7 +53,7 @@ impl CardUploadableKey for SequoiaKey { .key .clone() .decrypt_secret(&sequoia_openpgp::crypto::Password::from(pw.as_str())) - .map_err(|e| Error::InternalError(format!("sequoia decrypt failed {:?}", e)))?, + .map_err(|e| Error::InternalError(format!("sequoia decrypt failed {e:?}")))?, }; // Get private cryptographic material @@ -129,7 +129,7 @@ impl SqRSA { q: ProtectedMPI, ) -> Result { let nettle = nettle::rsa::PrivateKey::new(d.value(), p.value(), q.value(), None) - .map_err(|e| Error::InternalError(format!("nettle error {:?}", e)))?; + .map_err(|e| Error::InternalError(format!("nettle error {e:?}")))?; Ok(Self { e, n, p, q, nettle }) } diff --git a/openpgp-card-sequoia/src/util.rs b/openpgp-card-sequoia/src/util.rs index a4ba462..5583187 100644 --- a/openpgp-card-sequoia/src/util.rs +++ b/openpgp-card-sequoia/src/util.rs @@ -37,8 +37,8 @@ use crate::{Card, PublicKey}; /// /// FIXME: accept optional metadata for user_id(s)? #[allow(clippy::too_many_arguments)] -pub fn make_cert<'app>( - open: &mut Card>, +pub fn make_cert( + open: &mut Card>, key_sig: PublicKey, key_dec: Option, key_aut: Option, @@ -230,7 +230,7 @@ pub fn public_key_material_to_key( match pkm { PublicKeyMaterial::R(rsa) => { let k4 = Key4::import_public_rsa(rsa.v(), rsa.n(), Some(time)).map_err(|e| { - Error::InternalError(format!("sequoia Key4::import_public_rsa failed: {:?}", e)) + Error::InternalError(format!("sequoia Key4::import_public_rsa failed: {e:?}")) })?; Ok(k4.into()) @@ -254,8 +254,7 @@ pub fn public_key_material_to_key( let k4 = Key4::import_public_ed25519(ecc.data(), time).map_err(|e| { Error::InternalError(format!( - "sequoia Key4::import_public_ed25519 failed: {:?}", - e + "sequoia Key4::import_public_ed25519 failed: {e:?}" )) })?; @@ -272,8 +271,7 @@ pub fn public_key_material_to_key( ) .map_err(|e| { Error::InternalError(format!( - "sequoia Key4::new for ECDSA failed: {:?}", - e + "sequoia Key4::new for ECDSA failed: {e:?}" )) })?; @@ -286,8 +284,7 @@ pub fn public_key_material_to_key( let k4 = Key4::import_public_cv25519(ecc.data(), hash, sym, time) .map_err(|e| { Error::InternalError(format!( - "sequoia Key4::import_public_cv25519 failed: {:?}", - e + "sequoia Key4::import_public_cv25519 failed: {e:?}" )) })?; @@ -306,8 +303,7 @@ pub fn public_key_material_to_key( ) .map_err(|e| { Error::InternalError(format!( - "sequoia Key4::new for ECDH failed: {:?}", - e + "sequoia Key4::new for ECDH failed: {e:?}" )) })?; diff --git a/openpgp-card/src/algorithm.rs b/openpgp-card/src/algorithm.rs index 0e81124..47f6d7e 100644 --- a/openpgp-card/src/algorithm.rs +++ b/openpgp-card/src/algorithm.rs @@ -45,7 +45,7 @@ impl TryFrom<&str> for AlgoSimple { "NIST384" => NIST384, "NIST521" => NIST521, "Curve25519" => Curve25519, - _ => return Err(Error::UnsupportedAlgo(format!("unexpected algo {}", algo))), + _ => return Err(Error::UnsupportedAlgo(format!("unexpected algo {algo}"))), }) } } @@ -175,7 +175,7 @@ impl fmt::Display for Algo { ) } Self::Unknown(u) => { - write!(f, "Unknown: {:?}", u) + write!(f, "Unknown: {u:?}") } } } @@ -188,10 +188,7 @@ impl Algo { match self { Algo::Rsa(rsa) => Self::rsa_algo_attrs(rsa), Algo::Ecc(ecc) => Self::ecc_algo_attrs(ecc.oid(), ecc.ecc_type()), - _ => Err(Error::UnsupportedAlgo(format!( - "Unexpected Algo {:?}", - self - ))), + _ => Err(Error::UnsupportedAlgo(format!("Unexpected Algo {self:?}"))), } } @@ -351,7 +348,7 @@ impl TryFrom<&[u8]> for Curve { oid::ED448 => Ed448, oid::X448 => X448, - _ => return Err(Error::ParseError(format!("Unknown curve OID {:?}", oid))), + _ => return Err(Error::ParseError(format!("Unknown curve OID {oid:?}"))), }; Ok(curve) diff --git a/openpgp-card/src/apdu/command.rs b/openpgp-card/src/apdu/command.rs index 2e37bfe..cdb6497 100644 --- a/openpgp-card/src/apdu/command.rs +++ b/openpgp-card/src/apdu/command.rs @@ -93,8 +93,8 @@ impl Command { if !ext_len { assert!( len <= 0xff, - "unexpected: len = {:x?}, but ext says Short", - len + "{}", + "unexpected: len = {len:x?}, but ext says Short" ); } diff --git a/openpgp-card/src/card_do.rs b/openpgp-card/src/card_do.rs index 1ea5560..6276dd5 100644 --- a/openpgp-card/src/card_do.rs +++ b/openpgp-card/src/card_do.rs @@ -112,8 +112,7 @@ impl ApplicationRelatedData { Algo::try_from(&aa.serialize()[..]) } else { Err(Error::NotFound(format!( - "Failed to get algorithm attributes for {:?}.", - key_type + "Failed to get algorithm attributes for {key_type:?}." ))) } } @@ -317,7 +316,7 @@ impl TryFrom> for UIF { if v.len() == 2 { Ok(UIF(v.try_into().unwrap())) } else { - Err(Error::ParseError(format!("Can't get UID from {:x?}", v))) + Err(Error::ParseError(format!("Can't get UID from {v:x?}"))) } } } @@ -388,7 +387,7 @@ impl Display for TouchPolicy { TouchPolicy::Fixed => write!(f, "Fixed"), TouchPolicy::Cached => write!(f, "Cached"), TouchPolicy::CachedFixed => write!(f, "CachedFixed"), - TouchPolicy::Unknown(i) => write!(f, "Unknown({})", i), + TouchPolicy::Unknown(i) => write!(f, "Unknown({i})"), } } } @@ -575,7 +574,7 @@ impl Display for KeyStatus { KeyStatus::NotPresent => write!(f, "not present"), KeyStatus::Generated => write!(f, "generated"), KeyStatus::Imported => write!(f, "imported"), - KeyStatus::Unknown(i) => write!(f, "unknown status ({})", i), + KeyStatus::Unknown(i) => write!(f, "unknown status ({i})"), } } } @@ -755,19 +754,15 @@ impl Display for ExtendedCapabilities { // v2 if let Some(max_cmd_len) = self.max_cmd_len { - writeln!(f, "- maximum command length: {}", max_cmd_len)?; + writeln!(f, "- maximum command length: {max_cmd_len}")?; } if let Some(max_resp_len) = self.max_resp_len { - writeln!(f, "- maximum response length: {}", max_resp_len)?; + writeln!(f, "- maximum response length: {max_resp_len}")?; } // v3 if let Some(max_len_special_do) = self.max_len_special_do { - writeln!( - f, - "- maximum length for special DOs: {}", - max_len_special_do - )?; + writeln!(f, "- maximum length for special DOs: {max_len_special_do}")?; } if self.pin_block_2_format_support == Some(true) { writeln!(f, "- PIN block 2 format supported")?; @@ -809,7 +804,7 @@ impl Display for CardholderRelatedData { writeln!(f, "Name: {}", Self::latin1_to_string(name))?; } if let Some(sex) = self.sex { - writeln!(f, "Sex: {}", sex)?; + writeln!(f, "Sex: {sex}")?; } if let Some(lang) = &self.lang { for (n, l) in lang.iter().enumerate() { @@ -839,7 +834,7 @@ impl Display for Sex { Self::Male => write!(f, "Male"), Self::Female => write!(f, "Female"), Self::NotApplicable => write!(f, "Not applicable"), - Self::UndefinedValue(v) => write!(f, "Undefined value {:x?}", v), + Self::UndefinedValue(v) => write!(f, "Undefined value {v:x?}"), } } } @@ -884,7 +879,7 @@ impl Display for Lang { write!(f, "{}{}", v[0] as char, v[1] as char) } Self::Invalid(v) => { - write!(f, "{:x?}", v) + write!(f, "{v:x?}") } } } @@ -1023,8 +1018,7 @@ pub(crate) fn complete(result: nom::IResult<&[u8], O>) -> Result { Ok(output) } else { Err(Error::ParseError(format!( - "Parsing incomplete, trailing data: {:x?}", - rem + "Parsing incomplete, trailing data: {rem:x?}" ))) } } diff --git a/openpgp-card/src/card_do/algo_info.rs b/openpgp-card/src/card_do/algo_info.rs index 37bbfd1..1c90724 100644 --- a/openpgp-card/src/card_do/algo_info.rs +++ b/openpgp-card/src/card_do/algo_info.rs @@ -33,7 +33,7 @@ impl fmt::Display for AlgoInfo { KeyType::Authentication => "AUT", KeyType::Attestation => "ATT", }; - writeln!(f, "{}: {} ", kt, a)?; + writeln!(f, "{kt}: {a} ")?; } Ok(()) } diff --git a/openpgp-card/src/card_do/extended_cap.rs b/openpgp-card/src/card_do/extended_cap.rs index 542d2c9..1a34853 100644 --- a/openpgp-card/src/card_do/extended_cap.rs +++ b/openpgp-card/src/card_do/extended_cap.rs @@ -80,8 +80,7 @@ impl TryFrom<(&[u8], u16)> for ExtendedCapabilities { if i8 > 1 { return Err(Error::ParseError(format!( - "Illegal value '{}' for pin_block_2_format_support", - i8 + "Illegal value '{i8}' for pin_block_2_format_support" ))); } @@ -89,8 +88,7 @@ impl TryFrom<(&[u8], u16)> for ExtendedCapabilities { if i9 > 1 { return Err(Error::ParseError(format!( - "Illegal value '{}' for mse_command_support", - i9 + "Illegal value '{i9}' for mse_command_support" ))); } mse_command_support = Some(i9 != 0); diff --git a/openpgp-card/src/card_do/fingerprint.rs b/openpgp-card/src/card_do/fingerprint.rs index 6c0ea9a..1f86572 100644 --- a/openpgp-card/src/card_do/fingerprint.rs +++ b/openpgp-card/src/card_do/fingerprint.rs @@ -44,14 +44,14 @@ impl Fingerprint { impl fmt::Display for Fingerprint { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:X}", self) + write!(f, "{self:X}") } } impl fmt::UpperHex for Fingerprint { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for b in &self.0 { - write!(f, "{:02X}", b)?; + write!(f, "{b:02X}")?; } Ok(()) } @@ -133,9 +133,6 @@ mod test { let fp = Fingerprint::try_from(&data1[..]).expect("failed to parse fingerprint"); - assert_eq!( - format!("{}", fp), - "B7CD9F76371E077F761C826555543E6D656D1D80" - ); + assert_eq!(format!("{fp}"), "B7CD9F76371E077F761C826555543E6D656D1D80"); } } diff --git a/openpgp-card/src/card_do/historical.rs b/openpgp-card/src/card_do/historical.rs index 971bb40..f12e759 100644 --- a/openpgp-card/src/card_do/historical.rs +++ b/openpgp-card/src/card_do/historical.rs @@ -100,8 +100,7 @@ impl TryFrom<&[u8]> for HistoricalBytes { // historical bytes cannot be this short return Err(Error::ParseError(format!( - "Historical bytes too short ({} bytes), must be >= 4", - len + "Historical bytes too short ({len} bytes), must be >= 4" ))); } diff --git a/openpgp-card/src/keys.rs b/openpgp-card/src/keys.rs index e3511e6..b283428 100644 --- a/openpgp-card/src/keys.rs +++ b/openpgp-card/src/keys.rs @@ -76,7 +76,7 @@ pub(crate) fn gen_key_with_metadata( // Store creation timestamp (unix time format, limited to u32) let ts = time .duration_since(UNIX_EPOCH) - .map_err(|e| Error::InternalError(format!("This should never happen {}", e)))? + .map_err(|e| Error::InternalError(format!("This should never happen {e}")))? .as_secs() as u32; let ts = ts.into(); @@ -111,8 +111,7 @@ fn tlv_to_pubkey(tlv: &Tlv, algo: &Algo) -> Result Err(Error::UnsupportedAlgo(format!( - "Unexpected public key material from card {:?}", - tlv + "Unexpected public key material from card {tlv:?}" ))), } } @@ -285,8 +284,7 @@ pub(crate) fn determine_ecc_attrs( if algos.is_empty() { // If oid is not in algo_info, return error. return Err(Error::UnsupportedAlgo(format!( - "Oid {:?} unsupported according to algo_info", - oid + "Oid {oid:?} unsupported according to algo_info" ))); } @@ -340,8 +338,7 @@ fn card_algo_rsa(algo_info: AlgoInfo, key_type: KeyType, rsa_bits: u16) -> Resul } else { // RSA with this bit length is not in algo_info Err(Error::UnsupportedAlgo(format!( - "RSA {} unsupported according to algo_info", - rsa_bits + "RSA {rsa_bits} unsupported according to algo_info" ))) } } diff --git a/openpgp-card/src/lib.rs b/openpgp-card/src/lib.rs index 4119254..a89a12a 100644 --- a/openpgp-card/src/lib.rs +++ b/openpgp-card/src/lib.rs @@ -39,7 +39,6 @@ mod openpgp; mod tlv; use std::convert::TryInto; -use std::ops::{Deref, DerefMut}; use crate::apdu::commands; use crate::card_do::ApplicationRelatedData; @@ -186,19 +185,6 @@ pub trait CardTransaction { } } -impl<'a> Deref for dyn CardTransaction + Send + Sync + 'a { - type Target = dyn CardTransaction + 'a; - - fn deref(&self) -> &Self::Target { - self - } -} -impl<'a> DerefMut for dyn CardTransaction + Send + Sync + 'a { - fn deref_mut(&mut self) -> &mut Self::Target { - self - } -} - /// Information about the capabilities of a card. /// /// CardCaps is used to signal capabilities (chaining, extended length support, max diff --git a/pcsc/src/lib.rs b/pcsc/src/lib.rs index 1258c45..98dedd6 100644 --- a/pcsc/src/lib.rs +++ b/pcsc/src/lib.rs @@ -126,8 +126,7 @@ impl<'b> PcscTransaction<'b> { c.reconnect(mode, pcsc::Protocols::ANY, Disposition::ResetCard) .map_err(|e| { Error::Smartcard(SmartcardError::Error(format!( - "Reconnect failed: {:?}", - e + "Reconnect failed: {e:?}" ))) })?; } @@ -139,8 +138,7 @@ impl<'b> PcscTransaction<'b> { Err((_, e)) => { log::trace!("start_tx: error {:?}", e); break Err(Error::Smartcard(SmartcardError::Error(format!( - "Error: {:?}", - e + "Error: {e:?}" )))); } }; @@ -162,8 +160,7 @@ impl<'b> PcscTransaction<'b> { ) -> Result { ::application_related_data(card_tx).map_err(|e| { Error::Smartcard(SmartcardError::Error(format!( - "TxClient: failed to get application_related_data {:x?}", - e + "TxClient: failed to get application_related_data {e:x?}" ))) }) } @@ -179,8 +176,7 @@ impl<'b> PcscTransaction<'b> { .control(cm_ioctl_get_feature_request, &[], &mut recv) .map_err(|e| { Error::Smartcard(SmartcardError::Error(format!( - "GET_FEATURE_REQUEST control call failed: {:?}", - e + "GET_FEATURE_REQUEST control call failed: {e:?}" ))) })?; @@ -216,7 +212,7 @@ impl CardTransaction for PcscTransaction<'_> { .transmit(cmd, &mut resp_buffer) .map_err(|e| match e { pcsc::Error::NotTransacted => Error::Smartcard(SmartcardError::NotTransacted), - _ => Error::Smartcard(SmartcardError::Error(format!("Transmit failed: {:?}", e))), + _ => Error::Smartcard(SmartcardError::Error(format!("Transmit failed: {e:?}"))), })?; Ok(resp.to_vec()) @@ -317,13 +313,13 @@ impl CardTransaction for PcscTransaction<'_> { .ok_or_else(|| Error::Smartcard(SmartcardError::Error("no reader_capability".into())))? .value() .try_into() - .map_err(|e| Error::ParseError(format!("unexpected feature data: {:?}", e)))?; + .map_err(|e| Error::ParseError(format!("unexpected feature data: {e:?}")))?; let res = self .tx .control(u32::from_be_bytes(verify_ioctl).into(), &send, &mut recv) .map_err(|e: pcsc::Error| { - Error::Smartcard(SmartcardError::Error(format!("pcsc Error: {:?}", e))) + Error::Smartcard(SmartcardError::Error(format!("pcsc Error: {e:?}"))) })?; log::trace!(" <- pcsc pinpad_verify result: {:x?}", res); @@ -420,13 +416,13 @@ impl CardTransaction for PcscTransaction<'_> { .ok_or_else(|| Error::Smartcard(SmartcardError::Error("no reader_capability".into())))? .value() .try_into() - .map_err(|e| Error::ParseError(format!("unexpected feature data: {:?}", e)))?; + .map_err(|e| Error::ParseError(format!("unexpected feature data: {e:?}")))?; let res = self .tx .control(u32::from_be_bytes(modify_ioctl).into(), &send, &mut recv) .map_err(|e: pcsc::Error| { - Error::Smartcard(SmartcardError::Error(format!("pcsc Error: {:?}", e))) + Error::Smartcard(SmartcardError::Error(format!("pcsc Error: {e:?}"))) })?; log::trace!(" <- pcsc pinpad_modify result: {:x?}", res); diff --git a/scdc/src/lib.rs b/scdc/src/lib.rs index 2dc8fb5..2632d84 100644 --- a/scdc/src/lib.rs +++ b/scdc/src/lib.rs @@ -103,16 +103,13 @@ impl ScdBackend { } else { // Create and use a new Agent based on a default Context let ctx = Context::new().map_err(|e| { - Error::Smartcard(SmartcardError::Error(format!("Context::new failed {}", e))) + Error::Smartcard(SmartcardError::Error(format!("Context::new failed {e}"))) })?; RT.lock() .unwrap() .block_on(Agent::connect(&ctx)) .map_err(|e| { - Error::Smartcard(SmartcardError::Error(format!( - "Agent::connect failed {}", - e - ))) + Error::Smartcard(SmartcardError::Error(format!("Agent::connect failed {e}"))) })? }; @@ -131,8 +128,7 @@ impl ScdBackend { fn send2(&mut self, cmd: &str) -> Result<(), Error> { self.agent.send(cmd).map_err(|e| { Error::Smartcard(SmartcardError::Error(format!( - "scdc agent send failed: {}", - e + "scdc agent send failed: {e}" ))) }) } @@ -166,7 +162,7 @@ impl ScdBackend { /// Ask scdameon to switch to using a specific OpenPGP card, based on /// its `serial`. fn select_card(&mut self, serial: &str) -> Result<(), Error> { - let send = format!("SCD SERIALNO --demand={}", serial); + let send = format!("SCD SERIALNO --demand={serial}"); self.send2(&send)?; let rt = RT.lock().unwrap(); @@ -204,7 +200,7 @@ impl ScdBackend { log::trace!("select res: {:x?}", response); if let Err(e) = response { - return Err(Error::Smartcard(SmartcardError::Error(format!("{:?}", e)))); + return Err(Error::Smartcard(SmartcardError::Error(format!("{e:?}")))); } if let Ok(..) = response { @@ -218,8 +214,7 @@ impl ScdBackend { } Err(Error::Smartcard(SmartcardError::Error(format!( - "Error sending command {}", - cmd + "Error sending command {cmd}" )))) } } @@ -250,7 +245,7 @@ impl CardTransaction for ScdTransaction<'_> { "".to_string() }; - let send = format!("SCD APDU {}{}\n", ext, hex); + let send = format!("SCD APDU {ext}{hex}\n"); log::trace!("SCDC command: '{}'", send); if send.len() > ASSUAN_LINELENGTH { @@ -268,8 +263,7 @@ impl CardTransaction for ScdTransaction<'_> { log::trace!("res: {:x?}", response); if response.is_err() { return Err(Error::Smartcard(SmartcardError::Error(format!( - "Unexpected error response from SCD {:?}", - response + "Unexpected error response from SCD {response:?}" )))); } diff --git a/tools/src/commands/admin.rs b/tools/src/commands/admin.rs index 130b08a..8fb686d 100644 --- a/tools/src/commands/admin.rs +++ b/tools/src/commands/admin.rs @@ -515,7 +515,7 @@ fn generate_command( let algo = cmd.algo.map(AlgoSimple::from); log::info!(" Key generation will be attempted with algo: {:?}", algo); - output.algorithm(format!("{:?}", algo)); + output.algorithm(format!("{algo:?}")); // 2) Then, generate keys on the card. // We need "admin" access to the card for this). diff --git a/tools/src/commands/attestation.rs b/tools/src/commands/attestation.rs index 9d003b1..40b0c20 100644 --- a/tools/src/commands/attestation.rs +++ b/tools/src/commands/attestation.rs @@ -187,7 +187,7 @@ fn statement(ident: Option, key: BaseKeySlot) -> Result<(), Box { println!("\nFailed to change the User PIN!"); - println!("{:?}", err); + println!("{err:?}"); print_gnuk_note(err, &card)?; } Ok(_) => println!("\nUser PIN has been set."), diff --git a/tools/src/commands/status.rs b/tools/src/commands/status.rs index 06084b9..280bcd5 100644 --- a/tools/src/commands/status.rs +++ b/tools/src/commands/status.rs @@ -70,7 +70,7 @@ pub fn print_status( // Language Preference if let Some(lang) = card.cardholder_related_data()?.lang() { for lang in lang { - output.language_preference(format!("{}", lang)); + output.language_preference(format!("{lang}")); } } @@ -97,7 +97,7 @@ pub fn print_status( signature_key.touch_features(format!("{}", uif.features())); } if let Some(ks) = ki.as_ref().map(|ki| ki.sig_status()) { - signature_key.status(format!("{}", ks)); + signature_key.status(format!("{ks}")); } if let Ok(pkm) = card.public_key_material(KeyType::Signing) { @@ -125,7 +125,7 @@ pub fn print_status( decryption_key.touch_features(format!("{}", uif.features())); } if let Some(ks) = ki.as_ref().map(|ki| ki.dec_status()) { - decryption_key.status(format!("{}", ks)); + decryption_key.status(format!("{ks}")); } if let Ok(pkm) = card.public_key_material(KeyType::Decryption) { decryption_key.public_key_material(pkm.to_string()); @@ -148,7 +148,7 @@ pub fn print_status( authentication_key.touch_features(format!("{}", uif.features())); } if let Some(ks) = ki.as_ref().map(|ki| ki.aut_status()) { - authentication_key.status(format!("{}", ks)); + authentication_key.status(format!("{ks}")); } if let Ok(pkm) = card.public_key_material(KeyType::Authentication) { authentication_key.public_key_material(pkm.to_string()); @@ -160,7 +160,7 @@ pub fn print_status( attestation_key.fingerprint(fp.to_spaced_hex()); } if let Ok(Some(algo)) = card.attestation_key_algorithm_attributes() { - attestation_key.algorithm(format!("{}", algo)); + attestation_key.algorithm(format!("{algo}")); } if let Ok(Some(kgt)) = card.attestation_key_generation_time() { attestation_key.creation_time(format!("{}", kgt.to_datetime())); @@ -180,7 +180,7 @@ pub fn print_status( if let Some(ki) = ki.as_ref() { if let Some(n) = (0..ki.num_additional()).find(|&n| ki.additional_ref(n) == 0x81) { let ks = ki.additional_status(n); - attestation_key.status(format!("{}", ks)); + attestation_key.status(format!("{ks}")); } }; diff --git a/tools/src/opgpcard.rs b/tools/src/opgpcard.rs index 00f19b7..731f11a 100644 --- a/tools/src/opgpcard.rs +++ b/tools/src/opgpcard.rs @@ -76,9 +76,9 @@ fn main() -> Result<(), Box> { fn output_versions(chosen: OutputVersion) { for v in OUTPUT_VERSIONS.iter() { if v == &chosen { - println!("* {}", v); + println!("* {v}"); } else { - println!(" {}", v); + println!(" {v}"); } } } diff --git a/tools/src/output/info.rs b/tools/src/output/info.rs index 5c65b36..9a6cacb 100644 --- a/tools/src/output/info.rs +++ b/tools/src/output/info.rs @@ -85,7 +85,7 @@ impl Info { if !self.card_capabilities.is_empty() { s.push_str("Card Capabilities:\n"); for c in self.card_capabilities.iter() { - s.push_str(&format!("- {}\n", c)); + s.push_str(&format!("- {c}\n")); } s.push('\n'); } @@ -93,7 +93,7 @@ impl Info { if !self.card_service_data.is_empty() { s.push_str("Card service data:\n"); for c in self.card_service_data.iter() { - s.push_str(&format!("- {}\n", c)); + s.push_str(&format!("- {c}\n")); } s.push('\n'); } @@ -101,27 +101,27 @@ impl Info { if !self.extended_length_info.is_empty() { s.push_str("Extended Length Info:\n"); for c in self.extended_length_info.iter() { - s.push_str(&format!("- {}\n", c)); + s.push_str(&format!("- {c}\n")); } s.push('\n'); } s.push_str("Extended Capabilities:\n"); for c in self.extended_capabilities.iter() { - s.push_str(&format!("- {}\n", c)); + s.push_str(&format!("- {c}\n")); } s.push('\n'); if let Some(algos) = &self.algorithms { s.push_str("Supported algorithms:\n"); for c in algos.iter() { - s.push_str(&format!("- {}\n", c)); + s.push_str(&format!("- {c}\n")); } s.push('\n'); } if let Some(v) = &self.firmware_version { - s.push_str(&format!("Firmware Version: {}\n", v)); + s.push_str(&format!("Firmware Version: {v}\n")); } Ok(s) diff --git a/tools/src/output/list.rs b/tools/src/output/list.rs index eb2d010..8483f59 100644 --- a/tools/src/output/list.rs +++ b/tools/src/output/list.rs @@ -22,7 +22,7 @@ impl List { } else { let mut s = "Available OpenPGP cards:\n".to_string(); for id in self.idents.iter() { - s.push_str(&format!(" {}\n", id)); + s.push_str(&format!(" {id}\n")); } s }; diff --git a/tools/src/output/ssh.rs b/tools/src/output/ssh.rs index 39429c5..5ba0467 100644 --- a/tools/src/output/ssh.rs +++ b/tools/src/output/ssh.rs @@ -30,10 +30,10 @@ impl Ssh { let mut s = format!("OpenPGP card {}\n\n", self.ident); if let Some(fp) = &self.authentication_key_fingerprint { - s.push_str(&format!("Authentication key fingerprint:\n{}\n\n", fp)); + s.push_str(&format!("Authentication key fingerprint:\n{fp}\n\n")); } if let Some(key) = &self.ssh_public_key { - s.push_str(&format!("SSH public key:\n{}\n", key)); + s.push_str(&format!("SSH public key:\n{key}\n")); } Ok(s) diff --git a/tools/src/output/status.rs b/tools/src/output/status.rs index 64eaa32..e65e01b 100644 --- a/tools/src/output/status.rs +++ b/tools/src/output/status.rs @@ -112,14 +112,14 @@ impl Status { let mut nl = false; if let Some(name) = &self.cardholder_name { if !name.is_empty() { - s.push_str(&format!("Cardholder: {}\n", name)); + s.push_str(&format!("Cardholder: {name}\n")); nl = true; } } if let Some(url) = &self.certificate_url { if !url.is_empty() { - s.push_str(&format!("Certificate URL: {}\n", url)); + s.push_str(&format!("Certificate URL: {url}\n")); nl = true; } } @@ -127,7 +127,7 @@ impl Status { if !self.language_preferences.is_empty() { let prefs = self.language_preferences.to_vec().join(", "); if !prefs.is_empty() { - s.push_str(&format!("Language preferences: '{}'\n", prefs)); + s.push_str(&format!("Language preferences: '{prefs}'\n")); nl = true; } } @@ -138,7 +138,7 @@ impl Status { s.push_str("Signature key:\n"); for line in self.signature_key.format(self.verbose, self.pkm) { - s.push_str(&format!(" {}\n", line)); + s.push_str(&format!(" {line}\n")); } if self.verbose { if self.user_pin_valid_for_only_one_signature { @@ -152,13 +152,13 @@ impl Status { s.push_str("Decryption key:\n"); for line in self.decryption_key.format(self.verbose, self.pkm) { - s.push_str(&format!(" {}\n", line)); + s.push_str(&format!(" {line}\n")); } s.push('\n'); s.push_str("Authentication key:\n"); for line in self.authentication_key.format(self.verbose, self.pkm) { - s.push_str(&format!(" {}\n", line)); + s.push_str(&format!(" {line}\n")); } s.push('\n'); @@ -167,7 +167,7 @@ impl Status { if attestation_key.touch_policy.is_some() || attestation_key.algorithm.is_some() { s.push_str("Attestation key:\n"); for line in attestation_key.format(self.verbose, self.pkm) { - s.push_str(&format!(" {}\n", line)); + s.push_str(&format!(" {line}\n")); } s.push('\n'); } @@ -183,10 +183,7 @@ impl Status { if self.verbose { for (keyref, status) in self.additional_key_statuses.iter() { - s.push_str(&format!( - "Additional key status (#{}): {}\n", - keyref, status - )); + s.push_str(&format!("Additional key status (#{keyref}): {status}\n")); } } @@ -311,30 +308,30 @@ impl KeySlotInfo { let mut lines = vec![]; if let Some(fp) = &self.fingerprint { - lines.push(format!("Fingerprint: {}", fp)); + lines.push(format!("Fingerprint: {fp}")); } else { lines.push("Fingerprint: [unset]".to_string()); } if let Some(ts) = &self.creation_time { - lines.push(format!("Creation Time: {}", ts)); + lines.push(format!("Creation Time: {ts}")); } if let Some(a) = &self.algorithm { - lines.push(format!("Algorithm: {}", a)); + lines.push(format!("Algorithm: {a}")); } if verbose { if let Some(policy) = &self.touch_policy { if let Some(features) = &self.touch_features { - lines.push(format!("Touch policy: {} (features: {})", policy, features)); + lines.push(format!("Touch policy: {policy} (features: {features})")); } } if let Some(status) = &self.status { - lines.push(format!("Key Status: {}", status)); + lines.push(format!("Key Status: {status}")); } } if pkm { if let Some(material) = &self.public_key_material { - lines.push(format!("Public key material: {}", material)); + lines.push(format!("Public key material: {material}")); } } diff --git a/tools/src/util.rs b/tools/src/util.rs index af846e1..a9aa949 100644 --- a/tools/src/util.rs +++ b/tools/src/util.rs @@ -133,7 +133,7 @@ pub(crate) fn open_or_stdout(f: Option<&Path>) -> Result Result { - let cardname = format!("opgpcard:{}", ident); + let cardname = format!("opgpcard:{ident}"); let (key_type, kind) = match pkm { PublicKeyMaterial::R(rsa) => {