Trait concrete_csprng::generators::RandomGenerator
source · pub trait RandomGenerator: Iterator<Item = u8> {
type ChildrenIter: Iterator<Item = Self>;
// Required methods
fn new(seed: Seed) -> Self;
fn remaining_bytes(&self) -> ByteCount;
fn try_fork(
&mut self,
n_children: ChildrenCount,
n_bytes: BytesPerChild,
) -> Result<Self::ChildrenIter, ForkError>;
// Provided method
fn next_byte(&mut self) -> Option<u8> { ... }
}
Expand description
A trait for cryptographically secure pseudo-random generators.
See the crate-level documentation for details.
Required Associated Types§
sourcetype ChildrenIter: Iterator<Item = Self>
type ChildrenIter: Iterator<Item = Self>
The iterator over children generators, returned by try_fork
in case of success.
Required Methods§
sourcefn new(seed: Seed) -> Self
fn new(seed: Seed) -> Self
Creates a new generator from a seed.
This operation is usually costly to perform, as the aes round keys need to be generated from the seed.
sourcefn remaining_bytes(&self) -> ByteCount
fn remaining_bytes(&self) -> ByteCount
Returns the number of bytes that can still be outputted by the generator before reaching its bound.
§Note:
A fresh generator can generate 2¹³² bytes. Unfortunately, no rust integer type in is able
to encode such a large number. Consequently ByteCount
uses the largest integer type
available to encode this value: the u128
type. For this reason, this method does not
effectively return the number of remaining bytes, but instead
min(2¹²⁸-1, remaining_bytes)
.
sourcefn try_fork(
&mut self,
n_children: ChildrenCount,
n_bytes: BytesPerChild,
) -> Result<Self::ChildrenIter, ForkError>
fn try_fork( &mut self, n_children: ChildrenCount, n_bytes: BytesPerChild, ) -> Result<Self::ChildrenIter, ForkError>
Tries to fork the generator into an iterator of n_children
new generators, each able to
output n_bytes
bytes.
§Note:
To be successful, the number of remaining bytes for the parent generator must be larger than
n_children*n_bytes
.