Struct ExternalRng

Source
pub struct ExternalRng {
    pub rng_bytes: [u8; 32],
    pub len: usize,
}
Expand description

ExternalRng has all features But use external random source

Fields§

§rng_bytes: [u8; 32]

bytes to receive external rng when init

§len: usize

lenght of RNG

Implementations§

Source§

impl ExternalRng

Source

pub fn copy_into_array<A, T>(slice: &[T]) -> A
where A: Default + AsMut<[T]>, T: Copy,

for no std env if want to convert slice to array

§Inputs
  • ‘slice’ is a slice from raw part
§returns
  • array from slice
§Examples
use rand_core::{CryptoRng,RngCore};
use exrng::ExternalRng;
fn main(){
use core::slice;
let rng_bytes:[u8;32] = [1u8;32];
let random_ptr: *const u8 = rng_bytes.as_ptr();
let r:&[u8] = unsafe {slice::from_raw_parts(random_ptr, 32)};
let mut rng = ExternalRng {rng_bytes:ExternalRng::copy_into_array(r),len:32};
let mut zero = [0u8; 32];
rng.fill_bytes(&mut zero);
assert_eq!([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], &zero[..]);
}

Trait Implementations§

Source§

impl Clone for ExternalRng

Source§

fn clone(&self) -> ExternalRng

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 Debug for ExternalRng

Source§

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

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

impl RngCore for ExternalRng

implement Trait RngCore for EnternalRng foucus on fill_bytes

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 CryptoRng for ExternalRng

implement Trait CryptoRng for EnternalRng empty implement

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, 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.