pub struct DynamicRng(/* private fields */);Expand description
Heap-allocated cryptographically secure random bytes.
This is a newtype over Dynamic<Vec<u8>> for semantic clarity.
Like FixedRng, guarantees freshness via RNG construction.
Requires the “rand” feature.
§Examples
use secure_gate::random::DynamicRng;
let random = DynamicRng::generate(64);
assert_eq!(random.len(), 64);Implementations§
Source§impl DynamicRng
impl DynamicRng
Sourcepub fn generate(len: usize) -> Self
pub fn generate(len: usize) -> Self
Generate fresh random bytes of the specified length.
Panics if the RNG fails.
§Example
use secure_gate::random::DynamicRng;
let random = DynamicRng::generate(128);Sourcepub fn try_generate(len: usize) -> Result<Self, OsError>
pub fn try_generate(len: usize) -> Result<Self, OsError>
Try to generate fresh random bytes of the specified length.
Returns an error if the RNG fails.
§Example
use secure_gate::random::DynamicRng;
let random: Result<DynamicRng, rand::rand_core::OsError> = DynamicRng::try_generate(64);
assert!(random.is_ok());Sourcepub fn expose_secret(&self) -> &[u8] ⓘ
pub fn expose_secret(&self) -> &[u8] ⓘ
Expose the random bytes for read-only access.
Sourcepub fn into_inner(self) -> Dynamic<Vec<u8>>
pub fn into_inner(self) -> Dynamic<Vec<u8>>
Consume and return the inner Dynamic<Vec<u8>>.
Trait Implementations§
Source§impl Debug for DynamicRng
impl Debug for DynamicRng
Source§impl From<DynamicRng> for Dynamic<Vec<u8>>
impl From<DynamicRng> for Dynamic<Vec<u8>>
Source§fn from(rng: DynamicRng) -> Self
fn from(rng: DynamicRng) -> Self
Convert a DynamicRng to Dynamic, transferring ownership.
This preserves all security guarantees. The DynamicRng type
ensures the value came from secure RNG, and this conversion
transfers that value to Dynamic without exposing bytes.
§Example
use secure_gate::{Dynamic, random::DynamicRng};
let random: Dynamic<Vec<u8>> = DynamicRng::generate(64).into();Auto Trait Implementations§
impl Freeze for DynamicRng
impl RefUnwindSafe for DynamicRng
impl Send for DynamicRng
impl Sync for DynamicRng
impl Unpin for DynamicRng
impl UnwindSafe for DynamicRng
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