summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/backend/nettle
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2023-04-26 15:20:22 +0200
committerJustus Winter <justus@sequoia-pgp.org>2023-04-26 15:55:53 +0200
commit0b4688e4a06b3077a6b93d0722f2fbfc1e989420 (patch)
treec1a44387f699a49c4a2fff7afd4856344f095d4b /openpgp/src/crypto/backend/nettle
parent83700d038e474ac9170938e0eb6c5ad2862b1c52 (diff)
openpgp: Harmonize Key::encrypt, make pk_algo match exhaustive.
- This changes and harmonizes the behavior of Key::encrypt, notably it also returns more specific errors when a signature algorithm is used for encryption. - It also makes the matches over the public key algorithms exhaustive, so that when we add more algorithms in the future, we will see where we need to implement them.
Diffstat (limited to 'openpgp/src/crypto/backend/nettle')
-rw-r--r--openpgp/src/crypto/backend/nettle/asymmetric.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/openpgp/src/crypto/backend/nettle/asymmetric.rs b/openpgp/src/crypto/backend/nettle/asymmetric.rs
index 54fa31d2..c96ccaf0 100644
--- a/openpgp/src/crypto/backend/nettle/asymmetric.rs
+++ b/openpgp/src/crypto/backend/nettle/asymmetric.rs
@@ -222,9 +222,18 @@ impl<P: key::KeyParts, R: key::KeyRole> Key<P, R> {
},
}
},
+
ECDH => crate::crypto::ecdh::encrypt(self.parts_as_public(),
data),
- algo => Err(Error::UnsupportedPublicKeyAlgorithm(algo).into()),
+
+ RSASign | DSA | ECDSA | EdDSA =>
+ Err(Error::InvalidOperation(
+ format!("{} is not an encryption algorithm", self.pk_algo())
+ ).into()),
+
+ ElGamalEncrypt | ElGamalEncryptSign |
+ Private(_) | Unknown(_) =>
+ Err(Error::UnsupportedPublicKeyAlgorithm(self.pk_algo()).into()),
}
}