Struct RandomNumberGenerator

Source
pub struct RandomNumberGenerator { /* private fields */ }
Expand description

A cryptographic random number generator

Implementations§

Source§

impl RandomNumberGenerator

Source

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();
Source

pub fn new_userspace() -> Result<RandomNumberGenerator>

Create a new userspace RNG object

§Examples
let userspace_rng = botan::RandomNumberGenerator::new_userspace().unwrap();
Source

pub fn new_system() -> Result<RandomNumberGenerator>

Create a new reference to the system PRNG

§Examples
let system_rng = botan::RandomNumberGenerator::new_system().unwrap();
Source

pub fn new_esdm() -> Result<RandomNumberGenerator>

Create a new reference to the ESDM PRNG (fully seeded)

Availability of this RNG depends on botan being compiled with ESDM support.

§Examples
let esdm_rng = botan::RandomNumberGenerator::new_esdm().unwrap();
Source

pub fn new_esdm_pr() -> Result<RandomNumberGenerator>

Create a new reference to the ESDM PRNG (with prediction resistance)

Availability of this RNG depends on botan being compiled with ESDM support.

§Examples
let esdm_rng = botan::RandomNumberGenerator::new_esdm_pr().unwrap();
Source

pub fn new_jitter() -> Result<RandomNumberGenerator>

Create a new reference to the Jitter RNG

Availability of this RNG depends on botan being compiled with Jitter RNG support.

§Examples
let jitter_rng = botan::RandomNumberGenerator::new_jitter().unwrap();
Source

pub fn new() -> Result<RandomNumberGenerator>

Create a new reference to an RNG of some arbitrary type

§Examples
let a_rng = botan::RandomNumberGenerator::new().unwrap();
Source

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);
Source

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();
Source

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();
Source

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();
Source

pub fn add_entropy(&mut self, seed: &[u8]) -> Result<()>

Add some seed material to the RNG

§Examples
let mut rng = botan::RandomNumberGenerator::new_userspace().unwrap();
let my_seed = vec![0x42, 0x6F, 0x62];
rng.add_entropy(&my_seed);

Trait Implementations§

Source§

impl Debug for RandomNumberGenerator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for RandomNumberGenerator

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for RandomNumberGenerator

Source§

impl Sync for RandomNumberGenerator

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.