#[derive(Clone, Copy, Default)]
pub(crate) struct OsRng10;
impl rand_core_10::TryRng for OsRng10 {
type Error = core::convert::Infallible;
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
let mut b = [0u8; 4];
self.try_fill_bytes(&mut b)?;
Ok(u32::from_le_bytes(b))
}
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
let mut b = [0u8; 8];
self.try_fill_bytes(&mut b)?;
Ok(u64::from_le_bytes(b))
}
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error> {
use rand::RngCore;
rand::rngs::OsRng.fill_bytes(dst);
Ok(())
}
}
impl rand_core_10::TryCryptoRng for OsRng10 {}
#[cfg(test)]
mod tests {
use super::OsRng10;
#[test]
fn os_rng10_drives_ff_014_field_random() {
use pasta_curves::group::ff::Field;
use pasta_curves::pallas::Scalar;
let a = <Scalar as Field>::random(&mut OsRng10);
let b = <Scalar as Field>::random(&mut OsRng10);
assert_ne!(a, b, "two draws must not collide");
assert!(bool::from(!<Scalar as Field>::is_zero(&a)));
}
}