diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-03-21 17:57:34 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-03-21 17:57:34 +0100 |
commit | c7b40bcd1a66419e737718c6ccebb09826b26cc4 (patch) | |
tree | 01666c475c67be8174daba7b0e3e423a210ae58b | |
parent | 289f87d10454005140ba2125402301b305060e94 (diff) |
openpgp: Delay non-trivial context computations.
- Fixes #892.
-rw-r--r-- | openpgp/src/cert/amalgamation/key.rs | 2 | ||||
-rw-r--r-- | openpgp/src/packet/userid.rs | 5 | ||||
-rw-r--r-- | openpgp/src/policy.rs | 8 |
3 files changed, 7 insertions, 8 deletions
diff --git a/openpgp/src/cert/amalgamation/key.rs b/openpgp/src/cert/amalgamation/key.rs index 42e89c72..fb6ce57b 100644 --- a/openpgp/src/cert/amalgamation/key.rs +++ b/openpgp/src/cert/amalgamation/key.rs @@ -1350,7 +1350,7 @@ impl<'a, P, R, R2> ValidKeyAmalgamation<'a, P, R, R2> }; if let Some(sig) = sig { sig.key_alive(self.key(), self.time()) - .context(if self.primary() { + .with_context(|| if self.primary() { "The primary key is not live" } else { "The subkey is not live" diff --git a/openpgp/src/packet/userid.rs b/openpgp/src/packet/userid.rs index b113a955..7b99dfeb 100644 --- a/openpgp/src/packet/userid.rs +++ b/openpgp/src/packet/userid.rs @@ -8,7 +8,6 @@ use std::sync::Mutex; #[cfg(test)] use quickcheck::{Arbitrary, Gen}; -use anyhow::Context; use regex::Regex; use crate::Result; @@ -854,8 +853,8 @@ impl UserID { Ok(puid) => puid, Err(err) => { // Return the error from the NameAddrOrOther parser. - return Err(err).context(format!( - "Failed to parse User ID: {:?}", s))?; + return Err(err.context(format!( + "Failed to parse User ID: {:?}", s))); } }); } diff --git a/openpgp/src/policy.rs b/openpgp/src/policy.rs index 92b08a47..a75ed74d 100644 --- a/openpgp/src/policy.rs +++ b/openpgp/src/policy.rs @@ -1455,14 +1455,14 @@ impl<'a> Policy for StandardPolicy<'a> { .collision_resistant_hash_algos .check(sig.hash_algo(), time, Some(self.hash_revocation_tolerance)) - .context(format!( + .with_context(|| format!( "Policy rejected revocation signature ({}) requiring \ collision resistance", sig.typ()))? } else { self .collision_resistant_hash_algos .check(sig.hash_algo(), time, None) - .context(format!( + .with_context(|| format!( "Policy rejected non-revocation signature ({}) requiring \ collision resistance", sig.typ()))? } @@ -1473,14 +1473,14 @@ impl<'a> Policy for StandardPolicy<'a> { .second_pre_image_resistant_hash_algos .check(sig.hash_algo(), time, Some(self.hash_revocation_tolerance)) - .context(format!( + .with_context(|| format!( "Policy rejected revocation signature ({}) requiring \ second pre-image resistance", sig.typ()))? } else { self .second_pre_image_resistant_hash_algos .check(sig.hash_algo(), time, None) - .context(format!( + .with_context(|| format!( "Policy rejected non-revocation signature ({}) requiring \ second pre-image resistance", sig.typ()))? } |