diff options
| author | Steven Fackler <[email protected]> | 2016-10-22 09:16:38 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-10-22 09:16:38 -0700 |
| commit | 98b7f2f9352e4d92b44245d0737f9a45adb4ae2b (patch) | |
| tree | 983929f8b6cd8be9e42e226ac74a5ddc5f29ccd5 /openssl/src/rand.rs | |
| parent | Properly propagate panics (diff) | |
| download | rust-openssl-98b7f2f9352e4d92b44245d0737f9a45adb4ae2b.tar.xz rust-openssl-98b7f2f9352e4d92b44245d0737f9a45adb4ae2b.zip | |
Flatten crypto module
Diffstat (limited to 'openssl/src/rand.rs')
| -rw-r--r-- | openssl/src/rand.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/openssl/src/rand.rs b/openssl/src/rand.rs new file mode 100644 index 00000000..c1c49e7b --- /dev/null +++ b/openssl/src/rand.rs @@ -0,0 +1,24 @@ +use libc::c_int; +use ffi; + +use cvt; +use error::ErrorStack; + +pub fn rand_bytes(buf: &mut [u8]) -> Result<(), ErrorStack> { + unsafe { + ffi::init(); + assert!(buf.len() <= c_int::max_value() as usize); + cvt(ffi::RAND_bytes(buf.as_mut_ptr(), buf.len() as c_int)).map(|_| ()) + } +} + +#[cfg(test)] +mod tests { + use super::rand_bytes; + + #[test] + fn test_rand_bytes() { + let mut buf = [0; 32]; + rand_bytes(&mut buf).unwrap(); + } +} |