Packet<...Key>'s Eq is broken
In general, we define equality as equality over the serialized forms of data structures.
In Packet
's documentation, we say, for instance:
We define equality on
Packet
as the equality of the serialized form of their packet bodies as defined by RFC 4880.
Packet::serialize only serializes secret key material for SecretKey
and SecretSubkey
packets; not for the public variants:
&Packet::PublicKey(ref p) => p.serialize_key(o, false),
&Packet::PublicSubkey(ref p) => p.serialize_key(o, false),
&Packet::SecretKey(ref p) => p.serialize_key(o, true),
&Packet::SecretSubkey(ref p) => p.serialize_key(o, true),
Unfortunately, this is not consistent with the Eq
implementation for Packet
, which is derived, and thus compares the secret key material unconditionally as per Key4::Eq
:
impl<P: KeyParts, R: KeyRole> PartialEq for Key4<P, R> {
fn eq(&self, other: &Key4<P, R>) -> bool {
self.creation_time == other.creation_time
&& self.pk_algo == other.pk_algo
&& self.mpis == other.mpis
&& self.secret == other.secret
}
}
Note: it is a bit surprising that Key4
does not respect the types, but Packet
does (well, at least Packet::serialize
)