summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-01-03 13:41:56 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-01-03 13:41:56 +0100
commit7140cffef397007746ab3d93ef15b7f3c98576b5 (patch)
tree45dd9e99f00145920e41a0b0b9436c0580ff3fa5
parenta608d9a1c57560a42cfc3b9642586166f8ab8e52 (diff)
openpgp: Simplify crypto::hash_file.
- The context knows the algorithm now.
-rw-r--r--openpgp/src/crypto/mod.rs9
-rw-r--r--sqv/src/sqv.rs2
2 files changed, 6 insertions, 5 deletions
diff --git a/openpgp/src/crypto/mod.rs b/openpgp/src/crypto/mod.rs
index 51db3b18..7955d810 100644
--- a/openpgp/src/crypto/mod.rs
+++ b/openpgp/src/crypto/mod.rs
@@ -169,7 +169,7 @@ impl Password {
///
/// This is useful when verifying detached signatures.
pub fn hash_file<R: Read>(reader: R, algos: &[HashAlgorithm])
- -> Result<Vec<(HashAlgorithm, hash::Context)>>
+ -> Result<Vec<hash::Context>>
{
use std::mem;
@@ -188,10 +188,10 @@ pub fn hash_file<R: Read>(reader: R, algos: &[HashAlgorithm])
// Hash all of the data.
reader.drop_eof()?;
- let mut hashes =
+ let hashes =
mem::replace(&mut reader.cookie_mut().sig_group_mut().hashes,
Default::default());
- let hashes = hashes.drain(..).collect();
+ let hashes = hashes.into_iter().map(|(_, ctx)| ctx).collect();
Ok(hashes)
}
@@ -210,7 +210,8 @@ fn hash_file_test() {
&expected.keys().cloned().collect::<Vec<HashAlgorithm>>())
.unwrap();
- for (algo, mut hash) in result.into_iter() {
+ for mut hash in result.into_iter() {
+ let algo = hash.algo();
let mut digest = vec![0u8; hash.digest_size()];
hash.digest(&mut digest);
diff --git a/sqv/src/sqv.rs b/sqv/src/sqv.rs
index ac78c8c5..a7ddf0e7 100644
--- a/sqv/src/sqv.rs
+++ b/sqv/src/sqv.rs
@@ -150,7 +150,7 @@ fn real_main() -> Result<(), failure::Error> {
= sigs.iter().map(|&(ref sig, _)| sig.hash_algo()).collect();
let hashes: HashMap<_, _> =
openpgp::crypto::hash_file(File::open(file)?, &hash_algos[..])?
- .into_iter().collect();
+ .into_iter().map(|ctx| (ctx.algo(), ctx)).collect();
fn cert_has_key(cert: &Cert, keyid: &KeyID) -> bool {
// Even if a key is revoked or expired, we can still use it to