rsa/pkcs1v15/
encrypting_key.rs

1use super::encrypt;
2use crate::{traits::RandomizedEncryptor, Result, RsaPublicKey};
3use alloc::vec::Vec;
4use rand_core::CryptoRngCore;
5
6/// Encryption key for PKCS#1 v1.5 encryption as described in [RFC8017 § 7.2].
7///
8/// [RFC8017 § 7.2]: https://datatracker.ietf.org/doc/html/rfc8017#section-7.2
9#[derive(Debug, Clone)]
10pub struct EncryptingKey {
11    pub(super) inner: RsaPublicKey,
12}
13
14impl EncryptingKey {
15    /// Create a new verifying key from an RSA public key.
16    pub fn new(key: RsaPublicKey) -> Self {
17        Self { inner: key }
18    }
19}
20
21impl RandomizedEncryptor for EncryptingKey {
22    fn encrypt_with_rng<R: CryptoRngCore + ?Sized>(
23        &self,
24        rng: &mut R,
25        msg: &[u8],
26    ) -> Result<Vec<u8>> {
27        encrypt(rng, &self.inner, msg)
28    }
29}