diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-07-08 13:25:53 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-07-08 16:35:59 +0200 |
commit | 4841f86683bdea6fed6c2f7646b256fabb5db965 (patch) | |
tree | 8624bfef65af4e1d97558291f595b85d198ac346 | |
parent | fe68f4d84d137916a4e795591c108b343848ec75 (diff) |
openpgp: Fix std::hash::Hash for Signature4.
- If we PartialEq over a subset of fields, we cannot derive Hash,
because we must only hash the same subset of fields.
-rw-r--r-- | openpgp/src/packet/signature/mod.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs index 347b8d38..902e95e4 100644 --- a/openpgp/src/packet/signature/mod.rs +++ b/openpgp/src/packet/signature/mod.rs @@ -269,7 +269,7 @@ impl<'a> From<&'a Signature4> for &'a Builder { /// /// [Section 5.2 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.2 // Note: we can't derive PartialEq, because it includes the cached data. -#[derive(Eq, Hash, Clone)] +#[derive(Eq, Clone)] pub struct Signature4 { /// CTB packet header fields. pub(crate) common: packet::Common, @@ -358,6 +358,18 @@ impl PartialEq for Signature4 { } } +impl std::hash::Hash for Signature4 { + fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + use std::hash::Hash as StdHash; + self.fields.version.hash(state); + self.fields.sigtype.hash(state); + self.fields.pk_algo.hash(state); + self.fields.hash_algo.hash(state); + self.fields.hashed_area.hash(state); + StdHash::hash(&self.mpis, state); + } +} + impl Signature4 { /// Creates a new signature packet. /// |