From f3b034c0ba0934a21619ee99b0d0db1ed3d8ae06 Mon Sep 17 00:00:00 2001 From: Brendan McMillion Date: Mon, 18 Dec 2023 07:59:28 -0800 Subject: [PATCH] Add a method to expose KeyPackage lifetime. --- openmls/src/key_packages/lifetime.rs | 12 +++++++++++- openmls/src/key_packages/mod.rs | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/openmls/src/key_packages/lifetime.rs b/openmls/src/key_packages/lifetime.rs index 9da1f46573..ac27a010da 100644 --- a/openmls/src/key_packages/lifetime.rs +++ b/openmls/src/key_packages/lifetime.rs @@ -61,7 +61,7 @@ impl Lifetime { } /// Returns true if this lifetime is valid. - pub(crate) fn is_valid(&self) -> bool { + pub fn is_valid(&self) -> bool { match SystemTime::now() .duration_since(UNIX_EPOCH) .map(|duration| duration.as_secs()) @@ -80,6 +80,16 @@ impl Lifetime { pub fn has_acceptable_range(&self) -> bool { self.not_after.saturating_sub(self.not_before) <= MAX_LEAF_NODE_LIFETIME_RANGE_SECONDS } + + /// Returns the "not before" timestamp of the KeyPackage. + pub fn not_before(&self) -> u64 { + self.not_before + } + + /// Returns the "not after" timestamp of the KeyPackage. + pub fn not_after(&self) -> u64 { + self.not_after + } } impl Default for Lifetime { diff --git a/openmls/src/key_packages/mod.rs b/openmls/src/key_packages/mod.rs index 3df6073074..4dcaa02597 100644 --- a/openmls/src/key_packages/mod.rs +++ b/openmls/src/key_packages/mod.rs @@ -381,6 +381,11 @@ impl KeyPackage { pub fn last_resort(&self) -> bool { self.payload.extensions.contains(ExtensionType::LastResort) } + + /// Get the lifetime of the KeyPackage + pub fn life_time(&self) -> &Lifetime { + self.payload.leaf_node.life_time().unwrap() + } } /// Crate visible `KeyPackage` functions.