summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-04-01 14:19:50 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-04-01 16:15:00 +0200
commita0a9f564cf9fad4edd88258a51a6bc0cb1529151 (patch)
tree467a36b4be025ac82133511d09171b0ba55e52b0
parent1403b50a82e24fd696f367b82ef18ce9f8c6f4c3 (diff)
openpgp: New rountrip test for equality on Packet.
-rw-r--r--openpgp/src/packet/mod.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs
index db63da71..b5c3dd2c 100644
--- a/openpgp/src/packet/mod.rs
+++ b/openpgp/src/packet/mod.rs
@@ -1090,4 +1090,31 @@ mod test {
true
}
}
+
+ quickcheck! {
+ /// Given a packet and a position, induces a bit flip in the
+ /// serialized form, then checks that PartialEq detects that.
+ /// Recall that for packets, PartialEq is defined using the
+ /// serialized form.
+ fn mutate_eq_discriminates(p: Packet, i: usize) -> bool {
+ if p.tag() == Tag::CompressedData {
+ // Mutating compressed data streams is not that
+ // trivial, because there are bits we can flip without
+ // changing the decompressed data.
+ return true;
+ }
+
+ let mut buf = p.to_vec().unwrap();
+ let bit =
+ // Avoid first two bytes so that we don't change the
+ // type and reduce the chance of changing the length.
+ i.saturating_add(16)
+ % (buf.len() * 8);
+ buf[bit / 8] ^= 1 << (bit % 8);
+ match Packet::from_bytes(&buf) {
+ Ok(q) => p != q,
+ Err(_) => true, // Packet failed to parse.
+ }
+ }
+ }
}