pub use rand_chacha::*;
pub use reseeding::ReseedingRng;
use rand_core::{TryCryptoRng, TryRng};
mod reseeding;
pub struct RngAdaptor<T>(T);
impl<T> RngAdaptor<T> {
pub const fn new(rng: T) -> Self {
Self(rng)
}
pub fn into_inner(self) -> T {
self.0
}
}
impl<T> TryRng for RngAdaptor<T>
where
T: rand_core09::TryRngCore,
T::Error: core::error::Error,
{
type Error = T::Error;
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
self.0.try_next_u32()
}
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
self.0.try_next_u64()
}
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> {
self.0.try_fill_bytes(dest)
}
}
impl<T> TryCryptoRng for RngAdaptor<T>
where
T: rand_core09::TryCryptoRng,
T::Error: core::error::Error,
{
}
impl<T> rand_core09::RngCore for RngAdaptor<T>
where
T: rand_core::Rng,
{
fn next_u32(&mut self) -> u32 {
self.0.next_u32()
}
fn next_u64(&mut self) -> u64 {
self.0.next_u64()
}
fn fill_bytes(&mut self, dest: &mut [u8]) {
self.0.fill_bytes(dest)
}
}
impl<T> rand_core09::CryptoRng for RngAdaptor<T> where T: rand_core::CryptoRng {}
pub fn reseeding_csprng<T: TryRng>(
trng: T,
reseed_threshold: u64,
) -> Result<ReseedingRng<ChaCha12Rng, T>, T::Error> {
ReseedingRng::new(reseed_threshold, trng)
}