summaryrefslogtreecommitdiffstats
path: root/openpgp/src/packet/pkesk.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-03-27 13:59:06 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-03-27 14:08:22 +0100
commita3f64c655c9e212f79fbbb425fac58f1ee6ce5a9 (patch)
tree8d8e0d72390cd2beee010cb799e8297d246d85fb /openpgp/src/packet/pkesk.rs
parent20a8c5a9b191112af4d9db974d51922c57217882 (diff)
openpgp: Define equality using the serialized OpenPGP form.
- All packets should be considered equal if the serialized OpenPGP form is equal, modulo framing (i.e. CTB type, packet length encoding, partial body chunking). - In cases this may lead to surprising outcomes, discuss this in the documentation, and provide additional equality predicates. - Fixes #92.
Diffstat (limited to 'openpgp/src/packet/pkesk.rs')
-rw-r--r--openpgp/src/packet/pkesk.rs22
1 files changed, 3 insertions, 19 deletions
diff --git a/openpgp/src/packet/pkesk.rs b/openpgp/src/packet/pkesk.rs
index e048cff8..996b5a7a 100644
--- a/openpgp/src/packet/pkesk.rs
+++ b/openpgp/src/packet/pkesk.rs
@@ -26,7 +26,9 @@ use crate::packet;
/// [Section 5.1 of RFC 4880] for details.
///
/// [Section 5.1 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.1
-#[derive(Clone, Debug)]
+// IMPORTANT: If you add fields to this struct, you need to explicitly
+// IMPORTANT: implement PartialEq, Eq, and Hash.
+#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct PKESK3 {
/// CTB header fields.
pub(crate) common: packet::Common,
@@ -38,24 +40,6 @@ pub struct PKESK3 {
esk: Ciphertext,
}
-impl PartialEq for PKESK3 {
- fn eq(&self, other: &PKESK3) -> bool {
- self.recipient == other.recipient
- && self.pk_algo == other.pk_algo
- && self.esk == other.esk
- }
-}
-
-impl Eq for PKESK3 {}
-
-impl std::hash::Hash for PKESK3 {
- fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
- std::hash::Hash::hash(&self.recipient, state);
- std::hash::Hash::hash(&self.pk_algo, state);
- std::hash::Hash::hash(&self.esk, state);
- }
-}
-
impl PKESK3 {
/// Creates a new PKESK3 packet.
pub fn new(recipient: KeyID, pk_algo: PublicKeyAlgorithm,