diff options
| author | Steven Fackler <[email protected]> | 2015-02-07 21:28:54 -0800 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2015-02-07 21:30:05 -0800 |
| commit | ec65b0c67b452539fded5e06cbb6ce1d165074e0 (patch) | |
| tree | c50c22c2ce4ca095149c96a0f3a3b935b4012a5c /openssl/src/crypto/rand.rs | |
| parent | Fix deprecation warnings in openssl-sys (diff) | |
| download | rust-openssl-ec65b0c67b452539fded5e06cbb6ce1d165074e0.tar.xz rust-openssl-ec65b0c67b452539fded5e06cbb6ce1d165074e0.zip | |
Move docs to this repo and auto build
Diffstat (limited to 'openssl/src/crypto/rand.rs')
| -rw-r--r-- | openssl/src/crypto/rand.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/openssl/src/crypto/rand.rs b/openssl/src/crypto/rand.rs new file mode 100644 index 00000000..dc338a3d --- /dev/null +++ b/openssl/src/crypto/rand.rs @@ -0,0 +1,27 @@ +use libc::c_int; +use ffi; + +pub fn rand_bytes(len: usize) -> Vec<u8> { + unsafe { + let mut out = Vec::with_capacity(len); + + ffi::init(); + let r = ffi::RAND_bytes(out.as_mut_ptr(), len as c_int); + if r != 1 as c_int { panic!() } + + out.set_len(len); + + out + } +} + +#[cfg(test)] +mod tests { + use super::rand_bytes; + + #[test] + fn test_rand_bytes() { + let bytes = rand_bytes(32); + println!("{:?}", bytes); + } +} |