Skip to content

Commit

Permalink
Use getrandom::u32 / u64
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Nov 29, 2024
1 parent 60ede7d commit 160c891
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions rand_core/src/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,17 @@ impl TryRngCore for OsRng {

#[inline]
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
let mut buf = [0u8; 4];
getrandom::fill(&mut buf).map_err(OsError)?;
Ok(u32::from_ne_bytes(buf))
getrandom::u32().map_err(OsError)
}

#[inline]
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
let mut buf = [0u8; 8];
getrandom::fill(&mut buf).map_err(OsError)?;
Ok(u64::from_ne_bytes(buf))
getrandom::u64().map_err(OsError)
}

#[inline]
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> {
getrandom::fill(dest).map_err(OsError)?;
Ok(())
getrandom::fill(dest).map_err(OsError)
}
}

Expand Down

0 comments on commit 160c891

Please sign in to comment.