1#![allow(clippy::disallowed_methods)]
13
14use async_trait::async_trait;
15use aura_core::effects::random::RandomCoreEffects;
16use rand::RngCore;
17
18#[derive(Debug, Clone)]
20pub struct RealRandomHandler;
21
22impl Default for RealRandomHandler {
23 fn default() -> Self {
24 Self::new()
25 }
26}
27
28impl RealRandomHandler {
29 pub fn new() -> Self {
31 Self
32 }
33}
34
35#[async_trait]
36impl RandomCoreEffects for RealRandomHandler {
37 async fn random_bytes(&self, len: usize) -> Vec<u8> {
38 let mut bytes = vec![0u8; len];
39 rand::thread_rng().fill_bytes(&mut bytes);
40 bytes
41 }
42
43 async fn random_bytes_32(&self) -> [u8; 32] {
44 let mut bytes = [0u8; 32];
45 rand::thread_rng().fill_bytes(&mut bytes);
46 bytes
47 }
48
49 async fn random_u64(&self) -> u64 {
50 use rand::Rng;
51 rand::thread_rng().gen()
52 }
53}