Struct netstack3_core::testutil::context::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
impl FakeCryptoRng
sourcepub fn new_xorshift(seed: u128) -> FakeCryptoRng
pub fn new_xorshift(seed: u128) -> FakeCryptoRng
Creates a new FakeCryptoRng<XorShiftRng>
from a seed.
sourcepub fn deep_clone(&self) -> FakeCryptoRng
pub fn deep_clone(&self) -> FakeCryptoRng
Returns a deep clone of this RNG, copying the current RNG state.
sourcepub fn with_fake_rngs<F>(iterations: u128, f: F)where
F: Fn(FakeCryptoRng),
pub fn with_fake_rngs<F>(iterations: u128, f: F)where
F: Fn(FakeCryptoRng),
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 for FakeCryptoRng<R>where
R: Clone,
impl<R> Clone for FakeCryptoRng<R>where
R: Clone,
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 for FakeCryptoRng<R>where
R: Debug,
impl<R> Debug for FakeCryptoRng<R>where
R: Debug,
source§impl Default for FakeCryptoRng
impl Default for FakeCryptoRng
source§fn default() -> FakeCryptoRng
fn default() -> FakeCryptoRng
Returns the “default value” for a type. Read more
source§impl<R> RngContext for FakeCryptoRng<R>where
R: RngCore,
impl<R> RngContext for FakeCryptoRng<R>where
R: RngCore,
§type Rng<'a> = &'a mut FakeCryptoRng<R>
where
FakeCryptoRng<R>: 'a
type Rng<'a> = &'a mut FakeCryptoRng<R> where FakeCryptoRng<R>: 'a
The random number generator (RNG) provided by this
RngContext
. Read moresource§fn rng(&mut self) -> <FakeCryptoRng<R> as RngContext>::Rng<'_>
fn rng(&mut self) -> <FakeCryptoRng<R> as RngContext>::Rng<'_>
Gets the random number generator (RNG).
source§impl<R> RngCore for FakeCryptoRng<R>where
R: RngCore,
impl<R> RngCore for FakeCryptoRng<R>where
R: RngCore,
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 for FakeCryptoRng<R>where
R: SeedableRng,
impl<R> SeedableRng for FakeCryptoRng<R>where
R: SeedableRng,
§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 from_seed(seed: <FakeCryptoRng<R> as SeedableRng>::Seed) -> FakeCryptoRng<R>
fn from_seed(seed: <FakeCryptoRng<R> as SeedableRng>::Seed) -> FakeCryptoRng<R>
Create a new PRNG using the given seed. Read more
source§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> CryptoRng for FakeCryptoRng<R>where
R: RngCore,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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.