diff options
author | Steven Fackler <sfackler@gmail.com> | 2018-11-22 09:29:43 -0700 |
---|---|---|
committer | Steven Fackler <sfackler@gmail.com> | 2018-11-22 09:32:50 -0700 |
commit | 5c7fa43d8721851dd2092e9ebb16ce6d2251cb11 (patch) | |
tree | bf3758aad0583958b70d1fa3fb5df0da4ba3eb2a /openssl/src/rand.rs | |
parent | 894b924f1d76efd3e9698840f1ac0753093a8c2c (diff) | |
download | rust-openssl-5c7fa43d8721851dd2092e9ebb16ce6d2251cb11.zip |
Add bindings to RAND_keep_random_devices_open
Closes #1019
Diffstat (limited to 'openssl/src/rand.rs')
-rw-r--r-- | openssl/src/rand.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/openssl/src/rand.rs b/openssl/src/rand.rs index da52ef5f..6b85efb1 100644 --- a/openssl/src/rand.rs +++ b/openssl/src/rand.rs @@ -10,14 +10,16 @@ //! let mut buf = [0; 256]; //! rand_bytes(&mut buf).unwrap(); //! ``` -use libc::c_int; use ffi; +use libc::c_int; use cvt; use error::ErrorStack; /// Fill buffer with cryptographically strong pseudo-random bytes. /// +/// This corresponds to [`RAND_bytes`]. +/// /// # Examples /// /// To generate a buffer with cryptographically strong bytes: @@ -29,9 +31,7 @@ use error::ErrorStack; /// rand_bytes(&mut buf).unwrap(); /// ``` /// -/// # External OpenSSL Documentation -/// -/// [RAND_bytes](https://www.openssl.org/docs/man1.1.0/crypto/RAND_bytes.html) +/// [`RAND_bytes`](https://www.openssl.org/docs/man1.1.0/crypto/RAND_bytes.html) pub fn rand_bytes(buf: &mut [u8]) -> Result<(), ErrorStack> { unsafe { ffi::init(); @@ -40,6 +40,20 @@ pub fn rand_bytes(buf: &mut [u8]) -> Result<(), ErrorStack> { } } +/// Controls random device file descriptor behavior. +/// +/// Requires OpenSSL 1.1.1 or newer. +/// +/// This corresponds to [`RAND_keep_random_devices_open`]. +/// +/// [`RAND_keep_random_devices_open`]: https://www.openssl.org/docs/manmaster/man3/RAND_keep_random_devices_open.html +#[cfg(ossl111)] +pub fn keep_random_devices_open(keep: bool) { + unsafe { + ffi::RAND_keep_random_devices_open(keep as c_int); + } +} + #[cfg(test)] mod tests { use super::rand_bytes; |