FastZeroize

Trait FastZeroize 

Source
pub trait FastZeroize: ZeroizeMetadata + FastZeroizable { }
Expand description

Combined trait for types with both zeroization metadata and runtime zeroization.

This is the main trait users should implement. It combines:

§Usage

Most types should use #[derive(RedoubtZero)] which implements this automatically. Manual implementation is only needed for custom types with special zeroization requirements.

§CAN_BE_BULK_ZEROIZED Constant

§CAN_BE_BULK_ZEROIZED = true (Fast Path)

All-zeros is a valid bit pattern. Enables:

  • Fast vectorized memset operations (ptr::write_bytes)
  • ~20x performance improvement over byte-by-byte writes
  • Safe for: primitives (u8-u128, i8-i128, bool, char, floats)

§CAN_BE_BULK_ZEROIZED = false (Slow Path)

Requires element-by-element zeroization because:

  • Type contains pointers, references, or heap allocations
  • All-zeros may not be a valid representation
  • Needs recursive calls on each field

§Example

use redoubt_zero_core::FastZeroize;

// Primitive: bulk zeroization
impl FastZeroize for u32 {
    const CAN_BE_BULK_ZEROIZED: bool = true;

    fn fast_zeroize(&mut self) {
        redoubt_util::zeroize_primitive(self);
    }
}

// Complex type: element-by-element
struct ApiKey {
    secret: Vec<u8>,
}

impl FastZeroize for ApiKey {
    const CAN_BE_BULK_ZEROIZED: bool = false;

    fn fast_zeroize(&mut self) {
        self.secret.fast_zeroize();
    }
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§