use alloc::vec;
use alloc::vec::Vec;
use crate::crypto::SecureRandom;
pub(crate) fn random_vec(
secure_random: &dyn SecureRandom,
len: usize,
) -> Result<Vec<u8>, GetRandomFailed> {
let mut v = vec![0; len];
secure_random.fill(&mut v)?;
Ok(v)
}
pub(crate) fn random_u32(secure_random: &dyn SecureRandom) -> Result<u32, GetRandomFailed> {
let mut buf = [0u8; 4];
secure_random.fill(&mut buf)?;
Ok(u32::from_be_bytes(buf))
}
pub(crate) fn random_u16(secure_random: &dyn SecureRandom) -> Result<u16, GetRandomFailed> {
let mut buf = [0u8; 2];
secure_random.fill(&mut buf)?;
Ok(u16::from_be_bytes(buf))
}
#[derive(Debug)]
pub struct GetRandomFailed;