summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-07-05 14:56:43 +0200
committerJustus Winter <justus@sequoia-pgp.org>2019-07-05 15:11:59 +0200
commit61f8c5b8460e9d6121c4e2705faa500991d50b5a (patch)
treeed10fdb5ccf83354c9713e658b37921be718fd35
parent2d9e3d760e5ad3acc04ad81b6d467059115eb162 (diff)
openpgp: Rework PartialEq for Signature4.
- Previously, we compared serialized versions of the packet. This has some problems. First, it is expensive at it requires two heap allocations. Second, it depends on Sequoia being compiled with the serialization code. Third, it allows little control over what parts of the signature are compared.
-rw-r--r--openpgp/src/packet/signature/mod.rs24
1 files changed, 7 insertions, 17 deletions
diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs
index 51667b35..27607125 100644
--- a/openpgp/src/packet/signature/mod.rs
+++ b/openpgp/src/packet/signature/mod.rs
@@ -22,7 +22,6 @@ use packet::UserAttribute;
use Packet;
use packet;
use packet::signature::subpacket::SubpacketArea;
-use serialize::SerializeInto;
use nettle::{dsa, ecc, ecdsa, ed25519, rsa};
use nettle::rsa::verify_digest_pkcs1;
@@ -339,22 +338,13 @@ impl fmt::Debug for Signature4 {
impl PartialEq for Signature4 {
fn eq(&self, other: &Signature4) -> bool {
- // Comparing the relevant fields is error prone in case we add
- // a field at some point. Instead, we compare the serialized
- // versions. As a small optimization, we compare the MPIs.
- // Note: two `Signature4s` could be different even if they have
- // the same MPI if the MPI was not invalidated when changing a
- // field.
- if self.mpis != other.mpis {
- return false;
- }
-
- // Do a full check by serializing the fields.
- if let (Ok(a), Ok(b)) = (self.to_vec(), other.to_vec()) {
- a == b
- } else {
- false
- }
+ self.fields.version == other.fields.version
+ && self.fields.sigtype == other.fields.sigtype
+ && self.fields.pk_algo == other.fields.pk_algo
+ && self.fields.hash_algo == other.fields.hash_algo
+ && self.fields.hashed_area == other.fields.hashed_area
+ && self.fields.unhashed_area == other.fields.unhashed_area
+ && self.mpis == other.mpis
}
}