Skip to content

Commit

Permalink
Implement Clone for ReseedingRng
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Apr 12, 2018
1 parent 34ebc80 commit f6d6fe4
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/reseeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ where R: BlockRngCore<Item = u32> + SeedableRng,
}
}

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

impl<R, Rsdr> CryptoRng for ReseedingRng<R, Rsdr>
where R: BlockRngCore + SeedableRng + CryptoRng,
Rsdr: RngCore + CryptoRng {}
Expand Down Expand Up @@ -189,6 +200,20 @@ where R: BlockRngCore + SeedableRng,
}
}

impl<R, Rsdr> Clone for ReseedingCore<R, Rsdr>
where R: BlockRngCore + SeedableRng + Clone,
Rsdr: RngCore + 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> CryptoRng for ReseedingCore<R, Rsdr>
where R: BlockRngCore + SeedableRng + CryptoRng,
Rsdr: RngCore + CryptoRng {}
Expand Down

0 comments on commit f6d6fe4

Please sign in to comment.