diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-02-19 12:18:01 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-02-19 12:46:58 +0100 |
commit | ef396882bc35a97d778e985cd69ebd5181852d8c (patch) | |
tree | 6e7945e1394ff82e5a72badc933ddac710c108cc /ipc | |
parent | 32174f69cd4d94b4f621f3273781d487e97fa031 (diff) |
openpgp: Split VerificationResult.
- Split VerificationResult into Result<GoodChecksum,
VerificationError>.
- Fixes #416.
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/examples/gpg-agent-decrypt.rs | 33 | ||||
-rw-r--r-- | ipc/tests/gpg-agent.rs | 16 |
2 files changed, 26 insertions, 23 deletions
diff --git a/ipc/examples/gpg-agent-decrypt.rs b/ipc/examples/gpg-agent-decrypt.rs index 97397363..16d3a85a 100644 --- a/ipc/examples/gpg-agent-decrypt.rs +++ b/ipc/examples/gpg-agent-decrypt.rs @@ -16,7 +16,8 @@ use crate::openpgp::parse::{ DecryptionHelper, Decryptor, VerificationHelper, - VerificationResult, + GoodChecksum, + VerificationError, MessageStructure, MessageLayer, }, @@ -125,7 +126,7 @@ impl<'a> VerificationHelper for Helper<'a> { } fn check(&mut self, structure: MessageStructure) -> failure::Fallible<()> { - use self::VerificationResult::*; + use self::VerificationError::*; for layer in structure.iter() { match layer { MessageLayer::Compression { algo } => @@ -140,20 +141,30 @@ impl<'a> VerificationHelper for Helper<'a> { MessageLayer::SignatureGroup { ref results } => for result in results { match result { - GoodChecksum { cert, .. } => { - eprintln!("Good signature from {}", cert); + Ok(GoodChecksum { ka, .. }) => { + eprintln!("Good signature from {}", ka.cert()); }, - NotAlive { sig, .. } => { - eprintln!("Good, but not alive signature from {:?}", - sig.get_issuers()); + Err(MalformedSignature { error, .. }) => { + eprintln!("Signature is malformed: {}", error); }, - MissingKey { .. } => { - eprintln!("No key to check signature"); + Err(MissingKey { sig, .. }) => { + let issuers = sig.get_issuers(); + eprintln!("Missing key {}, which is needed to \ + verify signature.", + issuers.first().unwrap().to_hex()); }, - Error { error, .. } => { - eprintln!("Error verifying signature: {}", + Err(UnboundKey { cert, error, .. }) => { + eprintln!("Signing key on {} is not bound: {}", + cert.fingerprint().to_hex(), error); + }, + Err(BadKey { ka, error, .. }) => { + eprintln!("Signing key on {} is bad: {}", + ka.cert().fingerprint().to_hex(), error); }, + Err(BadSignature { error, .. }) => { + eprintln!("Verifying signature: {}.", error); + }, } } } diff --git a/ipc/tests/gpg-agent.rs b/ipc/tests/gpg-agent.rs index 2322e6d9..2b15aac7 100644 --- a/ipc/tests/gpg-agent.rs +++ b/ipc/tests/gpg-agent.rs @@ -166,18 +166,10 @@ fn sign() { // whether the signature checks out mathematically, we apply // our policy. match results.into_iter().next() { - Some(VerificationResult::GoodChecksum { .. }) => - good = true, - Some(VerificationResult::NotAlive { .. }) => - return Err(failure::err_msg( - "Good, but not live signature")), - Some(VerificationResult::MissingKey { .. }) => - return Err(failure::err_msg( - "Missing key to verify signature")), - Some(VerificationResult::Error { error, .. }) => - return Err(error), - None => - return Err(failure::err_msg("No signature")), + Some(Ok(_)) => good = true, + Some(Err(e)) => + return Err(openpgp::Error::from(e).into()), + None => (), } }, _ => return Err(failure::err_msg( |