aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2017-09-28 23:56:03 -0400
committerGitHub <[email protected]>2017-09-28 23:56:03 -0400
commitc3fc4944276182cd4d030509f07febfc31e874ff (patch)
treedb01d713d2245785768c08bf4d681ef3aa198d61 /openssl/src
parentMerge pull request #738 from johnthagen/readme (diff)
parentFix doc test and move external documentation link to rand_bytes function (diff)
downloadrust-openssl-c3fc4944276182cd4d030509f07febfc31e874ff.tar.xz
rust-openssl-c3fc4944276182cd4d030509f07febfc31e874ff.zip
Merge pull request #737 from johnthagen/rand
Document rand module
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/rand.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/openssl/src/rand.rs b/openssl/src/rand.rs
index c1c49e7b..da52ef5f 100644
--- a/openssl/src/rand.rs
+++ b/openssl/src/rand.rs
@@ -1,9 +1,37 @@
+//! Utilities for secure random number generation.
+//!
+//! # Examples
+//!
+//! To generate a buffer with cryptographically strong bytes:
+//!
+//! ```
+//! use openssl::rand::rand_bytes;
+//!
+//! let mut buf = [0; 256];
+//! rand_bytes(&mut buf).unwrap();
+//! ```
use libc::c_int;
use ffi;
use cvt;
use error::ErrorStack;
+/// Fill buffer with cryptographically strong pseudo-random bytes.
+///
+/// # Examples
+///
+/// To generate a buffer with cryptographically strong bytes:
+///
+/// ```
+/// use openssl::rand::rand_bytes;
+///
+/// let mut buf = [0; 256];
+/// rand_bytes(&mut buf).unwrap();
+/// ```
+///
+/// # External OpenSSL Documentation
+///
+/// [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();