summaryrefslogtreecommitdiffstats
path: root/openpgp/src/packet/one_pass_sig.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-12-05 13:50:35 +0100
committerJustus Winter <justus@sequoia-pgp.org>2018-12-14 14:05:21 +0100
commita5e26965f5f0fc8fbecb401f552826ce367ca7ec (patch)
tree92fcbf60de100d4da1c117aaa98fc36b40ee31d1 /openpgp/src/packet/one_pass_sig.rs
parentd411fb80983a4d4ebb9f023599c38e34a26551e7 (diff)
openpgp: Add roundtrip tests for packages.
Diffstat (limited to 'openpgp/src/packet/one_pass_sig.rs')
-rw-r--r--openpgp/src/packet/one_pass_sig.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/openpgp/src/packet/one_pass_sig.rs b/openpgp/src/packet/one_pass_sig.rs
index d1f28610..ae174652 100644
--- a/openpgp/src/packet/one_pass_sig.rs
+++ b/openpgp/src/packet/one_pass_sig.rs
@@ -1,4 +1,5 @@
use std::fmt;
+use quickcheck::{Arbitrary, Gen};
use Error;
use packet;
@@ -172,3 +173,29 @@ impl<'a> From<&'a Signature> for Result<OnePassSig> {
})
}
}
+
+impl Arbitrary for OnePassSig {
+ fn arbitrary<G: Gen>(g: &mut G) -> Self {
+ let mut ops = OnePassSig::new(SignatureType::arbitrary(g));
+ ops.set_hash_algo(HashAlgorithm::arbitrary(g));
+ ops.set_pk_algo(PublicKeyAlgorithm::arbitrary(g));
+ ops.set_issuer(KeyID::arbitrary(g));
+ ops.set_last_raw(u8::arbitrary(g));
+ ops
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use parse::Parse;
+ use serialize::Serialize;
+
+ quickcheck! {
+ fn roundtrip(p: OnePassSig) -> bool {
+ let q = OnePassSig::from_bytes(&p.to_vec().unwrap()).unwrap();
+ assert_eq!(p, q);
+ true
+ }
+ }
+}