CloneableVec

Type Alias CloneableVec 

Source
pub type CloneableVec = Dynamic<CloneableVecInner>;
Expand description

A dynamically-sized vector of bytes wrapped as a cloneable secret.

This type provides a secure wrapper around a Vec<u8> that can be safely cloned while ensuring the underlying data is properly zeroized when no longer needed. Use this for variable-length secret data like encrypted payloads or keys.

§Examples

use secure_gate::CloneableVec;

// Create from a vector
let data: CloneableVec = vec![1, 2, 3, 4].into();

// Create from a slice
let data2: CloneableVec = b"hello world".as_slice().into();

// Access the inner vector
let inner = data.expose_inner();
assert_eq!(inner.len(), 4);

Aliased Type§

pub struct CloneableVec(/* private fields */);

Implementations§

Source§

impl CloneableVec

Source

pub const fn expose_inner(&self) -> &Vec<u8>

Returns a reference to the inner vector without cloning.

This method provides direct access to the wrapped Vec<u8>. The reference is valid for the lifetime of the CloneableVec.

Source

pub fn expose_inner_mut(&mut self) -> &mut Vec<u8>

Returns a mutable reference to the inner vector.

This method provides direct mutable access to the wrapped Vec<u8>. Use this when you need to modify the vector contents in-place.

Source

pub fn init_with<F>(constructor: F) -> Self
where F: FnOnce() -> Vec<u8>,

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

Same stack-minimization benefits as CloneableString::init_with.

§Example
use secure_gate::CloneableVec;

let seed = CloneableVec::init_with(|| {
    let mut v = vec![0u8; 32];
    // Fill from some source...
    v
});
Source

pub fn try_init_with<F, E>(constructor: F) -> Result<Self, E>
where F: FnOnce() -> Result<Vec<u8>, 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 From<&[u8]> for CloneableVec

Wrap a byte slice in a CloneableVec.

Source§

fn from(value: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for CloneableVec

Wrap a Vec<u8> in a CloneableVec.

Source§

fn from(value: Vec<u8>) -> Self

Converts to this type from the input type.