pub struct RandomNumberGenerator { /* private fields */ }Expand description
A cryptographic random number generator
Implementations§
Source§impl RandomNumberGenerator
impl RandomNumberGenerator
Sourcepub fn new_of_type(typ: &str) -> Result<RandomNumberGenerator>
pub fn new_of_type(typ: &str) -> Result<RandomNumberGenerator>
Create a new RNG object with a specific type, e.g. “esdm-full”
§Examples
// This is just for demonstration, use RandomNumberGenerator::new_userspace() instead.
let specific_rng = botan::RandomNumberGenerator::new_of_type("user").unwrap();Sourcepub fn new_userspace() -> Result<RandomNumberGenerator>
pub fn new_userspace() -> Result<RandomNumberGenerator>
Create a new userspace RNG object
§Examples
let userspace_rng = botan::RandomNumberGenerator::new_userspace().unwrap();Sourcepub fn new_system() -> Result<RandomNumberGenerator>
pub fn new_system() -> Result<RandomNumberGenerator>
Create a new reference to the system PRNG
§Examples
let system_rng = botan::RandomNumberGenerator::new_system().unwrap();Sourcepub fn new_esdm() -> Result<RandomNumberGenerator>
pub fn new_esdm() -> Result<RandomNumberGenerator>
Sourcepub fn new_esdm_pr() -> Result<RandomNumberGenerator>
pub fn new_esdm_pr() -> Result<RandomNumberGenerator>
Sourcepub fn new_jitter() -> Result<RandomNumberGenerator>
pub fn new_jitter() -> Result<RandomNumberGenerator>
Sourcepub fn new() -> Result<RandomNumberGenerator>
pub fn new() -> Result<RandomNumberGenerator>
Create a new reference to an RNG of some arbitrary type
§Examples
let a_rng = botan::RandomNumberGenerator::new().unwrap();Sourcepub fn read(&mut self, len: usize) -> Result<Vec<u8>>
pub fn read(&mut self, len: usize) -> Result<Vec<u8>>
Read bytes from an RNG
§Examples
let mut rng = botan::RandomNumberGenerator::new().unwrap();
let output = rng.read(32).unwrap();
assert_eq!(output.len(), 32);Sourcepub fn fill(&mut self, out: &mut [u8]) -> Result<()>
pub fn fill(&mut self, out: &mut [u8]) -> Result<()>
Store bytes from the RNG into the passed slice
§Examples
let mut rng = botan::RandomNumberGenerator::new().unwrap();
let mut output = vec![0; 32];
rng.fill(&mut output).unwrap();Sourcepub fn reseed(&mut self, bits: usize) -> Result<()>
pub fn reseed(&mut self, bits: usize) -> Result<()>
Attempt to reseed the RNG by unspecified means
§Examples
let mut rng = botan::RandomNumberGenerator::new().unwrap();
rng.reseed(256).unwrap();Sourcepub fn reseed_from_rng(
&mut self,
source: &mut RandomNumberGenerator,
bits: usize,
) -> Result<()>
pub fn reseed_from_rng( &mut self, source: &mut RandomNumberGenerator, bits: usize, ) -> Result<()>
Attempt to reseed the RNG by getting data from source RNG
§Examples
let mut system_rng = botan::RandomNumberGenerator::new_system().unwrap();
let mut rng = botan::RandomNumberGenerator::new_userspace().unwrap();
rng.reseed_from_rng(&mut system_rng, 256).unwrap();Trait Implementations§
Source§impl Debug for RandomNumberGenerator
impl Debug for RandomNumberGenerator
Source§impl Drop for RandomNumberGenerator
impl Drop for RandomNumberGenerator
impl Send for RandomNumberGenerator
impl Sync for RandomNumberGenerator
Auto Trait Implementations§
impl Freeze for RandomNumberGenerator
impl RefUnwindSafe for RandomNumberGenerator
impl Unpin for RandomNumberGenerator
impl UnwindSafe for RandomNumberGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more