Skip to content

Commit

Permalink
Remove remaining unnecessary ?Sized bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Feb 19, 2025
1 parent 3e1ad57 commit f98d5a7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/int/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ impl<const LIMBS: usize> Random for Int<LIMBS> {
}

impl<const LIMBS: usize> RandomBits for Int<LIMBS> {
fn try_random_bits<R: TryRngCore + ?Sized>(
fn try_random_bits<R: TryRngCore>(
rng: &mut R,
bit_length: u32,
) -> Result<Self, RandomBitsError<R::Error>> {
Self::try_random_bits_with_precision(rng, bit_length, Self::BITS)
}

fn try_random_bits_with_precision<R: TryRngCore + ?Sized>(
fn try_random_bits_with_precision<R: TryRngCore>(
rng: &mut R,
bit_length: u32,
bits_precision: u32,
Expand Down
8 changes: 4 additions & 4 deletions src/limb/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ use subtle::ConstantTimeLess;

impl Random for Limb {
#[cfg(target_pointer_width = "32")]
fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self {
fn random<R: RngCore>(rng: &mut R) -> Self {
Self(rng.next_u32())
}

#[cfg(target_pointer_width = "64")]
fn random<R: RngCore + ?Sized>(rng: &mut R) -> Self {
fn random<R: RngCore>(rng: &mut R) -> Self {
Self(rng.next_u64())
}
}

impl RandomMod for Limb {
fn random_mod<R: RngCore + ?Sized>(rng: &mut R, modulus: &NonZero<Self>) -> Self {
fn random_mod<R: RngCore>(rng: &mut R, modulus: &NonZero<Self>) -> Self {
let mut bytes = <Self as Encoding>::Repr::default();

let n_bits = modulus.bits() as usize;
Expand All @@ -36,7 +36,7 @@ impl RandomMod for Limb {
}
}

fn try_random_mod<R: TryRngCore + ?Sized>(
fn try_random_mod<R: TryRngCore>(
rng: &mut R,
modulus: &NonZero<Self>,
) -> Result<Self, R::Error> {
Expand Down
2 changes: 1 addition & 1 deletion src/non_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R: RngCore + ?Sized>(mut rng: &mut R) -> Self {
fn random<R: RngCore>(mut rng: &mut R) -> Self {
loop {
if let Some(result) = Self::new(T::random(&mut rng)).into() {
break result;
Expand Down
2 changes: 1 addition & 1 deletion src/odd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl<const LIMBS: usize> Random for Odd<Uint<LIMBS>> {
#[cfg(all(feature = "alloc", feature = "rand_core"))]
impl Odd<BoxedUint> {
/// Generate a random `Odd<Uint<T>>`.
pub fn random<R: TryRngCore + ?Sized>(rng: &mut R, bit_length: u32) -> Self {
pub fn random<R: TryRngCore>(rng: &mut R, bit_length: u32) -> Self {
let mut ret = BoxedUint::random_bits(rng, bit_length);
ret.limbs[0] |= Limb::ONE;
Odd(ret)
Expand Down
8 changes: 4 additions & 4 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R: TryRngCore + ?Sized>(rng: &mut R, bit_length: u32) -> Self {
fn random_bits<R: TryRngCore>(rng: &mut R, bit_length: u32) -> Self {
Self::try_random_bits(rng, bit_length).expect("try_random_bits() failed")
}

Expand All @@ -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<R: TryRngCore + ?Sized>(
fn try_random_bits<R: TryRngCore>(
rng: &mut R,
bit_length: u32,
) -> Result<Self, RandomBitsError<R::Error>>;
Expand All @@ -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<R: TryRngCore + ?Sized>(
fn random_bits_with_precision<R: TryRngCore>(
rng: &mut R,
bit_length: u32,
bits_precision: u32,
Expand All @@ -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<R: TryRngCore + ?Sized>(
fn try_random_bits_with_precision<R: TryRngCore>(
rng: &mut R,
bit_length: u32,
bits_precision: u32,
Expand Down
4 changes: 2 additions & 2 deletions src/uint/boxed/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use crate::{
use rand_core::{RngCore, TryRngCore};

impl RandomBits for BoxedUint {
fn try_random_bits<R: TryRngCore + ?Sized>(
fn try_random_bits<R: TryRngCore>(
rng: &mut R,
bit_length: u32,
) -> Result<Self, RandomBitsError<R::Error>> {
Self::try_random_bits_with_precision(rng, bit_length, bit_length)
}

fn try_random_bits_with_precision<R: TryRngCore + ?Sized>(
fn try_random_bits_with_precision<R: TryRngCore>(
rng: &mut R,
bit_length: u32,
bits_precision: u32,
Expand Down
12 changes: 6 additions & 6 deletions src/uint/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rand_core::{RngCore, TryRngCore};
use subtle::ConstantTimeLess;

impl<const LIMBS: usize> Random for Uint<LIMBS> {
fn random<R: RngCore + ?Sized>(mut rng: &mut R) -> Self {
fn random<R: RngCore>(mut rng: &mut R) -> Self {
let mut limbs = [Limb::ZERO; LIMBS];

for limb in &mut limbs {
Expand All @@ -20,7 +20,7 @@ impl<const LIMBS: usize> Random for Uint<LIMBS> {
/// 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<R: TryRngCore + ?Sized>(
pub(crate) fn random_bits_core<R: TryRngCore>(
rng: &mut R,
zeroed_limbs: &mut [Limb],
bit_length: u32,
Expand Down Expand Up @@ -50,14 +50,14 @@ pub(crate) fn random_bits_core<R: TryRngCore + ?Sized>(
}

impl<const LIMBS: usize> RandomBits for Uint<LIMBS> {
fn try_random_bits<R: TryRngCore + ?Sized>(
fn try_random_bits<R: TryRngCore>(
rng: &mut R,
bit_length: u32,
) -> Result<Self, RandomBitsError<R::Error>> {
Self::try_random_bits_with_precision(rng, bit_length, Self::BITS)
}

fn try_random_bits_with_precision<R: TryRngCore + ?Sized>(
fn try_random_bits_with_precision<R: TryRngCore>(
rng: &mut R,
bit_length: u32,
bits_precision: u32,
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<const LIMBS: usize> RandomMod for Uint<LIMBS> {
n
}

fn try_random_mod<R: TryRngCore + ?Sized>(
fn try_random_mod<R: TryRngCore>(
rng: &mut R,
modulus: &NonZero<Self>,
) -> Result<Self, R::Error> {
Expand All @@ -99,7 +99,7 @@ impl<const LIMBS: usize> RandomMod for Uint<LIMBS> {

/// 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<T, R: TryRngCore + ?Sized>(
pub(super) fn random_mod_core<T, R: TryRngCore>(
rng: &mut R,
n: &mut T,
modulus: &NonZero<T>,
Expand Down

0 comments on commit f98d5a7

Please sign in to comment.