From f98d5a7e9d35a9ebb4d2929bcbb387516dc5a7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Thu, 20 Feb 2025 00:54:41 +0300 Subject: [PATCH] Remove remaining unnecessary `?Sized` bounds --- src/int/rand.rs | 4 ++-- src/limb/rand.rs | 8 ++++---- src/non_zero.rs | 2 +- src/odd.rs | 2 +- src/traits.rs | 8 ++++---- src/uint/boxed/rand.rs | 4 ++-- src/uint/rand.rs | 12 ++++++------ 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/int/rand.rs b/src/int/rand.rs index ecb84e65..98b0d363 100644 --- a/src/int/rand.rs +++ b/src/int/rand.rs @@ -14,14 +14,14 @@ impl Random for Int { } impl RandomBits for Int { - fn try_random_bits( + fn try_random_bits( rng: &mut R, bit_length: u32, ) -> Result> { Self::try_random_bits_with_precision(rng, bit_length, Self::BITS) } - fn try_random_bits_with_precision( + fn try_random_bits_with_precision( rng: &mut R, bit_length: u32, bits_precision: u32, diff --git a/src/limb/rand.rs b/src/limb/rand.rs index 3ad80ae7..abe1c47f 100644 --- a/src/limb/rand.rs +++ b/src/limb/rand.rs @@ -7,18 +7,18 @@ use subtle::ConstantTimeLess; impl Random for Limb { #[cfg(target_pointer_width = "32")] - fn random(rng: &mut R) -> Self { + fn random(rng: &mut R) -> Self { Self(rng.next_u32()) } #[cfg(target_pointer_width = "64")] - fn random(rng: &mut R) -> Self { + fn random(rng: &mut R) -> Self { Self(rng.next_u64()) } } impl RandomMod for Limb { - fn random_mod(rng: &mut R, modulus: &NonZero) -> Self { + fn random_mod(rng: &mut R, modulus: &NonZero) -> Self { let mut bytes = ::Repr::default(); let n_bits = modulus.bits() as usize; @@ -36,7 +36,7 @@ impl RandomMod for Limb { } } - fn try_random_mod( + fn try_random_mod( rng: &mut R, modulus: &NonZero, ) -> Result { diff --git a/src/non_zero.rs b/src/non_zero.rs index 79bbde78..1590748f 100644 --- a/src/non_zero.rs +++ b/src/non_zero.rs @@ -246,7 +246,7 @@ where /// As a result, it runs in variable time. If the generator `rng` is /// cryptographically secure (for example, it implements `CryptoRng`), /// then this is guaranteed not to leak anything about the output value. - fn random(mut rng: &mut R) -> Self { + fn random(mut rng: &mut R) -> Self { loop { if let Some(result) = Self::new(T::random(&mut rng)).into() { break result; diff --git a/src/odd.rs b/src/odd.rs index ce95aef5..dd1b4dbe 100644 --- a/src/odd.rs +++ b/src/odd.rs @@ -163,7 +163,7 @@ impl Random for Odd> { #[cfg(all(feature = "alloc", feature = "rand_core"))] impl Odd { /// Generate a random `Odd>`. - pub fn random(rng: &mut R, bit_length: u32) -> Self { + pub fn random(rng: &mut R, bit_length: u32) -> Self { let mut ret = BoxedUint::random_bits(rng, bit_length); ret.limbs[0] |= Limb::ONE; Odd(ret) diff --git a/src/traits.rs b/src/traits.rs index 97754200..b64f7bec 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -365,7 +365,7 @@ pub trait RandomBits: Sized { /// Generate a random value in range `[0, 2^bit_length)`. /// /// A wrapper for [`RandomBits::try_random_bits`] that panics on error. - fn random_bits(rng: &mut R, bit_length: u32) -> Self { + fn random_bits(rng: &mut R, bit_length: u32) -> Self { Self::try_random_bits(rng, bit_length).expect("try_random_bits() failed") } @@ -374,7 +374,7 @@ pub trait RandomBits: Sized { /// This method is variable time wrt `bit_length`. /// /// If `rng` is a CSRNG, the generation is cryptographically secure as well. - fn try_random_bits( + fn try_random_bits( rng: &mut R, bit_length: u32, ) -> Result>; @@ -384,7 +384,7 @@ pub trait RandomBits: Sized { /// (if the implementing type supports runtime sizing). /// /// A wrapper for [`RandomBits::try_random_bits_with_precision`] that panics on error. - fn random_bits_with_precision( + fn random_bits_with_precision( rng: &mut R, bit_length: u32, bits_precision: u32, @@ -400,7 +400,7 @@ pub trait RandomBits: Sized { /// This method is variable time wrt `bit_length`. /// /// If `rng` is a CSRNG, the generation is cryptographically secure as well. - fn try_random_bits_with_precision( + fn try_random_bits_with_precision( rng: &mut R, bit_length: u32, bits_precision: u32, diff --git a/src/uint/boxed/rand.rs b/src/uint/boxed/rand.rs index ae97e742..d24d3255 100644 --- a/src/uint/boxed/rand.rs +++ b/src/uint/boxed/rand.rs @@ -8,14 +8,14 @@ use crate::{ use rand_core::{RngCore, TryRngCore}; impl RandomBits for BoxedUint { - fn try_random_bits( + fn try_random_bits( rng: &mut R, bit_length: u32, ) -> Result> { Self::try_random_bits_with_precision(rng, bit_length, bit_length) } - fn try_random_bits_with_precision( + fn try_random_bits_with_precision( rng: &mut R, bit_length: u32, bits_precision: u32, diff --git a/src/uint/rand.rs b/src/uint/rand.rs index 037157e0..742fec71 100644 --- a/src/uint/rand.rs +++ b/src/uint/rand.rs @@ -6,7 +6,7 @@ use rand_core::{RngCore, TryRngCore}; use subtle::ConstantTimeLess; impl Random for Uint { - fn random(mut rng: &mut R) -> Self { + fn random(mut rng: &mut R) -> Self { let mut limbs = [Limb::ZERO; LIMBS]; for limb in &mut limbs { @@ -20,7 +20,7 @@ impl Random for Uint { /// Fill the given limbs slice with random bits. /// /// NOTE: Assumes that the limbs in the given slice are zeroed! -pub(crate) fn random_bits_core( +pub(crate) fn random_bits_core( rng: &mut R, zeroed_limbs: &mut [Limb], bit_length: u32, @@ -50,14 +50,14 @@ pub(crate) fn random_bits_core( } impl RandomBits for Uint { - fn try_random_bits( + fn try_random_bits( rng: &mut R, bit_length: u32, ) -> Result> { Self::try_random_bits_with_precision(rng, bit_length, Self::BITS) } - fn try_random_bits_with_precision( + fn try_random_bits_with_precision( rng: &mut R, bit_length: u32, bits_precision: u32, @@ -87,7 +87,7 @@ impl RandomMod for Uint { n } - fn try_random_mod( + fn try_random_mod( rng: &mut R, modulus: &NonZero, ) -> Result { @@ -99,7 +99,7 @@ impl RandomMod for Uint { /// Generic implementation of `random_mod` which can be shared with `BoxedUint`. // TODO(tarcieri): obtain `n_bits` via a trait like `Integer` -pub(super) fn random_mod_core( +pub(super) fn random_mod_core( rng: &mut R, n: &mut T, modulus: &NonZero,