Skip to content

Commit a87c65e

Browse files
committed
Remove duplication
1 parent 8ae5b43 commit a87c65e

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

src/rngs/os.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -535,32 +535,9 @@ mod imp {
535535
}
536536

537537

538-
#[cfg(any(target_os = "dragonfly", target_os = "haiku"))]
539-
mod imp {
540-
use Error;
541-
use super::random_device;
542-
use super::OsRngImpl;
543-
use std::fs::File;
544-
545-
#[derive(Clone, Debug)]
546-
pub struct OsRng();
547-
548-
impl OsRngImpl for OsRng {
549-
fn new() -> Result<OsRng, Error> {
550-
random_device::open("/dev/random", &|p| File::open(p))?;
551-
Ok(OsRng())
552-
}
553-
554-
fn fill_chunk(&mut self, dest: &mut [u8]) -> Result<(), Error> {
555-
random_device::read(dest)
556-
}
557-
558-
fn method_str(&self) -> &'static str { "/dev/random" }
559-
}
560-
}
561-
562-
563-
#[cfg(target_os = "emscripten")]
538+
#[cfg(any(target_os = "dragonfly",
539+
target_os = "haiku",
540+
target_os = "emscripten"))]
564541
mod imp {
565542
use Error;
566543
use super::random_device;
@@ -580,6 +557,7 @@ mod imp {
580557
random_device::read(dest)
581558
}
582559

560+
#[cfg(target_os = "emscripten")]
583561
fn max_chunk_size(&self) -> usize {
584562
// `Crypto.getRandomValues` documents `dest` should be at most 65536
585563
// bytes. `crypto.randomBytes` documents: "To minimize threadpool

0 commit comments

Comments
 (0)