From 840a9dc866402efd4bc5a5cd7c9e579e0be20dad Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Sat, 26 Nov 2022 18:56:04 -0700 Subject: [PATCH] Relax Rng trait bounds to allow `?Sized` Rngs (#394) This allows the code to compile if you pass it `&mut dyn RngType`, since trait objects are unsized. See here for an example of caller code that is simplified by this change: https://github.com/mobilecoinfoundation/mobilecoin/pull/1977#discussion_r872906913 --- src/ristretto.rs | 2 +- src/scalar.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ristretto.rs b/src/ristretto.rs index fe59cac..1be1bbd 100644 --- a/src/ristretto.rs +++ b/src/ristretto.rs @@ -677,7 +677,7 @@ impl RistrettoPoint { /// discrete log of the output point with respect to any other /// point should be unknown. The map is applied twice and the /// results are added, to ensure a uniform distribution. - pub fn random(rng: &mut R) -> Self { + pub fn random(rng: &mut R) -> Self { let mut uniform_bytes = [0u8; 64]; rng.fill_bytes(&mut uniform_bytes); diff --git a/src/scalar.rs b/src/scalar.rs index 7591c2d..dba8b29 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -573,7 +573,7 @@ impl Scalar { /// let mut csprng = OsRng; /// let a: Scalar = Scalar::random(&mut csprng); /// # } - pub fn random(rng: &mut R) -> Self { + pub fn random(rng: &mut R) -> Self { let mut scalar_bytes = [0u8; 64]; rng.fill_bytes(&mut scalar_bytes); Scalar::from_bytes_mod_order_wide(&scalar_bytes)