summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWiktor Kwapisiewicz <wiktor@metacode.biz>2022-01-10 10:01:15 +0100
committerWiktor Kwapisiewicz <wiktor@metacode.biz>2022-01-11 09:41:08 +0100
commitb72c6c6fc2fd5dd61386e929a726dfe667874853 (patch)
treea725c2751d48a9f016bab1100d370aeaca04bf2c
parentac929340927287d5899133db5fd41fbc212b55a1 (diff)
openpgp: Add convenience Decryptor implementations for Box.
- Currently Signer has default implementations for Box and Box + Send + Sync. - Add similar default implementations for Decryptor.
-rw-r--r--openpgp/src/crypto/asymmetric.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/openpgp/src/crypto/asymmetric.rs b/openpgp/src/crypto/asymmetric.rs
index 4d29eb4b..d6c8f234 100644
--- a/openpgp/src/crypto/asymmetric.rs
+++ b/openpgp/src/crypto/asymmetric.rs
@@ -137,6 +137,30 @@ pub trait Decryptor {
-> Result<SessionKey>;
}
+impl Decryptor for Box<dyn Decryptor> {
+ fn public(&self) -> &Key<key::PublicParts, key::UnspecifiedRole> {
+ self.as_ref().public()
+ }
+
+ fn decrypt(&mut self, ciphertext: &mpi::Ciphertext,
+ plaintext_len: Option<usize>)
+ -> Result<SessionKey> {
+ self.as_mut().decrypt(ciphertext, plaintext_len)
+ }
+}
+
+impl Decryptor for Box<dyn Decryptor + Send + Sync> {
+ fn public(&self) -> &Key<key::PublicParts, key::UnspecifiedRole> {
+ self.as_ref().public()
+ }
+
+ fn decrypt(&mut self, ciphertext: &mpi::Ciphertext,
+ plaintext_len: Option<usize>)
+ -> Result<SessionKey> {
+ self.as_mut().decrypt(ciphertext, plaintext_len)
+ }
+}
+
/// A cryptographic key pair.
///
/// A `KeyPair` is a combination of public and secret key. If both