pub struct SecretArrayVec<T: SecureSanitize, const CAP: usize> { /* private fields */ }Expand description
Clear-on-drop wrapper around ArrayVec.
Live elements are sanitized before the vector is cleared. Spare uninitialized
storage is not treated as secret material because it has never held a T.
Implementations§
Source§impl<T: SecureSanitize, const CAP: usize> SecretArrayVec<T, CAP>
impl<T: SecureSanitize, const CAP: usize> SecretArrayVec<T, CAP>
Sourcepub const fn from_arrayvec(inner: ArrayVec<T, CAP>) -> Self
pub const fn from_arrayvec(inner: ArrayVec<T, CAP>) -> Self
Wrap an existing ArrayVec.
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 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 all live elements and clear the vector.
Sourcepub fn into_cleared(self)
pub fn into_cleared(self)
Consume after first sanitizing all live elements.