From 523cfd7845fd8141293b5dbe63e630428e9ac90d Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 11 May 2022 13:21:58 +0200 Subject: openpgp: Add explicit forwarder for crypto::random. - This harmonizes the docstring across the different backends. Also, it avoids monomorphization of the backend functions. --- openpgp/src/crypto/backend/cng.rs | 4 ++-- openpgp/src/crypto/backend/nettle.rs | 12 ++---------- openpgp/src/crypto/backend/rust.rs | 9 ++------- 3 files changed, 6 insertions(+), 19 deletions(-) (limited to 'openpgp/src/crypto/backend') diff --git a/openpgp/src/crypto/backend/cng.rs b/openpgp/src/crypto/backend/cng.rs index 8bf01b02..f964756a 100644 --- a/openpgp/src/crypto/backend/cng.rs +++ b/openpgp/src/crypto/backend/cng.rs @@ -11,9 +11,9 @@ pub mod hash; pub mod symmetric; /// Fills the given buffer with random data. -pub fn random>(mut buf: B) { +pub fn random(buf: &mut [u8]) { RandomNumberGenerator::system_preferred() - .gen_random(buf.as_mut()) + .gen_random(buf) .expect("system-preferred RNG not to fail") } diff --git a/openpgp/src/crypto/backend/nettle.rs b/openpgp/src/crypto/backend/nettle.rs index 9bf737c0..79497a66 100644 --- a/openpgp/src/crypto/backend/nettle.rs +++ b/openpgp/src/crypto/backend/nettle.rs @@ -11,16 +11,8 @@ pub mod hash; pub mod symmetric; /// Fills the given buffer with random data. -/// -/// Fills the given buffer with random data produced by a -/// cryptographically secure pseudorandom number generator (CSPRNG). -/// The output may be used as session keys or to derive long-term -/// cryptographic keys from. However, to create session keys, -/// consider using [`SessionKey::new`]. -/// -/// [`SessionKey::new`]: crate::crypto::SessionKey::new() -pub fn random>(mut buf: B) { - Yarrow::default().random(buf.as_mut()); +pub fn random(buf: &mut [u8]) { + Yarrow::default().random(buf); } impl PublicKeyAlgorithm { diff --git a/openpgp/src/crypto/backend/rust.rs b/openpgp/src/crypto/backend/rust.rs index 1bc6bf05..06b1da03 100644 --- a/openpgp/src/crypto/backend/rust.rs +++ b/openpgp/src/crypto/backend/rust.rs @@ -10,16 +10,11 @@ pub mod hash; pub mod symmetric; /// Fills the given buffer with random data. -/// -/// Fills the given buffer with random data produced by a -/// cryptographically secure pseudorandom number generator (CSPRNG). -/// The output may be used as session keys or to derive long-term -/// cryptographic keys from. -pub fn random>(mut buf: B) { +pub fn random(buf: &mut [u8]) { use rand07::rngs::OsRng; use rand07::RngCore; - OsRng.fill_bytes(buf.as_mut()) + OsRng.fill_bytes(buf) } impl PublicKeyAlgorithm { -- cgit v1.2.3