pub fn timelock(
cadence: Option<TimeLockCadence>,
time: Option<TimeLockTime>,
precision: Option<TimePrecision>,
format: Option<TimeFormat>,
salts: Option<TimeLockSalts>,
kdf: Option<KdfParams>,
params: Option<TimeLockParams>,
) -> Result<TimeLockKey, TimeLockError>Expand description
Derive a 32-byte time-locked key — unified sync entry point.
§Encryption path (params = None)
Set params to None and supply all of cadence, time, precision,
format, salts, and kdf as Some(...). Requires the
enc-timelock-keygen-input feature. After calling, use pack with the
same arguments to produce a TimeLockParams header for the ciphertext.
§Decryption path (params = Some(p))
Set params to Some(header) where header is the TimeLockParams
read from the ciphertext. All other arguments are ignored and may be
None. Requires the enc-timelock-keygen-now feature.
§Errors
TimeLockError::ForbiddenActionif the required feature is not active, or if the_atpath is taken but any requiredOptionargument isNone.TimeLockError::Argon2/TimeLockError::Scrypton KDF failure.TimeLockError::ClockUnavailableif the OS clock is unusable (_nowpath).
§Example
let salts = TimeLockSalts::generate();
let kdf = KdfPreset::BalancedMac.params();
// Encryption side — lock to every Tuesday at 18:00
let enc_key = timelock(
Some(TimeLockCadence::DayOfWeek(Weekday::Tuesday)),
Some(TimeLockTime::new(18, 0).unwrap()),
Some(TimePrecision::Hour),
Some(TimeFormat::Hour24),
Some(salts.clone()),
Some(kdf),
None,
).unwrap();
// Pack settings + salts + kdf into header; store in ciphertext.
let header = pack(TimePrecision::Hour, TimeFormat::Hour24,
&TimeLockCadence::DayOfWeek(Weekday::Tuesday), salts, kdf);
// Decryption side — call on a Tuesday at 18:xx:
let dec_key = timelock(
None, None, None, None, None, None,
Some(header),
).unwrap();
// enc_key.as_bytes() == dec_key.as_bytes() when called at the right time