diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-07-17 17:44:17 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-07-17 17:44:17 +0200 |
commit | d44c0c28e50b6f93888ddfb42d486bde6beb4a90 (patch) | |
tree | 718aef34132646791d17faa4e4ff2cebda097d90 | |
parent | f2591a517c1cc81409048512aeb1b6b351006f50 (diff) |
openpgp: Add signature roundtrip test.
-rw-r--r-- | openpgp/src/packet/key.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index 7ace0843..285f5188 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -2107,6 +2107,31 @@ mod tests { } #[test] + fn signature_roundtrip() { + use crate::types::{Curve::*, SignatureType}; + + let keys = vec![NistP256, NistP384, NistP521].into_iter() + .filter_map(|cv| { + Key4::generate_ecc(true, cv).ok() + }).chain(vec![1024, 2048, 3072, 4096].into_iter().filter_map(|b| { + Key4::generate_rsa(b).ok() + })); + + for key in keys.into_iter() { + let key: Key<key::SecretParts, key::UnspecifiedRole> = key.into(); + let mut keypair = key.clone().into_keypair().unwrap(); + let hash = HashAlgorithm::default(); + + // Sign. + let mut sig = SignatureBuilder::new(SignatureType::Binary) + .sign_hash(&mut keypair, hash.context().unwrap()).unwrap(); + + // Verify. + sig.verify_hash(&key, hash.context().unwrap()).unwrap(); + } + } + + #[test] fn secret_encryption_roundtrip() { use crate::types::Curve::*; |