openpgp: Add getter for absolute expiration times in Amalgamation.

  - See #429.
parent 40807c9e
...@@ -348,6 +348,19 @@ pub trait Amalgamation<'a> { ...@@ -348,6 +348,19 @@ pub trait Amalgamation<'a> {
self.map(|s| s.key_validity_period()) self.map(|s| s.key_validity_period())
} }
/// Returns the key's expiration time as of the amalgamtion's
/// reference time.
///
/// If this function returns `None`, the key does not expire.
///
/// Considers both the binding signature and the direct key
/// signature. Information in the binding signature takes
/// precedence over the direct key signature. See also [Section
/// 5.2.3.3 of RFC 4880].
///
/// [Section 5.2.3.3 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.2.3.3
fn key_expiration_time(&self) -> Option<time::SystemTime>;
/// Returns the value of the Revocation Key subpacket, which /// Returns the value of the Revocation Key subpacket, which
/// contains a designated revoker. /// contains a designated revoker.
/// ///
...@@ -419,6 +432,25 @@ impl<'a, C> Amalgamation<'a> for ValidComponentAmalgamation<'a, C> { ...@@ -419,6 +432,25 @@ impl<'a, C> Amalgamation<'a> for ValidComponentAmalgamation<'a, C> {
self.bundle._revoked(self.policy(), self.time, self.bundle._revoked(self.policy(), self.time,
false, Some(self.binding_signature)) false, Some(self.binding_signature))
} }
/// Returns the key's expiration time as of the amalgamtion's
/// reference time.
///
/// If this function returns `None`, the key does not expire.
///
/// Considers both the binding signature and the direct key
/// signature. Information in the binding signature takes
/// precedence over the direct key signature. See also [Section
/// 5.2.3.3 of RFC 4880].
///
/// [Section 5.2.3.3 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.2.3.3
fn key_expiration_time(&self) -> Option<time::SystemTime> {
let key = self.cert().primary_key().key();
match self.key_validity_period() {
Some(vp) if vp.as_secs() > 0 => Some(key.creation_time() + vp),
_ => None,
}
}
} }
impl<'a, C> crate::cert::Preferences<'a> impl<'a, C> crate::cert::Preferences<'a>
......
...@@ -416,6 +416,24 @@ impl<'a, P: 'a + key::KeyParts> Amalgamation<'a> for ValidKeyAmalgamation<'a, P> ...@@ -416,6 +416,24 @@ impl<'a, P: 'a + key::KeyParts> Amalgamation<'a> for ValidKeyAmalgamation<'a, P>
bundle.revoked(self.policy, self.time()), bundle.revoked(self.policy, self.time()),
} }
} }
/// Returns the key's expiration time as of the amalgamtion's
/// reference time.
///
/// If this function returns `None`, the key does not expire.
///
/// Considers both the binding signature and the direct key
/// signature. Information in the binding signature takes
/// precedence over the direct key signature. See also [Section
/// 5.2.3.3 of RFC 4880].
///
/// [Section 5.2.3.3 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.2.3.3
fn key_expiration_time(&self) -> Option<time::SystemTime> {
match self.key_validity_period() {
Some(vp) if vp.as_secs() > 0 => Some(self.creation_time() + vp),
_ => None,
}
}
} }
impl<'a, P: 'a + key::KeyParts> ValidKeyAmalgamation<'a, P> { impl<'a, P: 'a + key::KeyParts> ValidKeyAmalgamation<'a, P> {
...@@ -603,6 +621,23 @@ impl<'a, P: 'a + key::KeyParts> Amalgamation<'a> ...@@ -603,6 +621,23 @@ impl<'a, P: 'a + key::KeyParts> Amalgamation<'a>
fn revoked(&self) -> RevocationStatus<'a> { fn revoked(&self) -> RevocationStatus<'a> {
self.a.revoked() self.a.revoked()
} }
/// Returns the key's expiration time as of the amalgamtion's
/// reference time.
///
/// Considers both the binding signature and the direct key
/// signature. Information in the binding signature takes
/// precedence over the direct key signature. See also [Section
/// 5.2.3.3 of RFC 4880].
///
/// [Section 5.2.3.3 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.2.3.3
fn key_expiration_time(&self) -> Option<time::SystemTime> {
let key = self.cert().primary_key().key();
match self.key_validity_period() {
Some(vp) if vp.as_secs() > 0 => Some(key.creation_time() + vp),
_ => None,
}
}
} }
impl<'a, P: key::KeyParts> crate::cert::Preferences<'a> impl<'a, P: key::KeyParts> crate::cert::Preferences<'a>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment