win_crypto_ng::random

Struct RandomNumberGenerator

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

Random number generator

Main type that is capable of generating random numbers.

Implementations§

Source§

impl RandomNumberGenerator

Source

pub fn open(id: RandomAlgorithmId) -> Result<RandomNumberGenerator>

Open a random number generator using the provided algorithm.

§Examples
let rng = RandomNumberGenerator::open(RandomAlgorithmId::Rng);

assert!(rng.is_ok());
Source

pub fn system_preferred() -> RandomNumberGenerator

Open a random number generator using the system preferred algorithm.

Windows Vista: This is not supported.

Source

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

Fills a buffer with random bytes.

Use a random number for the entropy.

§Examples
let mut buffer = [0u8; 32];
let rng = RandomNumberGenerator::system_preferred();
rng.gen_random(&mut buffer).unwrap();

assert_ne!(&buffer, &[0u8; 32]);
Source

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

Fills a buffer with random bytes.

This function will use the number in the buffer as additional entropy for the random number.

Windows 8 and later: This does the exact same thing as gen_random.

§Examples
let mut buffer = [0u8; 32];
let rng = RandomNumberGenerator::system_preferred();
rng.gen_random_with_entropy_in_buffer(&mut buffer).unwrap();

assert_ne!(&buffer, &[0u8; 32]);

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.