File tree 1 file changed +6
-1
lines changed
1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -258,13 +258,18 @@ cfg_if! {
258
258
/// source.
259
259
///
260
260
/// This function returns an error on any failure, including partial reads. We
261
- /// make no guarantees regarding the contents of `dest` on error.
261
+ /// make no guarantees regarding the contents of `dest` on error. If `dest` is
262
+ /// empty, `getrandom` immediately returns success, making no calls to the
263
+ /// underlying operating system.
262
264
///
263
265
/// Blocking is possible, at least during early boot; see module documentation.
264
266
///
265
267
/// In general, `getrandom` will be fast enough for interactive usage, though
266
268
/// significantly slower than a user-space CSPRNG; for the latter consider
267
269
/// [`rand::thread_rng`](https://docs.rs/rand/*/rand/fn.thread_rng.html).
268
270
pub fn getrandom ( dest : & mut [ u8 ] ) -> Result < ( ) , error:: Error > {
271
+ if dest. is_empty ( ) {
272
+ return Ok ( ( ) )
273
+ }
269
274
imp:: getrandom_inner ( dest)
270
275
}
You can’t perform that action at this time.
0 commit comments