(seed: Option<[u8; SEED_SIZE]>)
| 41 | /// can concurrently access the system random generator |
| 42 | impl PRNG { |
| 43 | pub fn new(seed: Option<[u8; SEED_SIZE]>) -> Result<PRNG> { |
| 44 | let err = |_| runtime_error!("Crypter didn't initialize"); |
| 45 | let bytes = match seed { |
| 46 | Some(bytes) => bytes, |
| 47 | None => { |
| 48 | let mut bytes = [0u8; SEED_SIZE]; |
| 49 | get_bytes_from_os(&mut bytes)?; |
| 50 | bytes |
| 51 | } |
| 52 | }; |
| 53 | let mut c = |
| 54 | Crypter::new(Cipher::aes_128_ecb(), Mode::Encrypt, &bytes, None).map_err(err)?; |
| 55 | c.pad(false); |
| 56 | Ok(PRNG { |
| 57 | aes: c, |
| 58 | random_source: PrfSession::new(0, BUFFER_SIZE)?, |
| 59 | }) |
| 60 | } |
| 61 | |
| 62 | pub fn get_random_bytes(&mut self, n: usize) -> Result<Vec<u8>> { |
| 63 | self.random_source |
nothing calls this directly
no test coverage detected