Skip to content

Commit d91e110

Browse files
committed
Implement Clone for ReseedingRng
1 parent 34ebc80 commit d91e110

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/reseeding.rs

+25
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ where R: BlockRngCore<Item = u32> + SeedableRng,
103103
}
104104
}
105105

106+
impl<R, Rsdr> Clone for ReseedingRng<R, Rsdr>
107+
where R: BlockRngCore + SeedableRng + Clone,
108+
Rsdr: RngCore + Clone
109+
{
110+
fn clone(&self) -> ReseedingRng<R, Rsdr> {
111+
// Recreating `BlockRng` seems easier than cloning it and resetting
112+
// the index.
113+
ReseedingRng(BlockRng::new(self.0.inner().clone()))
114+
}
115+
}
116+
106117
impl<R, Rsdr> CryptoRng for ReseedingRng<R, Rsdr>
107118
where R: BlockRngCore + SeedableRng + CryptoRng,
108119
Rsdr: RngCore + CryptoRng {}
@@ -189,6 +200,20 @@ where R: BlockRngCore + SeedableRng,
189200
}
190201
}
191202

203+
impl<R, Rsdr> Clone for ReseedingCore<R, Rsdr>
204+
where R: BlockRngCore + SeedableRng + Clone,
205+
Rsdr: RngCore + Clone
206+
{
207+
fn clone(&self) -> ReseedingCore<R, Rsdr> {
208+
ReseedingCore {
209+
inner: self.inner.clone(),
210+
reseeder: self.reseeder.clone(),
211+
threshold: self.threshold,
212+
bytes_until_reseed: 0, // reseed clone on first use
213+
}
214+
}
215+
}
216+
192217
impl<R, Rsdr> CryptoRng for ReseedingCore<R, Rsdr>
193218
where R: BlockRngCore + SeedableRng + CryptoRng,
194219
Rsdr: RngCore + CryptoRng {}

0 commit comments

Comments
 (0)