Skip to main content

rsa/traits/
encryption.rs

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