Skip to main content

Rand

Struct Rand 

Source
pub struct Rand;
Expand description

Zero-size type with static methods wrapping RAND_bytes / RAND_priv_bytes.

Implementations§

Source§

impl Rand

Source

pub fn fill(buf: &mut [u8]) -> Result<(), ErrorStack>

Fill buf with cryptographically random bytes.

Zero-copy: writes directly into the caller’s buffer.

§Panics

Panics if buf.len() > i32::MAX.

§Errors

Returns Err if the PRNG fails (e.g. not seeded).

Source

pub fn fill_private(buf: &mut [u8]) -> Result<(), ErrorStack>

Fill buf with private (non-predictable) random bytes.

§Panics

Panics if buf.len() > i32::MAX.

§Errors
Source

pub fn bytes(n: usize) -> Result<Vec<u8>, ErrorStack>

Allocate and fill a Vec<u8> of n random bytes.

Prefer fill when the destination buffer is already allocated.

§Errors
Source

pub fn bytes_private(n: usize) -> Result<Vec<u8>, ErrorStack>

Allocate and fill a Vec<u8> of n private random bytes.

Equivalent to bytes but uses RAND_priv_bytes — suitable for key material and other values that must not be disclosed.

§Errors

Auto Trait Implementations§

§

impl Freeze for Rand

§

impl RefUnwindSafe for Rand

§

impl Send for Rand

§

impl Sync for Rand

§

impl Unpin for Rand

§

impl UnsafeUnpin for Rand

§

impl UnwindSafe for Rand

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.