Skip to main content

OxiRng

Struct OxiRng 

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

A ChaCha20 CSPRNG seeded from the OS random source.

Use OxiRng::new to create an instance. The seed is obtained from getrandom::fill which calls /dev/urandom, RtlGenRandom, or arc4random depending on the platform — no C library required.

On Unix platforms, OxiRng automatically reseeds itself if the process PID changes (i.e. after a fork()), preventing parent/child state sharing.

Implementations§

Source§

impl OxiRng

Source

pub fn new() -> Result<Self, CryptoError>

Create a new OxiRng seeded from the OS.

Returns CryptoError::Internal if getrandom fails.

Source

pub fn reseed(&mut self) -> Result<(), CryptoError>

Reseed this RNG from OS entropy.

Replaces the internal ChaCha20 state with a fresh 32-byte seed and updates the stored PID to the current process. The free function crate::reseed is kept for backward compatibility.

Returns CryptoError::Rng if getrandom fails.

Source

pub fn fill_exact<const N: usize>( &mut self, dst: &mut [u8; N], ) -> Result<(), CryptoError>

Fill a fixed-size array with cryptographically random bytes.

Trait Implementations§

Source§

impl Debug for OxiRng

Source§

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

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

impl Display for OxiRng

Source§

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

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

impl Rng for OxiRng

Source§

fn fill(&mut self, dst: &mut [u8]) -> Result<(), CryptoError>

Fill dst with cryptographically secure random bytes.
Source§

impl TryRng for OxiRng

Source§

type Error = CryptoError

The type returned in the event of a RNG error. Read more
Source§

fn try_next_u32(&mut self) -> Result<u32, Self::Error>

Return the next random u32.
Source§

fn try_next_u64(&mut self) -> Result<u64, Self::Error>

Return the next random u64.
Source§

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

Fill dst entirely with random data.
Source§

impl TryCryptoRng for OxiRng

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<R> TryRngCore for R
where R: TryRng,

Source§

type Error = <R as TryRng>::Error

👎Deprecated since 0.10.0:

use TryRng instead

Error type.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,