diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-04-25 23:09:53 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-04-26 14:58:53 +0200 |
commit | 65e1e3690840cb180a4aac710bff51dd3e826b16 (patch) | |
tree | 8f4fe4c37432eb411ca07a2a4329f00682a86d2f /openpgp | |
parent | 685194a2a88654bde5af079a5bb6577ec707fb5c (diff) |
openpgp: Add randomized roundtrip tests for Key.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/packet/key.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index a6079f40..a95facad 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -1900,8 +1900,31 @@ mod tests { } } + quickcheck! { + fn roundtrip_public(p: Key<PublicParts, UnspecifiedRole>) -> bool { + use crate::parse::Parse; + use crate::serialize::MarshalInto; + let buf = p.to_vec().expect("Failed to serialize key"); + let q = Key::from_bytes(&buf).expect("Failed to parse key").into(); + assert_eq!(p, q); + true + } + } + + quickcheck! { + fn roundtrip_secret(p: Key<SecretParts, UnspecifiedRole>) -> bool { + use crate::parse::Parse; + use crate::serialize::MarshalInto; + let buf = p.to_vec().expect("Failed to serialize key"); + let q = Key::from_bytes(&buf).expect("Failed to parse key") + .parts_into_secret().expect("No secret material"); + assert_eq!(p, q); + true + } + } + #[test] - fn roundtrip() { + fn generate_roundtrip() { use crate::types::Curve::*; let keys = vec![NistP256, NistP384, NistP521].into_iter().flat_map(|cv| |