summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-09-18 14:23:55 +0200
committerNeal H. Walfield <neal@pep.foundation>2019-09-18 15:22:50 +0200
commit212202e5bec054cc3b2b83edffdd8b83db5bf011 (patch)
treec70a8449148eaf23af1bb6d7ee15fd0aba4a029f /openpgp
parent446dfdbcb63af00daa3a777958419e1dfb6fc737 (diff)
openpgp: Combine Signature4::key_alive and its _at variant.
- Combine Signature4::key_alive and Signature4::key_alive_at. - Use an Into<Option<time::Tm>> to distinguish the two previous cases: the current time (None), and a specific time (a time::Tm).
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/packet/signature/subpacket.rs44
-rw-r--r--openpgp/src/parse/stream.rs4
-rw-r--r--openpgp/src/tpk/keyiter.rs2
-rw-r--r--openpgp/src/tpk/mod.rs4
4 files changed, 21 insertions, 33 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index eda0010a..c1d7dddd 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -1552,35 +1552,23 @@ impl Signature4 {
}
}
- /// Returns whether or not the given key is alive, i.e. the
- /// creation time has passed, but the expiration time has not.
- ///
- /// This function does not check whether the key was revoked.
+ /// Returns whether or not the given key is alive at `t`.
///
- /// See [Section 5.2.3.6 of RFC 4880].
- ///
- /// [Section 5.2.3.6 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.2.3.6
- pub fn key_alive<P, R>(&self, key: &Key<P, R>) -> bool
- where P: key::KeyParts,
- R: key::KeyRole
- {
- self.key_alive_at(key, time::now_utc())
- }
-
- /// Returns whether or not the given key is alive at the given
- /// time, i.e. the creation time has passed, but the expiration
- /// time has not.
+ /// A key is considered to be alive if `creation time <= t` and `t
+ /// <= expiration time`.
///
/// This function does not check whether the key was revoked.
///
/// See [Section 5.2.3.6 of RFC 4880].
///
/// [Section 5.2.3.6 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.2.3.6
- pub fn key_alive_at<P, R>(&self, key: &Key<P, R>, tm: time::Tm) -> bool
+ pub fn key_alive<P, R, T>(&self, key: &Key<P, R>, t: T) -> bool
where P: key::KeyParts,
- R: key::KeyRole
+ R: key::KeyRole,
+ T: Into<Option<time::Tm>>
{
- *key.creation_time() <= tm && ! self.key_expired(key, tm)
+ let t = t.into().unwrap_or_else(time::now_utc);
+ *key.creation_time() <= t && ! self.key_expired(key, t)
}
/// Returns the value of the Preferred Symmetric Algorithms
@@ -2506,10 +2494,10 @@ fn accessors() {
assert!(!sig_.key_expired(&key, now));
assert!(sig_.key_expired(&key, now + ten_minutes));
- assert!(sig_.key_alive(&key));
- assert!(sig_.key_alive_at(&key, now));
- assert!(!sig_.key_alive_at(&key, now - five_minutes));
- assert!(!sig_.key_alive_at(&key, now + ten_minutes));
+ assert!(sig_.key_alive(&key, None));
+ assert!(sig_.key_alive(&key, now));
+ assert!(!sig_.key_alive(&key, now - five_minutes));
+ assert!(!sig_.key_alive(&key, now + ten_minutes));
sig = sig.set_key_expiration_time(None).unwrap();
let sig_ =
@@ -2519,10 +2507,10 @@ fn accessors() {
assert!(!sig_.key_expired(&key, now));
assert!(!sig_.key_expired(&key, now + ten_minutes));
- assert!(sig_.key_alive(&key));
- assert!(sig_.key_alive_at(&key, now));
- assert!(!sig_.key_alive_at(&key, now - five_minutes));
- assert!(sig_.key_alive_at(&key, now + ten_minutes));
+ assert!(sig_.key_alive(&key, None));
+ assert!(sig_.key_alive(&key, now));
+ assert!(!sig_.key_alive(&key, now - five_minutes));
+ assert!(sig_.key_alive(&key, now + ten_minutes));
let pref = vec![SymmetricAlgorithm::AES256,
SymmetricAlgorithm::AES192,
diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs
index 4565db6c..7ab8033d 100644
--- a/openpgp/src/parse/stream.rs
+++ b/openpgp/src/parse/stream.rs
@@ -480,7 +480,7 @@ impl<'a, H: VerificationHelper> Verifier<'a, H> {
sig.key_flags().can_sign()
// Check expiry.
&& sig.signature_alive_at(t)
- && sig.key_alive_at(key, t)
+ && sig.key_alive(key, t)
} else {
false
}
@@ -1299,7 +1299,7 @@ impl<'a, H: VerificationHelper + DecryptionHelper> Decryptor<'a, H> {
sig.key_flags().can_sign()
// Check expiry.
&& sig.signature_alive_at(t)
- && sig.key_alive_at(key, t)
+ && sig.key_alive(key, t)
} else {
false
}
diff --git a/openpgp/src/tpk/keyiter.rs b/openpgp/src/tpk/keyiter.rs
index af9f8eae..98a0b57c 100644
--- a/openpgp/src/tpk/keyiter.rs
+++ b/openpgp/src/tpk/keyiter.rs
@@ -123,7 +123,7 @@ impl<'a, P: 'a + key::KeyParts, R: 'a + key::KeyRole> Iterator
if let Some(alive_at) = self.alive_at {
if let Some(sig) = sigo {
- if ! sig.key_alive_at(key, alive_at) {
+ if ! sig.key_alive(key, alive_at) {
t!("Key not alive... skipping.");
continue;
}
diff --git a/openpgp/src/tpk/mod.rs b/openpgp/src/tpk/mod.rs
index 6396cb6f..dc230513 100644
--- a/openpgp/src/tpk/mod.rs
+++ b/openpgp/src/tpk/mod.rs
@@ -1301,7 +1301,7 @@ impl TPK {
/// Returns whether or not the TPK is alive.
pub fn alive(&self) -> bool {
if let Some(sig) = self.primary_key_signature(None) {
- sig.key_alive(self.primary().key())
+ sig.key_alive(self.primary().key(), None)
} else {
false
}
@@ -1310,7 +1310,7 @@ impl TPK {
/// Returns whether or not the key is alive at the given time.
pub fn alive_at(&self, tm: time::Tm) -> bool {
if let Some(sig) = self.primary_key_signature(tm) {
- sig.key_alive_at(self.primary().key(), tm)
+ sig.key_alive(self.primary().key(), tm)
} else {
false
}