Skip to content

Commit

Permalink
Merge pull request #6 from Bren2010/brendan/lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
neekolas authored Dec 18, 2023
2 parents 5764be7 + f3b034c commit 2f50273
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 2f50273

Please sign in to comment.