summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-03-31 17:17:11 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-04-01 16:15:00 +0200
commit6ffef8ff27bbf75e1a5f237cf0ae99556fbbdc9f (patch)
tree780bc281b5191b375deb2ba7dabbca976793654b
parent45b43bb2f5e8dd984e0b8a952dd9f6f6835d5317 (diff)
openpgp: Implement Arbitrary for Packet.
-rw-r--r--openpgp/src/packet/mod.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/openpgp/src/packet/mod.rs b/openpgp/src/packet/mod.rs
index af911578..17222bce 100644
--- a/openpgp/src/packet/mod.rs
+++ b/openpgp/src/packet/mod.rs
@@ -230,6 +230,23 @@ impl<'a> DerefMut for Packet {
}
}
}
+
+impl Arbitrary for Packet {
+ fn arbitrary<G: Gen>(g: &mut G) -> Self {
+ use rand::Rng;
+ match g.gen_range(0, 8) {
+ 0 => OnePassSig::arbitrary(g).into(),
+ 1 => Marker::arbitrary(g).into(),
+ 2 => Trust::arbitrary(g).into(),
+ 3 => UserID::arbitrary(g).into(),
+ 4 => UserAttribute::arbitrary(g).into(),
+ 5 => Literal::arbitrary(g).into(),
+ 6 => PKESK::arbitrary(g).into(),
+ 7 => SKESK::arbitrary(g).into(),
+ _ => unreachable!(),
+ }
+ }
+}
/// Fields used by multiple packet types.
#[derive(Debug, Clone)]