pub struct SecretArrayVec<T: SecureSanitize, const CAP: usize> { /* private fields */ }Expand description
Clear-on-drop wrapper around ArrayVec.
Live elements are sanitized and dropped before the complete resulting
MaybeUninit<T> spare region is volatile-cleared. This covers inline bytes
left by earlier push, pop, truncate, clear, reuse, or wrapping operations
without raw-zeroing a live T.
Implementations§
Source§impl<T: SecureSanitize, const CAP: usize> SecretArrayVec<T, CAP>
impl<T: SecureSanitize, const CAP: usize> SecretArrayVec<T, CAP>
Sourcepub fn from_arrayvec(inner: ArrayVec<T, CAP>) -> Self
pub fn from_arrayvec(inner: ArrayVec<T, CAP>) -> Self
Wrap an existing ArrayVec.
Historical bytes in the incoming vector’s current spare capacity are cleared immediately. Live elements remain unchanged.
Sourcepub fn push(&mut self, value: T) -> Result<(), CapacityError<T>>
pub fn push(&mut self, value: T) -> Result<(), CapacityError<T>>
Push one sanitizable element.
If the vector is full, CapacityError returns the original element
unchanged, matching arrayvec semantics. Callers remain responsible for
sanitizing or securely reusing that rejected value. Use
SecretArrayVec::push_or_sanitize when rejection must consume and
clear the element instead.
Sourcepub fn push_or_sanitize(
&mut self,
value: T,
) -> Result<(), SanitizedCapacityError>
pub fn push_or_sanitize( &mut self, value: T, ) -> Result<(), SanitizedCapacityError>
Push an element, consuming and sanitizing it if the vector is full.
The error intentionally carries no T, preventing callers from
mistaking a sanitized value for the original secret.
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Remove and return the last element.
The returned value remains secret-bearing and is the caller’s responsibility. The stale inline slot left by the move is volatile-cleared before this method returns.
Sourcepub fn truncate(&mut self, new_len: usize)
pub fn truncate(&mut self, new_len: usize)
Shorten the vector to new_len.
Removed elements are sanitized before their destructors run. The complete spare region, including historical bytes from earlier operations, is then volatile-cleared.
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Mutably borrow initialized elements.
Sourcepub fn with_secret<R>(&self, inspect: impl FnOnce(&[T]) -> R) -> R
pub fn with_secret<R>(&self, inspect: impl FnOnce(&[T]) -> R) -> R
Run a closure with read-only access to initialized elements.
Sourcepub fn with_secret_mut<R>(&mut self, edit: impl FnOnce(&mut [T]) -> R) -> R
pub fn with_secret_mut<R>(&mut self, edit: impl FnOnce(&mut [T]) -> R) -> R
Run a closure with mutable access to initialized elements.
Sourcepub fn clear_secret(&mut self)
pub fn clear_secret(&mut self)
Sanitize and drop all live elements, then clear all inline backing bytes.
Sourcepub fn into_cleared(self)
pub fn into_cleared(self)
Consume after first sanitizing all live elements.