diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-12-19 20:38:42 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-12-20 18:04:56 +0100 |
commit | f9a9abe78604cae8f9c3cdd398f93e829a561b9d (patch) | |
tree | 6c8fca51e9ecf2abb38e0b011e495af4b024a21a | |
parent | 3a80d2a1866b57b8c07f62ce095d951458e18430 (diff) |
openpgp: Use weaker ordering function.
- Previously, Cert::canonicalize relied on Unknown implenting Ord.
However, due to streaming, it cannot. Use a weaker ordering
function.
-rw-r--r-- | openpgp/src/cert/mod.rs | 2 | ||||
-rw-r--r-- | openpgp/src/packet/unknown.rs | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/openpgp/src/cert/mod.rs b/openpgp/src/cert/mod.rs index 19e3b6f7..8ab9aa9d 100644 --- a/openpgp/src/cert/mod.rs +++ b/openpgp/src/cert/mod.rs @@ -1701,7 +1701,7 @@ impl Cert { b.set_secret(a.set_secret(None)); } }); - self.unknowns.sort_and_dedup(Unknown::cmp, |_, _| {}); + self.unknowns.sort_and_dedup(Unknown::best_effort_cmp, |_, _| {}); // XXX: Check if the sigs in other_sigs issuer are actually // designated revokers for this key (listed in a "Revocation diff --git a/openpgp/src/packet/unknown.rs b/openpgp/src/packet/unknown.rs index ed718e1b..adb511bd 100644 --- a/openpgp/src/packet/unknown.rs +++ b/openpgp/src/packet/unknown.rs @@ -130,6 +130,17 @@ impl Unknown { pub fn set_body(&mut self, data: Vec<u8>) -> Vec<u8> { std::mem::replace(&mut self.body, data) } + + /// Best effort Ord implementation. + /// + /// The Cert canonicalization needs to order Unknown packets. + /// However, due to potential streaming, Unknown cannot implement + /// Eq. This is cheating a little, we simply ignore the streaming + /// case. + pub(crate) // For cert/mod.rs + fn best_effort_cmp(&self, other: &Unknown) -> Ordering { + self.tag.cmp(&other.tag).then_with(|| self.body().cmp(&other.body())) + } } impl From<Unknown> for Packet { |