use ring::rand::{SecureRandom, SystemRandom};
pub(crate) fn fill_random(bytes: &mut [u8]) -> Result<(), GetRandomFailed> {
SystemRandom::new()
.fill(bytes)
.map_err(|_| GetRandomFailed)
}
pub(crate) fn random_vec(len: usize) -> Result<Vec<u8>, GetRandomFailed> {
let mut v = vec![0; len];
fill_random(&mut v)?;
Ok(v)
}
pub(crate) fn random_u32() -> Result<u32, GetRandomFailed> {
let mut buf = [0u8; 4];
fill_random(&mut buf)?;
Ok(u32::from_be_bytes(buf))
}
#[derive(Debug)]
pub struct GetRandomFailed;