Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
- Fix `OsError::raw_os_error` on UEFI targets by returning `Option<usize>` (#1665)
- Replace fn `TryRngCore::read_adapter(..) -> RngReadAdapter` with simpler struct `RngReader` (#1669)
- Remove fns `SeedableRng::from_os_rng`, `try_from_os_rng` (#1674)
- Remove `Clone` support for `StdRng`, `ReseedingRng` (#1677)

### Additions
- Add fns `IndexedRandom::choose_iter`, `choose_weighted_iter` (#1632)
Expand Down
46 changes: 0 additions & 46 deletions src/rngs/reseeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use rand_core::{CryptoRng, RngCore, SeedableRng, TryCryptoRng, TryRngCore};
/// `ReseedingRng` reseeds the underlying PRNG in the following cases:
///
/// - On a manual call to [`reseed()`].
/// - After `clone()`, the clone will be reseeded on first use.
/// - After the PRNG has generated a configurable number of random bytes.
///
/// # When should reseeding after a fixed number of generated bytes be used?
Expand Down Expand Up @@ -62,9 +61,6 @@ use rand_core::{CryptoRng, RngCore, SeedableRng, TryCryptoRng, TryRngCore};
/// let mut reseeding_rng = ReseedingRng::<ChaCha20Core, _>::new(0, OsRng).unwrap();
///
/// println!("{}", reseeding_rng.random::<u64>());
///
/// let mut cloned_rng = reseeding_rng.clone();
/// assert!(reseeding_rng.random::<u64>() != cloned_rng.random::<u64>());
/// ```
///
/// [`BlockRngCore`]: rand_core::block::BlockRngCore
Expand Down Expand Up @@ -124,18 +120,6 @@ where
}
}

impl<R, Rsdr> Clone for ReseedingRng<R, Rsdr>
where
R: BlockRngCore + SeedableRng + Clone,
Rsdr: TryRngCore + Clone,
{
fn clone(&self) -> ReseedingRng<R, Rsdr> {
// Recreating `BlockRng` seems easier than cloning it and resetting
// the index.
ReseedingRng(BlockRng::new(self.0.core.clone()))
}
}

impl<R, Rsdr> CryptoRng for ReseedingRng<R, Rsdr>
where
R: BlockRngCore<Item = u32> + SeedableRng + CryptoBlockRng,
Expand Down Expand Up @@ -228,21 +212,6 @@ where
}
}

impl<R, Rsdr> Clone for ReseedingCore<R, Rsdr>
where
R: BlockRngCore + SeedableRng + Clone,
Rsdr: TryRngCore + Clone,
{
fn clone(&self) -> ReseedingCore<R, Rsdr> {
ReseedingCore {
inner: self.inner.clone(),
reseeder: self.reseeder.clone(),
threshold: self.threshold,
bytes_until_reseed: 0, // reseed clone on first use
}
}
}

impl<R, Rsdr> CryptoBlockRng for ReseedingCore<R, Rsdr>
where
R: BlockRngCore<Item = u32> + SeedableRng + CryptoBlockRng,
Expand Down Expand Up @@ -277,19 +246,4 @@ mod test {
assert_eq!(buf, seq);
}
}

#[test]
#[allow(clippy::redundant_clone)]
fn test_clone_reseeding() {
let zero = const_rng(0);
let mut rng1 = ReseedingRng::<Core, _>::new(32 * 4, zero).unwrap();

let first: u32 = rng1.random();
for _ in 0..10 {
let _ = rng1.random::<u32>();
}

let mut rng2 = rng1.clone();
assert_eq!(first, rng2.random::<u32>());
}
}
2 changes: 1 addition & 1 deletion src/rngs/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use chacha20::ChaCha12Rng as Rng;
/// [CSPRNG]: https://rust-random.github.io/book/guide-gen.html#cryptographically-secure-pseudo-random-number-generator
/// [rand_chacha]: https://crates.io/crates/rand_chacha
/// [rand issue]: https://github.com/rust-random/rand/issues/932
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq)]
pub struct StdRng(Rng);

impl RngCore for StdRng {
Expand Down