From 7140cffef397007746ab3d93ef15b7f3c98576b5 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Fri, 3 Jan 2020 13:41:56 +0100 Subject: openpgp: Simplify crypto::hash_file. - The context knows the algorithm now. --- openpgp/src/crypto/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'openpgp/src/crypto/mod.rs') 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(reader: R, algos: &[HashAlgorithm]) - -> Result> + -> Result> { use std::mem; @@ -188,10 +188,10 @@ pub fn hash_file(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::>()) .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); -- cgit v1.2.3