Skip to main content

timelock

Attribute Macro timelock 

Source
#[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

PathWhen to useRequired args
EncryptionGenerate a key from an explicit timeprecision, format, time, salts, kdf
DecryptionRe-derive a key from a stored headerparams

§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

ArgumentTypeNotes
asyncflagUse timelock_async().await?; default uses timelock()?
params = exprTimeLockParamsDecryption path. Mutually exclusive with all other args
precision = …Hour | Quarter | MinuteEncryption path. Time quantisation level
format = …Hour12 | Hour24Encryption path. Clock representation
time(h, m)two int literalsEncryption path. Target time (24-hour h, m)
cadence = …variant or NoneOptional; defaults to None (TimeLockCadence::None)
salts = exprTimeLockSaltsEncryption path. Three 32-byte KDF salts
kdf = exprKdfParamsEncryption 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.