From f9a9abe78604cae8f9c3cdd398f93e829a561b9d Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 19 Dec 2019 20:38:42 +0100 Subject: openpgp: Use weaker ordering function. - Previously, Cert::canonicalize relied on Unknown implenting Ord. However, due to streaming, it cannot. Use a weaker ordering function. --- openpgp/src/packet/unknown.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'openpgp/src/packet/unknown.rs') 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) -> Vec { 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 for Packet { -- cgit v1.2.3