diff --git a/src/lib.rs b/src/lib.rs index 1c312c002d..5d6d203743 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -834,27 +834,8 @@ pub trait NewRng: SeedableRng { #[cfg(feature="std")] impl NewRng for R { fn new() -> Result { - // Note: error handling would be easier with try/catch blocks - fn new_os() -> Result { - let mut r = OsRng::new()?; - T::from_rng(&mut r) - } - - fn new_jitter() -> Result { - 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) } }