Skip to content

Commit

Permalink
Use EntropySource in NewSeeded
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jan 24, 2018
1 parent a996cf7 commit 2278d44
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,27 +834,8 @@ pub trait NewRng: SeedableRng {
#[cfg(feature="std")]
impl<R: SeedableRng> NewRng for R {
fn new() -> Result<Self, Error> {
// Note: error handling would be easier with try/catch blocks
fn new_os<T: SeedableRng>() -> Result<T, Error> {
let mut r = OsRng::new()?;
T::from_rng(&mut r)
}

fn new_jitter<T: SeedableRng>() -> Result<T, Error> {
let mut r = JitterRng::new()?;
T::from_rng(&mut r)
}

new_os().or_else(|e1| {
new_jitter().map_err(|_e2| {
// TODO: log
// TODO: can we somehow return both error sources?
Error::with_cause(
ErrorKind::Unavailable,
"seeding a new RNG failed: both OS and Jitter entropy sources failed",
e1)
})
})
let mut source = EntropySource::new()?;
R::from_rng(&mut source)
}
}

Expand Down

0 comments on commit 2278d44

Please sign in to comment.