]> git.proxmox.com Git - cargo.git/blob - vendor/openssl-0.9.19/src/rand.rs
New upstream version 0.23.0
[cargo.git] / vendor / openssl-0.9.19 / src / rand.rs
1 use libc::c_int;
2 use ffi;
3
4 use cvt;
5 use error::ErrorStack;
6
7 pub fn rand_bytes(buf: &mut [u8]) -> Result<(), ErrorStack> {
8 unsafe {
9 ffi::init();
10 assert!(buf.len() <= c_int::max_value() as usize);
11 cvt(ffi::RAND_bytes(buf.as_mut_ptr(), buf.len() as c_int)).map(|_| ())
12 }
13 }
14
15 #[cfg(test)]
16 mod tests {
17 use super::rand_bytes;
18
19 #[test]
20 fn test_rand_bytes() {
21 let mut buf = [0; 32];
22 rand_bytes(&mut buf).unwrap();
23 }
24 }