diff --git a/src/lib.rs b/src/lib.rs index c11771a0..faee196c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -222,6 +222,7 @@ pub mod algorithms; pub mod errors; pub mod pkcs1v15; pub mod pss; +pub mod traits; mod dummy_rng; mod encoding; diff --git a/src/traits.rs b/src/traits.rs new file mode 100644 index 00000000..30b67902 --- /dev/null +++ b/src/traits.rs @@ -0,0 +1,42 @@ +//! Generic traits for message encryption and decryption + +use alloc::vec::Vec; +use rand_core::CryptoRngCore; + +use crate::errors::Result; + +/// Encrypt the message using provided random source +pub trait RandomizedEncryptor { + /// Encrypt the given message. + fn encrypt_with_rng( + &self, + rng: &mut R, + msg: &[u8], + ) -> Result>; +} + +/// Decrypt the given message +pub trait Decryptor { + /// Decrypt the given message. + fn decrypt(&self, ciphertext: &[u8]) -> Result>; +} + +/// Decrypt the given message using provided random source +pub trait RandomizedDecryptor { + /// Decrypt the given message. + fn decrypt_with_rng( + &self, + rng: &mut R, + ciphertext: &[u8], + ) -> Result>; +} + +/// Encryption keypair with an associated encryption key. +pub trait EncryptingKeypair { + /// Encrypting key type for this keypair. + type EncryptingKey: Clone; + + /// Get the encrypting key which can encrypt messages to be decrypted by + /// the decryption key portion of this keypair. + fn encrypting_key(&self) -> Self::EncryptingKey; +}