File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -258,13 +258,18 @@ cfg_if! {
258258/// source.
259259///
260260/// 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.
262264///
263265/// Blocking is possible, at least during early boot; see module documentation.
264266///
265267/// In general, `getrandom` will be fast enough for interactive usage, though
266268/// significantly slower than a user-space CSPRNG; for the latter consider
267269/// [`rand::thread_rng`](https://docs.rs/rand/*/rand/fn.thread_rng.html).
268270pub fn getrandom ( dest : & mut [ u8 ] ) -> Result < ( ) , error:: Error > {
271+ if dest. is_empty ( ) {
272+ return Ok ( ( ) )
273+ }
269274 imp:: getrandom_inner ( dest)
270275}
You can’t perform that action at this time.
0 commit comments