diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2022-06-29 10:48:37 +0200 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2022-06-29 19:19:28 +0200 |
commit | 6812f587d53edfdeaf4577733d2162952b71de4d (patch) | |
tree | 62854569749f152fe5bd73f35df10472bda283ba | |
parent | 8451a9afca7e187cf584fbfc77eda15662e80e3c (diff) |
sq: Never emit a session key prefix.
-rw-r--r-- | sq/src/commands/decrypt.rs | 18 | ||||
-rw-r--r-- | sq/src/sq_cli.rs | 8 |
2 files changed, 8 insertions, 18 deletions
diff --git a/sq/src/commands/decrypt.rs b/sq/src/commands/decrypt.rs index 8e362621..af766a04 100644 --- a/sq/src/commands/decrypt.rs +++ b/sq/src/commands/decrypt.rs @@ -210,23 +210,17 @@ impl<'a> DecryptionHelper for Helper<'a> { { // Before anything else, try the session keys for sk in &self.session_keys { - let decrypted_with = if let Some(sa) = sk.symmetric_algo { - decrypt(sa, &sk.session_key).then(|| sk.clone()) + let decrypted = if let Some(sa) = sk.symmetric_algo { + decrypt(sa, &sk.session_key) } else { // We don't know which algorithm to use, // try to find one that decrypts the message. - let sa = (1u8..=19) + (1u8..=19) .map(SymmetricAlgorithm::from) - .find(|&sa| decrypt(sa, &sk.session_key)); - sa.map(|sa| { - CliSessionKey { - session_key: sk.session_key.clone(), - symmetric_algo: Some(sa), - } - }) + .any(|sa| decrypt(sa, &sk.session_key)) }; - if let Some(d) = decrypted_with { - eprintln!("Encrypted with Session Key {}", d.display_sensitive()); + if decrypted { + eprintln!("Encrypted with Session Key {}", sk.display_sensitive()); return Ok(None); } } diff --git a/sq/src/sq_cli.rs b/sq/src/sq_cli.rs index eb7438c0..5896ea25 100644 --- a/sq/src/sq_cli.rs +++ b/sq/src/sq_cli.rs @@ -2555,15 +2555,11 @@ pub struct CliSessionKeyDisplay<'a> { csk: &'a CliSessionKey, } +/// Print the session key without prefix in hexadecimal representation. impl<'a> std::fmt::Display for CliSessionKeyDisplay<'a> { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { let sk = self.csk; - match sk.symmetric_algo { - Some(sa) => { - write!(f, "{}:{}", <u8>::from(sa), hex::encode(&sk.session_key)) - } - None => write!(f, "{}", hex::encode(&sk.session_key)), - } + write!(f, "{}", hex::encode(&sk.session_key)) } } |