Skip to content

Commit 5792a52

Browse files
committed
Replace uses of fuchsia-zircon with fuchsia-cprng
As in #706, fuchsia is replacing users of fuchsia-zircon with fuchsia-cprng, since that reduces exposure to our changing syscalls. If this is accepted, could a new version be cut?
1 parent 317651c commit 5792a52

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ appveyor = { repository = "alexcrichton/rand" }
2020
[features]
2121
default = ["std" ] # without "std" rand uses libcore
2222
nightly = ["i128_support"] # enables all features requiring nightly rust
23-
std = ["rand_core/std", "alloc", "libc", "winapi", "cloudabi", "fuchsia-zircon"]
23+
std = ["rand_core/std", "alloc", "libc", "winapi", "cloudabi", "fuchsia-cprng"]
2424
alloc = ["rand_core/alloc"] # enables Vec and Box support (without std)
2525
i128_support = [] # enables i128 and u128 support
2626
serde1 = ["serde", "serde_derive", "rand_core/serde1"] # enables serialization for PRNGs
@@ -44,7 +44,7 @@ winapi = { version = "0.3", features = ["minwindef", "ntsecapi", "profileapi", "
4444
cloudabi = { version = "0.0.3", optional = true }
4545

4646
[target.'cfg(target_os = "fuchsia")'.dependencies]
47-
fuchsia-zircon = { version = "0.3.2", optional = true }
47+
fuchsia-cprng = { version = "0.1.0", optional = true }
4848

4949
[target.wasm32-unknown-unknown.dependencies]
5050
# use with `--target wasm32-unknown-unknown --features=stdweb`

src/rngs/os.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -924,9 +924,9 @@ mod imp {
924924

925925
#[cfg(target_os = "fuchsia")]
926926
mod imp {
927-
extern crate fuchsia_zircon;
927+
extern crate fuchsia_cprng;
928928

929-
use {Error, ErrorKind};
929+
use Error;
930930
use super::OsRngImpl;
931931

932932
#[derive(Clone, Debug)]
@@ -936,25 +936,10 @@ mod imp {
936936
fn new() -> Result<OsRng, Error> { Ok(OsRng) }
937937

938938
fn fill_chunk(&mut self, dest: &mut [u8]) -> Result<(), Error> {
939-
let mut read = 0;
940-
while read < dest.len() {
941-
match fuchsia_zircon::cprng_draw(&mut dest[read..]) {
942-
Ok(actual) => read += actual,
943-
Err(e) => {
944-
return Err(Error::with_cause(
945-
ErrorKind::Unavailable,
946-
"cprng_draw failed",
947-
e.into_io_error()));
948-
}
949-
};
950-
}
939+
fuchsia_cprng::cprng_draw(dest);
951940
Ok(())
952941
}
953942

954-
fn max_chunk_size(&self) -> usize {
955-
fuchsia_zircon::sys::ZX_CPRNG_DRAW_MAX_LEN
956-
}
957-
958943
fn method_str(&self) -> &'static str { "cprng_draw" }
959944
}
960945
}

0 commit comments

Comments
 (0)