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

source

pub fn new_xorshift(seed: u128) -> FakeCryptoRng

Creates a new FakeCryptoRng<XorShiftRng> from a seed.

source

pub fn deep_clone(&self) -> FakeCryptoRng

Returns a deep clone of this RNG, copying the current RNG state.

source

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 FakeCryptoRngs 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,

source§

fn clone(&self) -> FakeCryptoRng<R>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<R> Debug for FakeCryptoRng<R>
where R: Debug,

source§

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

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

impl Default for FakeCryptoRng

source§

fn default() -> FakeCryptoRng

Returns the “default value” for a type. Read more
source§

impl<R> RngContext for FakeCryptoRng<R>
where R: RngCore,

§

type Rng<'a> = &'a mut FakeCryptoRng<R> where FakeCryptoRng<R>: 'a

The random number generator (RNG) provided by this RngContext. Read more
source§

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,

source§

fn next_u32(&mut self) -> u32

Return the next random u32. Read more
source§

fn next_u64(&mut self) -> u64

Return the next random u64. Read more
source§

fn fill_bytes(&mut self, dest: &mut [u8])

Fill dest with random data. Read more
source§

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

Fill dest entirely with random data. Read more
source§

impl<R> SeedableRng for FakeCryptoRng<R>
where R: SeedableRng,

§

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 more
source§

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

Create a new PRNG using a u64 seed. Read more
source§

fn from_rng<R>(rng: R) -> Result<Self, Error>
where R: RngCore,

Create a new PRNG seeded from another Rng. Read more
source§

fn from_entropy() -> Self

Creates a new instance of the RNG seeded via getrandom. Read more
source§

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> 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<CC, BC, Meta> RecvFrameContext<BC, Meta> for CC
where Meta: ReceivableFrameMeta<CC, BC>,

source§

fn receive_frame<B>(&mut self, bindings_ctx: &mut BC, metadata: Meta, frame: B)
where B: BufferMut + Debug,

Receive a frame. Read more
source§

impl<R> Rng for R
where R: RngCore + ?Sized,

source§

fn gen<T>(&mut self) -> T

Return a random value supporting the Standard distribution. Read more
source§

fn gen_range<T, R>(&mut self, range: R) -> T
where T: SampleUniform, R: SampleRange<T>,

Generate a random value in the given range. Read more
source§

fn sample<T, D>(&mut self, distr: D) -> T
where 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,

Create an iterator that generates values using the given distribution. Read more
source§

fn fill<T>(&mut self, dest: &mut T)
where T: Fill + ?Sized,

Fill any type implementing Fill with random data Read more
source§

fn try_fill<T>(&mut self, dest: &mut T) -> Result<(), Error>
where T: Fill + ?Sized,

Fill any type implementing Fill with random data Read more
source§

fn gen_bool(&mut self, p: f64) -> bool

Return a bool with a probability p of being true. Read more
source§

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 more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<CC, BC, Meta> SendFrameContext<BC, Meta> for CC
where Meta: SendableFrameMeta<CC, BC>,

source§

fn send_frame<S>( &mut self, bindings_ctx: &mut BC, metadata: Meta, frame: S ) -> Result<(), S>
where S: Serializer, <S as Serializer>::Buffer: BufferMut,

Send a frame. Read more
source§

impl<Meta, BC> SendableFrameMeta<FakeFrameCtx<Meta>, BC> for Meta

source§

fn send_meta<S>( self, core_ctx: &mut FakeFrameCtx<Meta>, _bindings_ctx: &mut BC, frame: S ) -> Result<(), S>
where S: Serializer, <S as Serializer>::Buffer: BufferMut,

Sends this frame metadata to the provided contexts.
source§

impl<T> Takeable for T
where T: Default,

source§

fn take(&mut self) -> T

Replaces self with an implementor-defined “empty” value.
source§

impl<Id, CC, BC> TimerHandler<BC, Id> for CC
where Id: HandleableTimer<CC, BC>,

source§

fn handle_timer(&mut self, bindings_ctx: &mut BC, id: Id)

Handle a timer firing.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<B, A> LockBefore<B> for A
where B: LockAfter<A>,