Documentation
use std::fs::File;
use std::io::{BufReader, Read};

use crate::RandomSource;

pub struct DevRandom {
    file: BufReader<File>,
}

impl DevRandom {
    pub fn new() -> std::io::Result<Self> {
        let file = BufReader::new(File::open("/dev/random")?);
        Ok(Self { file })
    }
}

impl RandomSource for DevRandom {
    fn fill_bytes(&mut self, bytes: &mut [u8]) {
        self.file.read_exact(bytes).unwrap();
    }
}