Skip to content

Commit 0f371be

Browse files
committed
Rename getrandom_os → getrandom_inner; more WASM doc
1 parent 7ff3aff commit 0f371be

16 files changed

+29
-18
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ fn get_random_buf() -> Result<[u8; 32], getrandom::Error> {
3434
}
3535
```
3636

37+
## Features
38+
39+
This library is `no_std` compatible on SGX but requires `std` on most platforms.
40+
41+
For WebAssembly (`wasm32`), Enscripten targets are supported directly; otherwise
42+
one of the following features must be enabled:
43+
44+
- [`wasm-bindgen`](https://crates.io/crates/wasm_bindgen)
45+
- [`stdweb`](https://crates.io/crates/stdweb)
46+
3747

3848
# License
3949

src/cloudabi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern "C" {
1111
fn cloudabi_sys_random_get(buf: *mut u8, len: usize) -> u16;
1212
}
1313

14-
pub fn getrandom_os(dest: &mut [u8]) -> Result<(), Error> {
14+
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1515
let errno = unsafe { cloudabi_sys_random_get(dest.as_ptr(), dest.len()) };
1616
if errno == 0 {
1717
Ok(())

src/dragonfly_haiku.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::cell::RefCell;
1515

1616
thread_local!(static RNG_FILE: RefCell<Option<File>> = RefCell::new(None));
1717

18-
pub fn getrandom_os(dest: &mut [u8]) -> Result<(), Error> {
18+
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1919
RNG_FILE.with(|f| {
2020
use_init(f,
2121
|| File::open("/dev/random").map_err(From::from),

src/dummy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
//! `Err(UNAVAILABLE_ERROR)`
1111
use super::UNAVAILABLE_ERROR;
1212

13-
pub fn getrandom_os(dest: &mut [u8]) -> Result<(), Error> {
13+
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1414
Err(UNAVAILABLE_ERROR)
1515
}

src/emscripten.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::utils::use_init;
1515

1616
thread_local!(static RNG_FILE: RefCell<Option<File>> = RefCell::new(None));
1717

18-
pub fn getrandom_os(dest: &mut [u8]) -> Result<(), Error> {
18+
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1919
// `Crypto.getRandomValues` documents `dest` should be at most 65536
2020
// bytes. `crypto.randomBytes` documents: "To minimize threadpool
2121
// task length variation, partition large randomBytes requests when

src/freebsd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use super::Error;
1313
use core::ptr;
1414
use std::io;
1515

16-
pub fn getrandom_os(dest: &mut [u8]) -> Result<(), Error> {
16+
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1717
let mib = [libc::CTL_KERN, libc::KERN_ARND];
1818
// kern.arandom permits a maximum buffer size of 256 bytes
1919
for chunk in dest.chunks_mut(256) {

src/fuchsia.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern crate fuchsia_cprng;
1111

1212
use super::Error;
1313

14-
pub fn getrandom_os(dest: &mut [u8]) -> Result<(), Error> {
14+
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
1515
fuchsia_cprng::cprng_draw(dest);
1616
Ok(())
1717
}

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
//! The bare WASM target `wasm32-unknown-unknown` tries to call the javascript
4343
//! methods directly, using either `stdweb` or `wasm-bindgen` depending on what
4444
//! features are activated for this crate. Note that if both features are
45-
//! enabled `wasm-bindgen` will be used.
45+
//! enabled `wasm-bindgen` will be used. If neither feature is enabled,
46+
//! `getrandom` will always fail.
4647
//!
4748
//! ## Early boot
4849
//!
@@ -112,14 +113,14 @@ pub use error::{Error, UNKNOWN_ERROR, UNAVAILABLE_ERROR};
112113

113114
// System-specific implementations.
114115
//
115-
// These should all provide getrandom_os with the same signature as getrandom.
116+
// These should all provide getrandom_inner with the same signature as getrandom.
116117

117118
macro_rules! mod_use {
118119
($cond:meta, $module:ident) => {
119120
#[$cond]
120121
mod $module;
121122
#[$cond]
122-
use $module::getrandom_os;
123+
use $module::getrandom_inner;
123124
}
124125
}
125126

@@ -204,5 +205,5 @@ mod_use!(
204205
/// significantly slower than a user-space CSPRNG; for the latter consider
205206
/// [`rand::thread_rng`](https://docs.rs/rand/*/rand/fn.thread_rng.html).
206207
pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
207-
getrandom_os(dest)
208+
getrandom_inner(dest)
208209
}

src/linux_android.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn syscall_getrandom(dest: &mut [u8]) -> Result<(), io::Error> {
3838
Ok(())
3939
}
4040

41-
pub fn getrandom_os(dest: &mut [u8]) -> Result<(), Error> {
41+
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
4242
RNG_SOURCE.with(|f| {
4343
use_init(f,
4444
|| {

src/macos.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern {
2121
) -> c_int;
2222
}
2323

24-
pub fn getrandom_os(dest: &mut [u8]) -> Result<(), Error> {
24+
pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
2525
let ret = unsafe {
2626
SecRandomCopyBytes(
2727
kSecRandomDefault,

0 commit comments

Comments
 (0)