Skip to content

Commit 4cc9891

Browse files
committed
Remove Clone support for ReseedingRng
1 parent e9c799c commit 4cc9891

File tree

1 file changed

+0
-46
lines changed

1 file changed

+0
-46
lines changed

src/rngs/reseeding.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use rand_core::{CryptoRng, RngCore, SeedableRng, TryCryptoRng, TryRngCore};
2121
/// `ReseedingRng` reseeds the underlying PRNG in the following cases:
2222
///
2323
/// - On a manual call to [`reseed()`].
24-
/// - After `clone()`, the clone will be reseeded on first use.
2524
/// - After the PRNG has generated a configurable number of random bytes.
2625
///
2726
/// # When should reseeding after a fixed number of generated bytes be used?
@@ -62,9 +61,6 @@ use rand_core::{CryptoRng, RngCore, SeedableRng, TryCryptoRng, TryRngCore};
6261
/// let mut reseeding_rng = ReseedingRng::<ChaCha20Core, _>::new(0, OsRng).unwrap();
6362
///
6463
/// println!("{}", reseeding_rng.random::<u64>());
65-
///
66-
/// let mut cloned_rng = reseeding_rng.clone();
67-
/// assert!(reseeding_rng.random::<u64>() != cloned_rng.random::<u64>());
6864
/// ```
6965
///
7066
/// [`BlockRngCore`]: rand_core::block::BlockRngCore
@@ -124,18 +120,6 @@ where
124120
}
125121
}
126122

127-
impl<R, Rsdr> Clone for ReseedingRng<R, Rsdr>
128-
where
129-
R: BlockRngCore + SeedableRng + Clone,
130-
Rsdr: TryRngCore + Clone,
131-
{
132-
fn clone(&self) -> ReseedingRng<R, Rsdr> {
133-
// Recreating `BlockRng` seems easier than cloning it and resetting
134-
// the index.
135-
ReseedingRng(BlockRng::new(self.0.core.clone()))
136-
}
137-
}
138-
139123
impl<R, Rsdr> CryptoRng for ReseedingRng<R, Rsdr>
140124
where
141125
R: BlockRngCore<Item = u32> + SeedableRng + CryptoBlockRng,
@@ -228,21 +212,6 @@ where
228212
}
229213
}
230214

231-
impl<R, Rsdr> Clone for ReseedingCore<R, Rsdr>
232-
where
233-
R: BlockRngCore + SeedableRng + Clone,
234-
Rsdr: TryRngCore + Clone,
235-
{
236-
fn clone(&self) -> ReseedingCore<R, Rsdr> {
237-
ReseedingCore {
238-
inner: self.inner.clone(),
239-
reseeder: self.reseeder.clone(),
240-
threshold: self.threshold,
241-
bytes_until_reseed: 0, // reseed clone on first use
242-
}
243-
}
244-
}
245-
246215
impl<R, Rsdr> CryptoBlockRng for ReseedingCore<R, Rsdr>
247216
where
248217
R: BlockRngCore<Item = u32> + SeedableRng + CryptoBlockRng,
@@ -277,19 +246,4 @@ mod test {
277246
assert_eq!(buf, seq);
278247
}
279248
}
280-
281-
#[test]
282-
#[allow(clippy::redundant_clone)]
283-
fn test_clone_reseeding() {
284-
let zero = const_rng(0);
285-
let mut rng1 = ReseedingRng::<Core, _>::new(32 * 4, zero).unwrap();
286-
287-
let first: u32 = rng1.random();
288-
for _ in 0..10 {
289-
let _ = rng1.random::<u32>();
290-
}
291-
292-
let mut rng2 = rng1.clone();
293-
assert_eq!(first, rng2.random::<u32>());
294-
}
295249
}

0 commit comments

Comments
 (0)