1use crate::crypto::SecureRandom;
4
5pub(crate) fn random_array<const N: usize>(
7 secure_random: &dyn SecureRandom,
8) -> Result<[u8; N], GetRandomFailed> {
9 let mut v = [0; N];
10 secure_random.fill(&mut v)?;
11 Ok(v)
12}
13
14pub(crate) fn random_u32(secure_random: &dyn SecureRandom) -> Result<u32, GetRandomFailed> {
16 Ok(u32::from_be_bytes(random_array(secure_random)?))
17}
18
19pub(crate) fn random_u16(secure_random: &dyn SecureRandom) -> Result<u16, GetRandomFailed> {
21 Ok(u16::from_be_bytes(random_array(secure_random)?))
22}
23
24#[allow(clippy::exhaustive_structs)]
26#[derive(Debug)]
27pub struct GetRandomFailed;