Skip to content

Commit ffad2b0

Browse files
committed
Use EntropySource in NewSeeded
1 parent 0935467 commit ffad2b0

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

src/lib.rs

+2-21
Original file line numberDiff line numberDiff line change
@@ -843,27 +843,8 @@ pub trait NewSeeded: SeedableRng {
843843
#[cfg(feature="std")]
844844
impl<R: SeedableRng> NewSeeded for R {
845845
fn new() -> Result<Self, Error> {
846-
// Note: error handling would be easier with try/catch blocks
847-
fn new_os<T: SeedableRng>() -> Result<T, Error> {
848-
let mut r = OsRng::new()?;
849-
T::from_rng(&mut r)
850-
}
851-
852-
fn new_jitter<T: SeedableRng>() -> Result<T, Error> {
853-
let mut r = JitterRng::new()?;
854-
T::from_rng(&mut r)
855-
}
856-
857-
new_os().or_else(|e1| {
858-
new_jitter().map_err(|_e2| {
859-
// TODO: log
860-
// TODO: can we somehow return both error sources?
861-
Error::with_cause(
862-
ErrorKind::Unavailable,
863-
"seeding a new RNG failed: both OS and Jitter entropy sources failed",
864-
e1)
865-
})
866-
})
846+
let mut source = EntropySource::new()?;
847+
R::from_rng(&mut source)
867848
}
868849
}
869850

0 commit comments

Comments
 (0)