Skip to content

Commit c864540

Browse files
authored
Merge pull request #706 from erickt/master
Switch rand_os to use fuchsia-cprng crate in rand-0.6
2 parents 6f3875f + c963f9d commit c864540

File tree

2 files changed

+4
-19
lines changed

2 files changed

+4
-19
lines changed

rand_os/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ winapi = { version = "0.3", features = ["minwindef", "ntsecapi", "winnt"] }
2828
cloudabi = "0.0.3"
2929

3030
[target.'cfg(target_os = "fuchsia")'.dependencies]
31-
fuchsia-zircon = "0.3.2"
31+
fuchsia-cprng = "0.1.0"
3232

3333
[target.wasm32-unknown-unknown.dependencies]
3434
wasm-bindgen = { version = "0.2.12", optional = true }

rand_os/src/fuchsia.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
//! Implementation for Fuchsia Zircon
1010
11-
extern crate fuchsia_zircon;
11+
extern crate fuchsia_cprng;
1212

13-
use rand_core::{Error, ErrorKind};
13+
use rand_core::Error;
1414
use super::OsRngImpl;
1515

1616
#[derive(Clone, Debug)]
@@ -20,24 +20,9 @@ impl OsRngImpl for OsRng {
2020
fn new() -> Result<OsRng, Error> { Ok(OsRng) }
2121

2222
fn fill_chunk(&mut self, dest: &mut [u8]) -> Result<(), Error> {
23-
let mut read = 0;
24-
while read < dest.len() {
25-
match fuchsia_zircon::cprng_draw(&mut dest[read..]) {
26-
Ok(actual) => read += actual,
27-
Err(e) => {
28-
return Err(Error::with_cause(
29-
ErrorKind::Unavailable,
30-
"cprng_draw failed",
31-
e.into_io_error()));
32-
}
33-
};
34-
}
23+
fuchsia_cprng::cprng_draw(dest);
3524
Ok(())
3625
}
3726

38-
fn max_chunk_size(&self) -> usize {
39-
fuchsia_zircon::sys::ZX_CPRNG_DRAW_MAX_LEN
40-
}
41-
4227
fn method_str(&self) -> &'static str { "cprng_draw" }
4328
}

0 commit comments

Comments
 (0)