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