Skip to content

Commit

Permalink
Add a method to expose KeyPackage lifetime.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bren2010 committed Dec 18, 2023
1 parent 5764be7 commit f3b034c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion openmls/src/key_packages/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions openmls/src/key_packages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f3b034c

Please sign in to comment.