]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/windows/rand.rs
Auto merge of #65779 - kevgrasso:E0308highlight, r=estebank
[rust.git] / src / libstd / sys / windows / rand.rs
1 use crate::io;
2 use crate::mem;
3 use crate::sys::c;
4
5 #[cfg(not(target_vendor = "uwp"))]
6 pub fn hashmap_random_keys() -> (u64, u64) {
7     let mut v = (0, 0);
8     let ret = unsafe {
9         c::RtlGenRandom(&mut v as *mut _ as *mut u8,
10                         mem::size_of_val(&v) as c::ULONG)
11     };
12     if ret == 0 {
13         panic!("couldn't generate random bytes: {}",
14                io::Error::last_os_error());
15     }
16     v
17 }
18
19 #[cfg(target_vendor = "uwp")]
20 pub fn hashmap_random_keys() -> (u64, u64) {
21     use crate::ptr;
22
23     let mut v = (0, 0);
24     let ret = unsafe {
25         c::BCryptGenRandom(ptr::null_mut(), &mut v as *mut _ as *mut u8,
26                            mem::size_of_val(&v) as c::ULONG,
27                            c::BCRYPT_USE_SYSTEM_PREFERRED_RNG)
28     };
29     if ret != 0 {
30         panic!("couldn't generate random bytes: {}",
31                io::Error::last_os_error());
32     }
33     return v
34 }