summaryrefslogtreecommitdiffstats
path: root/openpgp/src/packet
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-09-25 15:21:05 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-09-25 15:21:05 +0200
commit66e290c2e9550c6cd02efe895fb5e0b0220444d9 (patch)
treee8c1df362886c170f12e9776e64677eaee586afb /openpgp/src/packet
parent7b90b8b0dbefb8c98c3eeec709a3899ed41b1089 (diff)
openpgp: Either derive both Eq and Hash, or impl both.
- crypto::mpi::SecretKeyMaterial is the sole exception to this rule, because we are trying to compare them in constant time. Add a hint for clippy that this is okay. - KeyHandle no longer implements Eq, so there is no point in implementing Hash. Simply remove it. - Implement Hash for SubpacketLength by hashing the serialized form. Manually implement Eq for consistency. - Fixes #567.
Diffstat (limited to 'openpgp/src/packet')
-rw-r--r--openpgp/src/packet/signature/subpacket.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index cbcb2df2..62494df9 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -1674,7 +1674,7 @@ impl Subpacket {
}
}
-#[derive(Clone, Debug, Hash, Eq)]
+#[derive(Clone, Debug)]
pub(crate) struct SubpacketLength {
/// The length.
pub(crate) len: u32,
@@ -1715,6 +1715,22 @@ impl PartialEq for SubpacketLength {
}
}
+impl Eq for SubpacketLength {}
+
+impl Hash for SubpacketLength {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ match &self.raw {
+ Some(raw) => raw.hash(state),
+ None => {
+ let l = self.serialized_len();
+ let mut raw = [0; 5];
+ self.serialize_into(&mut raw[..l]).unwrap();
+ raw[..l].hash(state);
+ },
+ }
+ }
+}
+
impl SubpacketLength {
pub(crate) fn new(len: u32, raw: Option<Vec<u8>>) -> Self {
Self { len, raw }