#![forbid(unsafe_code)]
use chio_kernel_core::Rng;
#[derive(Debug, Clone, Copy, Default)]
pub struct MobileRng;
impl MobileRng {
#[must_use]
pub const fn new() -> Self {
Self
}
}
impl Rng for MobileRng {
fn fill_bytes(&self, dest: &mut [u8]) {
if getrandom::getrandom(dest).is_err() {
for byte in dest.iter_mut() {
*byte = 0;
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn mobile_rng_fills_buffer_with_plausible_entropy() {
let rng = MobileRng::new();
let mut buf = [0u8; 32];
rng.fill_bytes(&mut buf);
let total: u32 = buf.iter().map(|b| u32::from(*b)).sum();
let _ = total;
}
}