From 49c76d957f1e03165124fe0ffc6a7da4cae062e6 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Fri, 27 Mar 2020 17:16:15 +0100 Subject: sqv: Improve error reporting. --- sqv/src/sqv.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/sqv/src/sqv.rs b/sqv/src/sqv.rs index 74e2d078..886bcd43 100644 --- a/sqv/src/sqv.rs +++ b/sqv/src/sqv.rs @@ -145,9 +145,11 @@ impl<'a> VerificationHelper for VHelper<'a> { self.not_before, self.not_after) { - (None, _, _) => - eprintln!("Malformed signature: \ - no signature creation time"), + (None, _, _) => { + eprintln!("Malformed signature:"); + print_error_chain(&anyhow::anyhow!( + "no signature creation time")); + }, (Some(t), Some(not_before), not_after) => { if t < not_before { eprintln!( @@ -176,7 +178,8 @@ impl<'a> VerificationHelper for VHelper<'a> { }; } Err(MalformedSignature { error, .. }) => { - eprintln!("Signature is malformed: {}", error); + eprintln!("Signature is malformed:"); + print_error_chain(&error); } Err(MissingKey { sig, .. }) => { let issuers = sig.get_issuers(); @@ -185,16 +188,18 @@ impl<'a> VerificationHelper for VHelper<'a> { issuers.first().unwrap()); } Err(UnboundKey { cert, error, .. }) => { - eprintln!("Signing key on {:X} is not bound: {}", - cert.fingerprint(), error); + eprintln!("Signing key on {:X} is not bound:", + cert.fingerprint()); + print_error_chain(&error); } Err(BadKey { ka, error, .. }) => { - eprintln!("Signing key on {:X} is bad: {}", - ka.cert().fingerprint(), - error); + eprintln!("Signing key on {:X} is bad:", + ka.cert().fingerprint()); + print_error_chain(&error); } Err(BadSignature { error, .. }) => { - eprintln!("Verifying signature: {}.", error); + eprintln!("Verifying signature:"); + print_error_chain(&error); if verification_err.is_none() { verification_err = Some(error) } @@ -221,6 +226,11 @@ impl<'a> VerificationHelper for VHelper<'a> { } } +fn print_error_chain(err: &anyhow::Error) { + eprintln!(" {}", err); + err.chain().skip(1).for_each(|cause| eprintln!(" because: {}", cause)); +} + fn main() -> Result<()> { let p = &P::new(); -- cgit v1.2.3