Struct memsecurity::CsprngArray
source · pub struct CsprngArray<const N: usize>(/* private fields */);
Expand description
Implementations§
source§impl<const N: usize> CsprngArray<N>
impl<const N: usize> CsprngArray<N>
sourcepub fn gen() -> Self
pub fn gen() -> Self
Method to generate random cryptographically secure random bytes
Example
let bytes = CsprngArray::<64>::gen(); // Generates 64 random bytes
assert_eq!(bytes.len(), 64);
sourcepub fn take(self, buffer: &mut [u8; N]) -> MemSecurityResult<()>
pub fn take(self, buffer: &mut [u8; N]) -> MemSecurityResult<()>
Copies the contents of the buffer
sourcepub fn take_zeroize_on_error(
self,
buffer: &mut [u8; N]
) -> MemSecurityResult<()>
pub fn take_zeroize_on_error( self, buffer: &mut [u8; N] ) -> MemSecurityResult<()>
Copies the contents of the buffer
sourcepub fn expose(&self) -> [u8; N]
pub fn expose(&self) -> [u8; N]
Clone the data. Be careful with this as it retains the secret in memory.
It is recommended to call Csprng::zeroize()
after consuming this in order to zeroize the memory
sourcepub fn expose_borrowed(&self) -> &[u8] ⓘ
pub fn expose_borrowed(&self) -> &[u8] ⓘ
Clone the data. Be careful with this as it retains the secret in memory.
It is recommended to call Csprng::zeroize()
after consuming this in order to zeroize the memory
sourcepub fn dangerous_debug(&self) -> &[u8; N]
pub fn dangerous_debug(&self) -> &[u8; N]
Get the inner value of the struct. This is only available in a debug build and
is enforced by the flag #[cfg(debug_assertions)]
Trait Implementations§
source§impl<const N: usize> BorshDeserialize for CsprngArray<N>
impl<const N: usize> BorshDeserialize for CsprngArray<N>
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self, Error>
source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Deserializes this instance from a given slice of bytes.
Updates the buffer to point at the remaining bytes.
source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
source§impl<const N: usize> BorshSerialize for CsprngArray<N>
impl<const N: usize> BorshSerialize for CsprngArray<N>
source§impl<const N: usize> Debug for CsprngArray<N>
impl<const N: usize> Debug for CsprngArray<N>
source§impl<const N: usize> Display for CsprngArray<N>
impl<const N: usize> Display for CsprngArray<N>
source§impl<const N: usize> Drop for CsprngArray<N>
impl<const N: usize> Drop for CsprngArray<N>
Auto Trait Implementations§
impl<const N: usize> RefUnwindSafe for CsprngArray<N>
impl<const N: usize> Send for CsprngArray<N>
impl<const N: usize> Sync for CsprngArray<N>
impl<const N: usize> Unpin for CsprngArray<N>
impl<const N: usize> UnwindSafe for CsprngArray<N>
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