Skip to content

Commit 6798400

Browse files
committed
Aead::encrypt_with_nonce_from_rng
1 parent 74c6769 commit 6798400

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

aead/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,18 @@ pub trait Aead: AeadCore {
232232
Ok(out)
233233
}
234234

235+
/// Encrypt with a random nonce generated by the specified RNG, explicitly
236+
/// prepended to the message.
237+
#[cfg(feature = "rand_core")]
238+
fn encrypt_with_nonce_from_rng<'msg, 'aad, R: CryptoRng + ?Sized>(
239+
&self,
240+
rng: &mut R,
241+
plaintext: impl Into<Payload<'msg, 'aad>>,
242+
) -> Result<Vec<u8>> {
243+
let nonce = Self::generate_nonce_with_rng(rng);
244+
self.encrypt_with_explicit_nonce(&nonce, plaintext)
245+
}
246+
235247
/// Decrypt an AEAD message which has an explicit nonce prepended to the
236248
/// AEAD message.
237249
fn decrypt_with_explicit_nonce<'msg, 'aad>(

0 commit comments

Comments
 (0)