CloneableArray

Type Alias CloneableArray 

Source
pub type CloneableArray<const N: usize> = Fixed<CloneableArrayInner<N>>;
Expand description

A fixed-size array of bytes wrapped as a cloneable secret.

This type provides a secure wrapper around a [u8; N] array that can be safely cloned while ensuring the underlying data is properly zeroized when no longer needed. Use this for cryptographic keys, nonces, or other fixed-size secret data.

§Examples

use secure_gate::{CloneableArray, ExposeSecret};

// Create from an array
let key: CloneableArray<32> = [42u8; 32].into();

// Access the inner array
let inner = &key.expose_secret().0;
assert_eq!(inner.len(), 32);

Aliased Type§

pub struct CloneableArray<const N: usize>(/* private fields */);

Implementations§

Source§

impl<const N: usize> CloneableArray<N>

Source

pub fn init_with<F>(constructor: F) -> Self
where F: FnOnce() -> [u8; N],

Construct a cloneable array secret by building it in a closure.

Same stack-minimization benefits as CloneableString::init_with.

§Example
use secure_gate::CloneableArray;

let key = CloneableArray::<32>::init_with(|| {
    let mut arr = [0u8; 32];
    // Fill from some source...
    arr
});
Source

pub fn try_init_with<F, E>(constructor: F) -> Result<Self, E>
where F: FnOnce() -> Result<[u8; N], E>,

Fallible version of init_with.

Same stack-minimization benefits as init_with, but allows for construction that may fail with an error. Useful when reading secrets from fallible sources like files or network connections.

Trait Implementations§

Source§

impl<const N: usize> From<[u8; N]> for CloneableArray<N>

Source§

fn from(arr: [u8; N]) -> Self

Wrap a [u8; N] array in a CloneableArray.