summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/backend/openssl
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/openssl
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/openssl')
-rw-r--r--openpgp/src/crypto/backend/openssl/asymmetric.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/openpgp/src/crypto/backend/openssl/asymmetric.rs b/openpgp/src/crypto/backend/openssl/asymmetric.rs
index 1d586585..3ba3ca64 100644
--- a/openpgp/src/crypto/backend/openssl/asymmetric.rs
+++ b/openpgp/src/crypto/backend/openssl/asymmetric.rs
@@ -1,4 +1,4 @@
-use crate::Result;
+use crate::{Error, Result};
use crate::crypto::asymmetric::{Decryptor, KeyPair, Signer};
use crate::crypto::mpi;
@@ -289,8 +289,17 @@ impl<P: key::KeyParts, R: key::KeyRole> Key<P, R> {
))
.into()),
},
+
ECDH => crate::crypto::ecdh::encrypt(self.parts_as_public(), data),
- algo => Err(crate::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()),
}
}