#[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,
AssertZeroizeOnDropwill be implemented for testing drop behavior
§Attributes
#[fast_zeroize(drop)]: Also generates aDropimplementation that callsfast_zeroize()#[fast_zeroize(skip)]: Skip a field from zeroization (e.g., immutable references)
§Generated Implementations
Always generated:
FastZeroizable: Zeroizes all fields (except skipped)ZeroizeMetadata: SetsCAN_BE_BULK_ZEROIZED = falseZeroizationProbe: 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: Callsfast_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