Struct netstack3_base::testutil::FakeCryptoRng
source · pub struct FakeCryptoRng<R = XorShiftRng>(/* private fields */);
Expand description
A wrapper which implements RngCore
and CryptoRng
for any RngCore
.
This is used to satisfy RngContext
’s requirement that the
associated Rng
type implements CryptoRng
.
§Security
This is obviously insecure. Don’t use it except in testing!
Implementations§
source§impl FakeCryptoRng<XorShiftRng>
impl FakeCryptoRng<XorShiftRng>
sourcepub fn new_xorshift(seed: u128) -> FakeCryptoRng<XorShiftRng>
pub fn new_xorshift(seed: u128) -> FakeCryptoRng<XorShiftRng>
Creates a new FakeCryptoRng<XorShiftRng>
from a seed.
sourcepub fn deep_clone(&self) -> Self
pub fn deep_clone(&self) -> Self
Returns a deep clone of this RNG, copying the current RNG state.
sourcepub fn with_fake_rngs<F: Fn(Self)>(iterations: u128, f: F)
pub fn with_fake_rngs<F: Fn(Self)>(iterations: u128, f: F)
Creates iterations
fake RNGs.
with_fake_rngs
will create iterations
different
FakeCryptoRng
s and call the function f
for each one of them.
This function can be used for tests that weed out weirdness that can happen with certain random number sequences.
Trait Implementations§
source§impl<R: Clone> Clone for FakeCryptoRng<R>
impl<R: Clone> Clone for FakeCryptoRng<R>
source§fn clone(&self) -> FakeCryptoRng<R>
fn clone(&self) -> FakeCryptoRng<R>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<R: Debug> Debug for FakeCryptoRng<R>
impl<R: Debug> Debug for FakeCryptoRng<R>
source§impl Default for FakeCryptoRng<XorShiftRng>
impl Default for FakeCryptoRng<XorShiftRng>
source§fn default() -> FakeCryptoRng<XorShiftRng>
fn default() -> FakeCryptoRng<XorShiftRng>
Returns the “default value” for a type. Read more
source§impl<R: RngCore> RngContext for FakeCryptoRng<R>
impl<R: RngCore> RngContext for FakeCryptoRng<R>
source§impl<R: RngCore> RngCore for FakeCryptoRng<R>
impl<R: RngCore> RngCore for FakeCryptoRng<R>
source§fn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
Fill
dest
with random data. Read moresource§impl<R: SeedableRng> SeedableRng for FakeCryptoRng<R>
impl<R: SeedableRng> SeedableRng for FakeCryptoRng<R>
§type Seed = <R as SeedableRng>::Seed
type Seed = <R as SeedableRng>::Seed
Seed type, which is restricted to types mutably-dereferencable as
u8
arrays (we recommend [u8; N]
for some N
). Read moresource§fn seed_from_u64(state: u64) -> Self
fn seed_from_u64(state: u64) -> Self
Create a new PRNG using a
u64
seed. Read moresource§fn from_rng<R>(rng: R) -> Result<Self, Error>where
R: RngCore,
fn from_rng<R>(rng: R) -> Result<Self, Error>where
R: RngCore,
Create a new PRNG seeded from another
Rng
. Read moresource§fn from_entropy() -> Self
fn from_entropy() -> Self
impl<R: RngCore> CryptoRng for FakeCryptoRng<R>
Auto Trait Implementations§
impl<R> Freeze for FakeCryptoRng<R>
impl<R> RefUnwindSafe for FakeCryptoRng<R>
impl<R> Send for FakeCryptoRng<R>where
R: Send,
impl<R> Sync for FakeCryptoRng<R>where
R: Send,
impl<R> Unpin for FakeCryptoRng<R>
impl<R> UnwindSafe for FakeCryptoRng<R>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<CC, BC, Meta> RecvFrameContext<BC, Meta> for CCwhere
Meta: ReceivableFrameMeta<CC, BC>,
impl<CC, BC, Meta> RecvFrameContext<BC, Meta> for CCwhere
Meta: ReceivableFrameMeta<CC, BC>,
source§impl<R> Rng for R
impl<R> Rng for R
source§fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
fn gen<T>(&mut self) -> Twhere
Standard: Distribution<T>,
source§fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn gen_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Generate a random value in the given range. Read more
source§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Sample a new value, using the given distribution. Read more
source§fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Create an iterator that generates values using the given distribution. Read more
source§fn gen_bool(&mut self, p: f64) -> bool
fn gen_bool(&mut self, p: f64) -> bool
Return a bool with a probability
p
of being true. Read moresource§fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool
Return a bool with a probability of
numerator/denominator
of being
true. I.e. gen_ratio(2, 3)
has chance of 2 in 3, or about 67%, of
returning true. If numerator == denominator
, then the returned value
is guaranteed to be true
. If numerator == 0
, then the returned
value is guaranteed to be false
. Read moresource§impl<CC, BC, Meta> SendFrameContext<BC, Meta> for CCwhere
Meta: SendableFrameMeta<CC, BC>,
impl<CC, BC, Meta> SendFrameContext<BC, Meta> for CCwhere
Meta: SendableFrameMeta<CC, BC>,
source§impl<Meta, BC> SendableFrameMeta<FakeFrameCtx<Meta>, BC> for Meta
impl<Meta, BC> SendableFrameMeta<FakeFrameCtx<Meta>, BC> for Meta
source§impl<Id, CC, BC> TimerHandler<BC, Id> for CCwhere
Id: HandleableTimer<CC, BC>,
impl<Id, CC, BC> TimerHandler<BC, Id> for CCwhere
Id: HandleableTimer<CC, BC>,
source§fn handle_timer(&mut self, bindings_ctx: &mut BC, id: Id)
fn handle_timer(&mut self, bindings_ctx: &mut BC, id: Id)
Handle a timer firing.