#[timelock]Expand description
Concise attribute macro for deriving a time-locked key inline.
Replaces the decorated fn with a call to timelock (sync) or
timelock_async (async, add the async flag). See
toolkit_zero_macros::timelock for the full argument reference.
§Examples
ⓘ
use toolkit_zero::encryption::timelock::*;
// Encryption — derive for 14:37 with Minute precision.
fn encrypt_key() -> Result<TimeLockKey, TimeLockError> {
let salts = TimeLockSalts::generate();
let kdf = KdfPreset::Balanced.params();
#[timelock(precision = Minute, format = Hour24, time(14, 37), salts = salts, kdf = kdf)]
fn key() {}
Ok(key)
}
// Decryption — re-derive from a stored header.
fn decrypt_key(header: TimeLockParams) -> Result<TimeLockKey, TimeLockError> {
#[timelock(params = header)]
fn key() {}
Ok(key)
}Replace a decorated fn with an inline time-locked key derivation call.
Available when any enc-timelock-* feature is enabled.
Re-exported as toolkit_zero::encryption::timelock::timelock (the macro).
Routes to either timelock (sync) or timelock_async (async — add
the async flag) and builds the positional Option<…> arguments for you.
§Two paths
| Path | When to use | Required args |
|---|---|---|
| Encryption | Generate a key from an explicit time | precision, format, time, salts, kdf |
| Decryption | Re-derive a key from a stored header | params |
§Syntax
// Encryption path
#[timelock(precision = Minute, format = Hour24, time(14, 37), salts = s, kdf = k)]
#[timelock(precision = Minute, format = Hour24, time(14, 37), salts = s, kdf = k,
cadence = DayOfWeek(Tuesday))]
#[timelock(async, precision = Minute, format = Hour24, time(14, 37), salts = s, kdf = k)]
// Decryption path
#[timelock(params = header)]
#[timelock(async, params = header)]§Arguments
| Argument | Type | Notes |
|---|---|---|
async | flag | Use timelock_async().await?; default uses timelock()? |
params = expr | TimeLockParams | Decryption path. Mutually exclusive with all other args |
precision = … | Hour | Quarter | Minute | Encryption path. Time quantisation level |
format = … | Hour12 | Hour24 | Encryption path. Clock representation |
time(h, m) | two int literals | Encryption path. Target time (24-hour h, m) |
cadence = … | variant or None | Optional; defaults to None (TimeLockCadence::None) |
salts = expr | TimeLockSalts | Encryption path. Three 32-byte KDF salts |
kdf = expr | KdfParams | Encryption path. KDF work-factor parameters |
§Cadence variants
cadence = None
cadence = DayOfWeek(Tuesday)
cadence = DayOfMonth(15)
cadence = MonthOfYear(January)
cadence = DayOfWeekInMonth(Tuesday, January)
cadence = DayOfMonthInMonth(15, January)
cadence = DayOfWeekAndDayOfMonth(Tuesday, 15)§What the macro expands to
ⓘ
// Encryption path:
#[timelock(precision = Minute, format = Hour24, time(14, 37), salts = s, kdf = k)]
fn enc_key() {}
// expands to:
// let enc_key = ::toolkit_zero::encryption::timelock::timelock(
// Some(TimeLockCadence::None),
// Some(TimeLockTime::new(14, 37).unwrap()),
// Some(TimePrecision::Minute),
// Some(TimeFormat::Hour24),
// Some(s), Some(k), None,
// )?;
// Decryption path:
#[timelock(params = header)]
fn dec_key() {}
// expands to:
// let dec_key = ::toolkit_zero::encryption::timelock::timelock(
// None, None, None, None, None, None,
// Some(header),
// )?;Full documentation and examples are in the
crate-level #[timelock] section.