use crate::error::Unspecified;
use native_ossl::rand::Rand;
#[derive(Debug, Clone)]
pub struct SystemRandom;
impl SystemRandom {
#[must_use]
pub fn new() -> Self {
Self
}
}
impl Default for SystemRandom {
fn default() -> Self {
Self::new()
}
}
pub trait SecureRandom: sealed::SecureRandom {
fn fill(&self, dest: &mut [u8]) -> Result<(), Unspecified>;
}
mod sealed {
pub trait SecureRandom {}
}
impl sealed::SecureRandom for SystemRandom {}
impl SecureRandom for SystemRandom {
fn fill(&self, dest: &mut [u8]) -> Result<(), Unspecified> {
Rand::fill(dest).map_err(|_| Unspecified)
}
}