summaryrefslogtreecommitdiffstats
path: root/openpgp/src/parse
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-01-03 14:05:18 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-01-03 14:05:18 +0100
commitd0740a2752c7bb089dcfc666cb8933aff2587ba4 (patch)
treead1ed808c2ca091fd42cc0254e26381f6b4c8b53 /openpgp/src/parse
parent7140cffef397007746ab3d93ef15b7f3c98576b5 (diff)
openpgp: Simplify SignatureGroup::hashes.
- The hash context knows the algorithm now.
Diffstat (limited to 'openpgp/src/parse')
-rw-r--r--openpgp/src/parse/hashed_reader.rs16
-rw-r--r--openpgp/src/parse/parse.rs24
2 files changed, 20 insertions, 20 deletions
diff --git a/openpgp/src/parse/hashed_reader.rs b/openpgp/src/parse/hashed_reader.rs
index a8ec36cf..1e46adda 100644
--- a/openpgp/src/parse/hashed_reader.rs
+++ b/openpgp/src/parse/hashed_reader.rs
@@ -40,7 +40,7 @@ impl<R: BufferedReader<Cookie>> HashedReader<R> {
let mut cookie = Cookie::default();
for &algo in &algos {
cookie.sig_group_mut().hashes
- .push((algo, algo.context().unwrap()));
+ .push(algo.context().unwrap());
}
cookie.hashes_for = hashes_for;
@@ -69,11 +69,10 @@ impl Cookie {
// We fix that here by hashing the stashed data into the
// former topmost signature-group's hash.
assert!(ngroups > 1);
- for (algo, ref mut h) in
- self.sig_groups[ngroups-2].hashes.iter_mut()
+ for h in self.sig_groups[ngroups-2].hashes.iter_mut()
{
t!("({:?}): group {} {:?} hashing {} stashed bytes.",
- hashes_for, ngroups-2, algo, data.len());
+ hashes_for, ngroups-2, h.algo(), data.len());
h.update(&stashed_data);
}
@@ -101,9 +100,9 @@ impl Cookie {
return;
}
- for (algo, ref mut h) in sig_group.hashes.iter_mut() {
+ for h in sig_group.hashes.iter_mut() {
t!("{:?}): group {} {:?} hashing {} bytes.",
- hashes_for, i, algo, data.len());
+ hashes_for, i, h.algo(), data.len());
h.update(data);
}
}
@@ -275,12 +274,13 @@ mod test {
let mut hashes = mem::replace(&mut cookie.sig_group_mut().hashes,
Default::default());
- for (algo, ref mut hash) in hashes.iter_mut() {
+ for hash in hashes.iter_mut() {
+ let algo = hash.algo();
let mut digest = vec![0u8; hash.digest_size()];
hash.digest(&mut digest);
assert_eq!(digest,
- &crate::fmt::from_hex(test.expected.get(algo)
+ &crate::fmt::from_hex(test.expected.get(&algo)
.unwrap(), true)
.unwrap()[..],
"Algo: {:?}", algo);
diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs
index b4093d1d..2c881662 100644
--- a/openpgp/src/parse/parse.rs
+++ b/openpgp/src/parse/parse.rs
@@ -515,14 +515,14 @@ pub(crate) struct SignatureGroup {
/// stack.
ops_count: usize,
- /// Maps hash algorithms to hash contexts.
- pub(crate) hashes: Vec<(HashAlgorithm, crypto::hash::Context)>,
+ /// The hash contexts.
+ pub(crate) hashes: Vec<crypto::hash::Context>,
}
impl fmt::Debug for SignatureGroup {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let algos = self.hashes.iter().map(|(a, _)| a)
- .collect::<Vec<&HashAlgorithm>>();
+ let algos = self.hashes.iter().map(|ctx| ctx.algo())
+ .collect::<Vec<_>>();
f.debug_struct("Cookie")
.field("ops_count", &self.ops_count)
@@ -1079,8 +1079,8 @@ impl Signature4 {
cookie.sig_group_mut().ops_count -= 1;
if let Some(hash) =
cookie.sig_group().hashes.iter().find_map(
- |(a, h)| if *a == hash_algo {
- Some(h)
+ |ctx| if ctx.algo() == hash_algo {
+ Some(ctx)
} else {
None
})
@@ -1556,12 +1556,12 @@ impl OnePassSig3 {
// Make sure that it uses the required
// hash algorithm.
- if ! cookie.sig_group()
- .hashes.iter().any(|(a, _)| *a == hash_algo)
+ if ! cookie.sig_group().hashes.iter()
+ .any(|ctx| ctx.algo() == hash_algo)
{
if let Ok(ctx) = hash_algo.context() {
cookie.sig_group_mut()
- .hashes.push((hash_algo, ctx));
+ .hashes.push(ctx);
}
}
@@ -2371,9 +2371,9 @@ impl MDC {
if state.sig_group().hashes.len() > 0 {
let h = state.sig_group_mut().hashes
.iter_mut().find_map(
- |(a, h)|
- if *a == HashAlgorithm::SHA1 {
- Some(h)
+ |ctx|
+ if ctx.algo() == HashAlgorithm::SHA1 {
+ Some(ctx)
} else {
None
}).unwrap();