Skip to main content

RedoubtZero

Derive Macro RedoubtZero 

Source
#[derive(RedoubtZero)]
{
    // Attributes available to this derive:
    #[fast_zeroize]
}
Expand description

Derives FastZeroizable, ZeroizeMetadata, ZeroizationProbe, and optionally AssertZeroizeOnDrop for a struct.

This macro automatically generates trait implementations for structs.

§Requirements

  • All fields must implement FastZeroizable (except fields with #[fast_zeroize(skip)])

§Optional Sentinel Field

  • Named structs can include a field named __sentinel: ZeroizeOnDropSentinel
  • Tuple structs can include a field of type ZeroizeOnDropSentinel
  • If present, AssertZeroizeOnDrop will be implemented for testing drop behavior

§Attributes

  • #[fast_zeroize(drop)]: Also generates a Drop implementation that calls fast_zeroize()
  • #[fast_zeroize(skip)]: Skip a field from zeroization (e.g., immutable references)

§Generated Implementations

Always generated:

  • FastZeroizable: Zeroizes all fields (except skipped)
  • ZeroizeMetadata: Sets CAN_BE_BULK_ZEROIZED = false
  • ZeroizationProbe: Checks if all fields are zeroized (except skipped and sentinel)

If ZeroizeOnDropSentinel field is present:

  • AssertZeroizeOnDrop: Provides test helpers for verifying zeroization on drop

With #[fast_zeroize(drop)]:

  • Drop: Calls fast_zeroize() on drop

§Examples

§Without automatic Drop

use redoubt_zero_derive::RedoubtZero;
use redoubt_zero_core::{ZeroizeOnDropSentinel, FastZeroizable};

#[derive(RedoubtZero)]
struct ApiKey {
    key: Vec<u8>,
    __sentinel: ZeroizeOnDropSentinel,
}

impl Drop for ApiKey {
    fn drop(&mut self) {
        self.fast_zeroize();
    }
}

§With automatic Drop

use redoubt_zero_derive::RedoubtZero;
use redoubt_zero_core::{ZeroizeOnDropSentinel, FastZeroizable};

#[derive(RedoubtZero)]
#[fast_zeroize(drop)]
struct ApiKey {
    key: Vec<u8>,
    __sentinel: ZeroizeOnDropSentinel,
}
// Drop is automatically generated