Skip to main content

BoundedSecretVec

Struct BoundedSecretVec 

Source
pub struct BoundedSecretVec<const MAX: usize> { /* private fields */ }
Expand description

Heap-allocated secret bytes constrained to a public maximum length.

This additive wrapper is intended for protocol and configuration trust boundaries where unbounded dynamic secret allocation is unacceptable. With the serde feature, every deserialization input form rejects more than MAX bytes. Rejected owned buffers and partially decoded values are cleared before they are released.

Implementations§

Source§

impl<const MAX: usize> BoundedSecretVec<MAX>

Source

pub const fn empty() -> Self

Create an empty bounded secret.

Source

pub fn from_slice(bytes: &[u8]) -> Result<Self, SecretVecLimitError>

Copy a slice into bounded secret storage.

Source

pub fn from_vec(bytes: Vec<u8>) -> Result<Self, SecretVecLimitError>

Take ownership of a vector after validating its length.

An oversized input allocation is volatile-cleared before the error is returned.

Source

pub fn from_secret_vec(secret: SecretVec) -> Result<Self, SecretVecLimitError>

Convert an existing secret vector after validating its length.

An oversized input is cleared before the error is returned.

Source

pub const fn max_len() -> usize

Maximum accepted length.

Source

pub fn len(&self) -> usize

Number of initialized secret bytes.

Source

pub fn is_empty(&self) -> bool

Returns true when no bytes are held.

Source

pub fn with_secret<R>(&self, inspect: impl FnOnce(&[u8]) -> R) -> R

Run a closure with read-only access to the secret bytes.

Source

pub fn with_secret_mut<R>(&mut self, edit: impl FnOnce(&mut [u8]) -> R) -> R

Run a closure with mutable access to the initialized secret bytes.

Source

pub fn extend_from_slice( &mut self, bytes: &[u8], ) -> Result<(), SecretVecLimitError>

Append bytes without permitting the configured limit to be exceeded.

Source

pub fn replace_from_slice( &mut self, bytes: &[u8], ) -> Result<(), SecretVecLimitError>

Replace the current value after validating the replacement length.

Source

pub fn clear_secret(&mut self)

Clear this value immediately with volatile writes.

Source

pub fn into_secret_vec(self) -> SecretVec

Return the bounded value as an ordinary clear-on-drop secret vector.

Trait Implementations§

Source§

impl<const MAX: usize> ConstantTimeEq for BoundedSecretVec<MAX>

Available on crate feature alloc only.
Source§

fn ct_eq(&self, other: &Self) -> Choice

Compare without secret-dependent early exit.
Source§

fn ct_ne(&self, other: &Rhs) -> Choice

Source§

impl<const MAX: usize> ConstantTimeEq for BoundedSecretVec<MAX>

Available on crate feature alloc only.
Source§

fn ct_eq(&self, other: &Self) -> Choice

Determine if two items are equal. Read more
Source§

fn ct_ne(&self, other: &Self) -> Choice

Determine if two items are NOT equal. Read more
Source§

impl<const MAX: usize> Debug for BoundedSecretVec<MAX>

Available on crate feature alloc only.
Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const MAX: usize> Default for BoundedSecretVec<MAX>

Available on crate feature alloc only.
Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, const MAX: usize> Deserialize<'de> for BoundedSecretVec<MAX>

Available on crate feature alloc only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<const MAX: usize> From<BoundedSecretVec<MAX>> for SecretVec

Available on crate feature alloc only.
Source§

fn from(secret: BoundedSecretVec<MAX>) -> Self

Converts to this type from the input type.
Source§

impl<const MAX: usize> SecureSanitize for BoundedSecretVec<MAX>

Available on crate feature alloc only.
Source§

fn secure_sanitize(&mut self)

Clear the sensitive bytes owned by this value.
Source§

impl<const MAX: usize> Serialize for BoundedSecretVec<MAX>

Available on crate feature alloc only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<const MAX: usize> Zeroize for BoundedSecretVec<MAX>

Available on crate feature alloc only.
Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl<const MAX: usize> ZeroizeOnDrop for BoundedSecretVec<MAX>

Available on crate feature alloc only.

Auto Trait Implementations§

§

impl<const MAX: usize> Freeze for BoundedSecretVec<MAX>

§

impl<const MAX: usize> RefUnwindSafe for BoundedSecretVec<MAX>

§

impl<const MAX: usize> Send for BoundedSecretVec<MAX>

§

impl<const MAX: usize> Sync for BoundedSecretVec<MAX>

§

impl<const MAX: usize> Unpin for BoundedSecretVec<MAX>

§

impl<const MAX: usize> UnsafeUnpin for BoundedSecretVec<MAX>

§

impl<const MAX: usize> UnwindSafe for BoundedSecretVec<MAX>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.