Skip to content

Commit 9f87c44

Browse files
committed
custom: Expose cpurand directly
This allows users to get CPU-based randomness directly, even on platforms that have a normal getrandom implementation. Signed-off-by: Joe Richey <[email protected]>
1 parent 8e2c423 commit 9f87c44

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

custom/cpurand/src/lib.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,13 @@ cfg_if! {
2121
}
2222
}
2323

24-
register_custom_getrandom!(imp::getrandom_inner);
24+
/// Fill `dest` with random bytes via the CPU's randomness instructions.
25+
///
26+
/// This function returns an error on any failure, including partial reads. This
27+
/// can happen if your CPU does not support the required instructions, or if the
28+
/// CPU has encountered an internal failure.
29+
pub fn cpurand(dest: &mut [u8]) -> Result<(), Error> {
30+
imp::getrandom_inner(dest)
31+
}
32+
33+
register_custom_getrandom!(cpurand);

0 commit comments

Comments
 (0)