diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-12-04 15:16:34 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-12-05 15:47:10 +0100 |
commit | 4205c4377531006a53d611828279934961ab2fa2 (patch) | |
tree | 5acaac8c0541aa624db45a66020f5fd7d5d6ea7f /openpgp/src | |
parent | 8e60f7124212438f3ec2c916aa6a6f15a48a0b91 (diff) |
openpgp: Do not return stringy errors.
- See #1068.
Diffstat (limited to 'openpgp/src')
-rw-r--r-- | openpgp/src/crypto/backend/rust/symmetric.rs | 10 | ||||
-rw-r--r-- | openpgp/src/packet/userid.rs | 4 | ||||
-rw-r--r-- | openpgp/src/policy.rs | 15 |
3 files changed, 18 insertions, 11 deletions
diff --git a/openpgp/src/crypto/backend/rust/symmetric.rs b/openpgp/src/crypto/backend/rust/symmetric.rs index f96def91..fd010824 100644 --- a/openpgp/src/crypto/backend/rust/symmetric.rs +++ b/openpgp/src/crypto/backend/rust/symmetric.rs @@ -222,8 +222,9 @@ macro_rules! impl_enc_mode { _dst: &mut [u8], _src: &[u8], ) -> Result<()> { - Err(anyhow::anyhow!( - "decryption not supported in encryption mode")) + Err(Error::InvalidOperation( + "decryption not supported in encryption mode".into()) + .into()) } } } @@ -240,8 +241,9 @@ macro_rules! impl_dec_mode { _dst: &mut [u8], _src: &[u8], ) -> Result<()> { - Err(anyhow::anyhow!( - "encryption not supported in decryption mode")) + Err(Error::InvalidOperation( + "encryption not supported in decryption mode".into()) + .into()) } fn decrypt( diff --git a/openpgp/src/packet/userid.rs b/openpgp/src/packet/userid.rs index 1ad272f0..4a1a6016 100644 --- a/openpgp/src/packet/userid.rs +++ b/openpgp/src/packet/userid.rs @@ -971,8 +971,8 @@ impl UserID { // Normalize Unicode in domains. let domain = idna::domain_to_ascii(domain) - .map_err(|e| anyhow::anyhow!( - "punycode conversion failed: {:?}", e))?; + .map_err(|e| anyhow::Error::from(e) + .context("punycode conversion failed"))?; // Join. let address = format!("{}@{}", localpart, domain); diff --git a/openpgp/src/policy.rs b/openpgp/src/policy.rs index 744f8387..9ea4fcb2 100644 --- a/openpgp/src/policy.rs +++ b/openpgp/src/policy.rs @@ -80,7 +80,8 @@ pub trait Policy : fmt::Debug + Send + Sync { /// revocations: if you reject a revocation certificate, it may /// inadvertently make something else valid! fn signature(&self, _sig: &Signature, _sec: HashAlgoSecurity) -> Result<()> { - Err(anyhow::anyhow!("By default all signatures are rejected.")) + Err(Error::PolicyViolation( + "By default all signatures are rejected.".into(), None).into()) } /// Returns an error if the key violates the policy. @@ -107,7 +108,8 @@ pub trait Policy : fmt::Debug + Send + Sync { fn key(&self, _ka: &ValidErasedKeyAmalgamation<key::PublicParts>) -> Result<()> { - Err(anyhow::anyhow!("By default all keys are rejected.")) + Err(Error::PolicyViolation( + "By default all keys are rejected.".into(), None).into()) } /// Returns an error if the symmetric encryption algorithm @@ -119,7 +121,8 @@ pub trait Policy : fmt::Debug + Send + Sync { /// With this function, you can prevent the use of insecure /// symmetric encryption algorithms. fn symmetric_algorithm(&self, _algo: SymmetricAlgorithm) -> Result<()> { - Err(anyhow::anyhow!("By default all symmetric algorithms are rejected.")) + Err(Error::PolicyViolation( + "By default all symmetric algorithms are rejected.".into(), None).into()) } /// Returns an error if the AEAD mode violates the policy. @@ -132,7 +135,8 @@ pub trait Policy : fmt::Debug + Send + Sync { /// /// This feature is [experimental](super#experimental-features). fn aead_algorithm(&self, _algo: AEADAlgorithm) -> Result<()> { - Err(anyhow::anyhow!("By default all AEAD algorithms are rejected.")) + Err(Error::PolicyViolation( + "By default all AEAD algorithms are rejected.".into(), None).into()) } /// Returns an error if the packet violates the policy. @@ -144,7 +148,8 @@ pub trait Policy : fmt::Debug + Send + Sync { /// encryption containers, notably the *Symmetrically Encrypted /// Data Packet*. fn packet(&self, _packet: &Packet) -> Result<()> { - Err(anyhow::anyhow!("By default all packets are rejected.")) + Err(Error::PolicyViolation( + "By default all packets are rejected.".into(), None).into()) } } |