Skip to main content

rsa/traits/
encryption.rs

1//! Encryption-related traits.
2
3use alloc::vec::Vec;
4use rand_core::CryptoRng;
5
6use crate::errors::Result;
7
8/// Encrypt the message using provided random source
9pub trait RandomizedEncryptor {
10    /// Encrypt the given message.
11    fn encrypt_with_rng<R: CryptoRng + ?Sized>(&self, rng: &mut R, msg: &[u8]) -> Result<Vec<u8>>;
12}
13
14/// Decrypt the given message
15pub trait Decryptor {
16    /// Decrypt the given message.
17    fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>>;
18}
19
20/// Decrypt the given message using provided random source
21pub trait RandomizedDecryptor {
22    /// Decrypt the given message.
23    fn decrypt_with_rng<R: CryptoRng + ?Sized>(
24        &self,
25        rng: &mut R,
26        ciphertext: &[u8],
27    ) -> Result<Vec<u8>>;
28}
29
30/// Encryption keypair with an associated encryption key.
31pub trait EncryptingKeypair {
32    /// Encrypting key type for this keypair.
33    type EncryptingKey: Clone;
34
35    /// Get the encrypting key which can encrypt messages to be decrypted by
36    /// the decryption key portion of this keypair.
37    fn encrypting_key(&self) -> Self::EncryptingKey;
38}