Document rand module

This commit is contained in:
johnthagen 2017-09-28 09:49:03 -04:00
parent 2c58c39e84
commit 220c707fd9
1 changed files with 18 additions and 0 deletions

View File

@ -1,9 +1,27 @@
//! Cryptographically strong random bytes.
//!
//! This module exposes functionality to put cryptographically strong
//! pseudo-random bytes into a buffer.
//!
//! # Examples
//!
//! To generate a buffer with cryptographically strong bytes:
//!
//! ```
//! let muf 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)
use libc::c_int; use libc::c_int;
use ffi; use ffi;
use cvt; use cvt;
use error::ErrorStack; use error::ErrorStack;
/// Fills buffer with cryptographically strong pseudo-random bytes.
pub fn rand_bytes(buf: &mut [u8]) -> Result<(), ErrorStack> { pub fn rand_bytes(buf: &mut [u8]) -> Result<(), ErrorStack> {
unsafe { unsafe {
ffi::init(); ffi::init();