Struct Rng

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

Random Generator.

If the rand_trait feature is enabled, it implements the rand_core::RngCore and rand_core::CryptoRng traits.

§Sample usage

use linux_kcapi::{RngType, Rng};

let rng = Rng::new(RngType::DrbgPrHmacSha256, &seed)?;
rng.get_bytes(&mut data)?;
assert_ne!(zero, data);
rng.get_bytes(&mut data2)?;
assert_ne!(data, data2);

Implementations§

Source§

impl Rng

Source

pub fn new<T>(rng: RngType, seed: &T) -> Result<Self, Error>
where T: AsRef<[u8]> + Clone,

Create a new random generator.

§Errors
Source

pub fn name(&self) -> RngType

Get Rng type

Source

pub fn get_bytes(&self, dest: &mut [u8]) -> Result<(), Error>

fill destination with random bytes

§Errors

Trait Implementations§

Source§

impl RngCore for Rng

Only available with "rand_trait" feature

§Panic

next_u32, next_u64 and fill_bytes will panic in case of error

Source§

fn next_u32(&mut self) -> u32

Return the next random u32. Read more
Source§

fn next_u64(&mut self) -> u64

Return the next random u64. Read more
Source§

fn fill_bytes(&mut self, dest: &mut [u8])

Fill dest with random data. Read more
Source§

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error>

Fill dest entirely with random data. Read more
Source§

impl CryptoRng for Rng

Only available with "rand_trait" feature

Auto Trait Implementations§

§

impl Freeze for Rng

§

impl RefUnwindSafe for Rng

§

impl Send for Rng

§

impl Sync for Rng

§

impl Unpin for Rng

§

impl UnwindSafe for Rng

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> CryptoRngCore for T
where T: CryptoRng + RngCore,

Source§

fn as_rngcore(&mut self) -> &mut dyn RngCore

Upcast to an RngCore trait object.
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.