diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-05-24 14:10:20 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-06-20 12:09:05 +0200 |
commit | 8e2dcd5287b24d246ae2083821fb83f39b34e1bc (patch) | |
tree | b61f800dc97ad78cc3ab5c51261107a158ed32d9 | |
parent | f4b7910a960f36b9525c871c894295e29c3fc9b6 (diff) |
openpgp: Validate algorithm in the common code.
-rw-r--r-- | openpgp/src/packet/key.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index b6de1f97..7ace0843 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -742,7 +742,20 @@ impl<P, R> Key<P, R> { /// Encrypts the given data with this key. pub fn encrypt(&self, data: &SessionKey) -> Result<mpi::Ciphertext> { - self.encrypt_backend(data) + use PublicKeyAlgorithm::*; + + #[allow(deprecated, non_snake_case)] + match self.pk_algo() { + RSASign | DSA | ECDSA | EdDSA => + Err(Error::InvalidOperation( + format!("{} is not an encryption algorithm", self.pk_algo()) + ).into()), + + RSAEncryptSign | RSAEncrypt | + ElGamalEncrypt | ElGamalEncryptSign | + ECDH | + Private(_) | Unknown(_) => self.encrypt_backend(data), + } } /// Verifies the given signature. |