From f6d6fe4a122d7c1b0a4b6d73e960b7d234ddad78 Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Thu, 12 Apr 2018 16:38:36 +0200 Subject: [PATCH] Implement Clone for ReseedingRng --- src/reseeding.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/reseeding.rs b/src/reseeding.rs index 263a6dca096..e34e5acc434 100644 --- a/src/reseeding.rs +++ b/src/reseeding.rs @@ -103,6 +103,17 @@ where R: BlockRngCore + SeedableRng, } } +impl Clone for ReseedingRng +where R: BlockRngCore + SeedableRng + Clone, + Rsdr: RngCore + Clone +{ + fn clone(&self) -> ReseedingRng { + // Recreating `BlockRng` seems easier than cloning it and resetting + // the index. + ReseedingRng(BlockRng::new(self.0.inner().clone())) + } +} + impl CryptoRng for ReseedingRng where R: BlockRngCore + SeedableRng + CryptoRng, Rsdr: RngCore + CryptoRng {} @@ -189,6 +200,20 @@ where R: BlockRngCore + SeedableRng, } } +impl Clone for ReseedingCore +where R: BlockRngCore + SeedableRng + Clone, + Rsdr: RngCore + Clone +{ + fn clone(&self) -> ReseedingCore { + ReseedingCore { + inner: self.inner.clone(), + reseeder: self.reseeder.clone(), + threshold: self.threshold, + bytes_until_reseed: 0, // reseed clone on first use + } + } +} + impl CryptoRng for ReseedingCore where R: BlockRngCore + SeedableRng + CryptoRng, Rsdr: RngCore + CryptoRng {}