Skip to content

Commit 6c40df1

Browse files
committed
Aead::encrypt_with_nonce_from_rng
1 parent 74c6769 commit 6c40df1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

aead/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,17 @@ 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+
fn encrypt_with_nonce_from_rng<'msg, 'aad, R: CryptoRng + ?Sized>(
238+
&self,
239+
rng: &mut R,
240+
plaintext: impl Into<Payload<'msg, 'aad>>,
241+
) -> Result<Vec<u8>> {
242+
let nonce = Self::generate_nonce_with_rng(rng);
243+
self.encrypt_with_explicit_nonce(&nonce, plaintext)
244+
}
245+
235246
/// Decrypt an AEAD message which has an explicit nonce prepended to the
236247
/// AEAD message.
237248
fn decrypt_with_explicit_nonce<'msg, 'aad>(

0 commit comments

Comments
 (0)