@@ -205,6 +205,9 @@ pub use crate::error::Error;
205
205
//
206
206
// These should all provide getrandom_inner with the signature
207
207
// `fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error>`.
208
+ // The function MUST fully initialize `dest` when `Ok(())` is returned.
209
+ // The function MUST NOT ever write uninitialized bytes into `dest`,
210
+ // regardless of what value it returns.
208
211
cfg_if ! {
209
212
if #[ cfg( any( target_os = "emscripten" , target_os = "haiku" ,
210
213
target_os = "redox" ) ) ] {
@@ -290,8 +293,11 @@ cfg_if! {
290
293
/// [`rand::thread_rng`](https://docs.rs/rand/*/rand/fn.thread_rng.html).
291
294
#[ inline]
292
295
pub fn getrandom ( dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
293
- // SAFETY: The `&mut MaybeUninit<_>` reference doesn't escape.
294
- getrandom_uninit_slice ( unsafe { slice_as_uninit_mut ( dest) } ) . map ( |_| ( ) )
296
+ // SAFETY: The `&mut MaybeUninit<_>` reference doesn't escape, and
297
+ // `getrandom_uninit_slice` guarantees it will never de-initialize any
298
+ // part of `dest`.
299
+ getrandom_uninit_slice ( unsafe { slice_as_uninit_mut ( dest) } ) ?;
300
+ Ok ( ( ) )
295
301
}
296
302
297
303
/// Version of the `getrandom` function which fills `dest` with random bytes
@@ -302,6 +308,9 @@ pub fn getrandom(dest: &mut [u8]) -> Result<(), Error> {
302
308
/// In other words, it's safe to assume that `dest` is initialized after
303
309
/// this function has returned `Ok`.
304
310
///
311
+ /// No part of `dest` will ever be de-initialized at any point, regardless
312
+ /// of what is returned.
313
+ ///
305
314
/// # Examples
306
315
///
307
316
/// ```ignore
0 commit comments