diff options
author | Neal H. Walfield <neal@pep.foundation> | 2019-09-18 16:04:18 +0200 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2019-09-18 16:04:18 +0200 |
commit | 044854773282eed2be23aab511d5dc38ffbe21ca (patch) | |
tree | d3affcb154624eab106d06c254128730be868f1b /openpgp | |
parent | c619dffe8562872ad33c501b7f3c3cd9edb7f00b (diff) |
openpgp: Combine Signature4::signature_alive and its _at variant.
- Combine Signature4::signature_alive and
Signature4::signature_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.rs | 45 | ||||
-rw-r--r-- | openpgp/src/parse/stream.rs | 8 | ||||
-rw-r--r-- | openpgp/src/serialize/tpk_armored.rs | 2 | ||||
-rw-r--r-- | openpgp/src/tpk/mod.rs | 8 |
4 files changed, 28 insertions, 35 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index dda69e2a..ab3a81a5 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -1350,24 +1350,14 @@ impl Signature4 { } } - /// Returns whether or not the signature is alive, i.e. the - /// creation time has passed, but the expiration time has not. + /// Returns whether or not the signature is alive at the given + /// time. /// - /// Note that [Section 5.2.3.4 of RFC 4880] states that "[[A - /// Signature Creation Time subpacket]] MUST be present in the - /// hashed area." Consequently, if such a packet does not exist, - /// but a "Signature Expiration Time" subpacket exists, we - /// conservatively treat the signature as expired, because there - /// is no way to evaluate the expiration time. + /// A signature is considered to be alive if `creation time <= t` + /// and `t <= expiration time`. + /// + /// If `t` is None, uses the current time. /// - /// [Section 5.2.3.4 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.2.3.4 - pub fn signature_alive(&self) -> bool { - self.signature_alive_at(time::now_utc()) - } - - /// Returns whether or not the signature is alive at the given - /// time, i.e. the creation time has passed, but the expiration - /// time has not. /// /// Note that [Section 5.2.3.4 of RFC 4880] states that "[[A /// Signature Creation Time subpacket]] MUST be present in the @@ -1377,9 +1367,12 @@ impl Signature4 { /// is no way to evaluate the expiration time. /// /// [Section 5.2.3.4 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.2.3.4 - pub fn signature_alive_at(&self, tm: time::Tm) -> bool { + pub fn signature_alive<T>(&self, t: T) -> bool + where T: Into<Option<time::Tm>> + { + let t = t.into().unwrap_or_else(time::now_utc); if let Some(creation_time) = self.signature_creation_time() { - creation_time <= tm && ! self.signature_expired(tm) + creation_time <= t && ! self.signature_expired(t) } else { false } @@ -2429,10 +2422,10 @@ fn accessors() { assert!(!sig_.signature_expired(now)); assert!(sig_.signature_expired(now + ten_minutes)); - assert!(sig_.signature_alive()); - assert!(sig_.signature_alive_at(now)); - assert!(!sig_.signature_alive_at(now - five_minutes)); - assert!(!sig_.signature_alive_at(now + ten_minutes)); + assert!(sig_.signature_alive(None)); + assert!(sig_.signature_alive(now)); + assert!(!sig_.signature_alive(now - five_minutes)); + assert!(!sig_.signature_alive(now + ten_minutes)); sig = sig.set_signature_expiration_time(None).unwrap(); let sig_ = @@ -2442,10 +2435,10 @@ fn accessors() { assert!(!sig_.signature_expired(now)); assert!(!sig_.signature_expired(now + ten_minutes)); - assert!(sig_.signature_alive()); - assert!(sig_.signature_alive_at(now)); - assert!(!sig_.signature_alive_at(now - five_minutes)); - assert!(sig_.signature_alive_at(now + ten_minutes)); + assert!(sig_.signature_alive(None)); + assert!(sig_.signature_alive(now)); + assert!(!sig_.signature_alive(now - five_minutes)); + assert!(sig_.signature_alive(now + ten_minutes)); sig = sig.set_exportable_certification(true).unwrap(); let sig_ = diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index 7ab8033d..6a1246af 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -479,7 +479,7 @@ impl<'a, H: VerificationHelper> Verifier<'a, H> { if let Some(sig) = sig { sig.key_flags().can_sign() // Check expiry. - && sig.signature_alive_at(t) + && sig.signature_alive(t) && sig.key_alive(key, t) } else { false @@ -627,7 +627,7 @@ impl<'a, H: VerificationHelper> Verifier<'a, H> { = tpk.keys_all().nth(*j) .unwrap(); if sig.verify(key).unwrap_or(false) - && sig.signature_alive_at(self.time) + && sig.signature_alive(self.time) { VerificationResult::GoodChecksum (sig, tpk, key, binding, @@ -1298,7 +1298,7 @@ impl<'a, H: VerificationHelper + DecryptionHelper> Decryptor<'a, H> { if let Some(sig) = sig { sig.key_flags().can_sign() // Check expiry. - && sig.signature_alive_at(t) + && sig.signature_alive(t) && sig.key_alive(key, t) } else { false @@ -1445,7 +1445,7 @@ impl<'a, H: VerificationHelper + DecryptionHelper> Decryptor<'a, H> { let (binding, revocation, key) = tpk.keys_all().nth(*j).unwrap(); if sig.verify(key).unwrap_or(false) && - sig.signature_alive_at(self.time) + sig.signature_alive(self.time) { // Check intended recipients. if let Some(identity) = diff --git a/openpgp/src/serialize/tpk_armored.rs b/openpgp/src/serialize/tpk_armored.rs index 7ab2405b..8c4c3253 100644 --- a/openpgp/src/serialize/tpk_armored.rs +++ b/openpgp/src/serialize/tpk_armored.rs @@ -39,7 +39,7 @@ impl TPK { } // Ignore userids not "alive". }).filter_map(|uidb| { - if uidb.binding_signature(None)?.signature_alive() { + if uidb.binding_signature(None)?.signature_alive(None) { Some(uidb) } else { None diff --git a/openpgp/src/tpk/mod.rs b/openpgp/src/tpk/mod.rs index 7fa91956..8f01ab24 100644 --- a/openpgp/src/tpk/mod.rs +++ b/openpgp/src/tpk/mod.rs @@ -153,7 +153,7 @@ impl<C> ComponentBinding<C> { let time_zero = time::at_utc(time::Timespec::new(0, 0)); self.selfsigs.iter().filter(|s| { - s.signature_alive_at(t) + s.signature_alive(t) }).max_by(|a, b| { a.signature_creation_time().unwrap_or(time_zero).cmp( &b.signature_creation_time().unwrap_or(time_zero)) @@ -219,7 +219,7 @@ impl<C> ComponentBinding<C> { selfsig_creation_time.rfc822(), t.rfc822()); if let Some(selfsig) = selfsig { - assert!(selfsig.signature_alive_at(t)); + assert!(selfsig.signature_alive(t)); } macro_rules! check { @@ -249,7 +249,7 @@ impl<C> ComponentBinding<C> { rev.signature_creation_time() .unwrap_or_else(time_zero).rfc822()); None - } else if !rev.signature_alive_at(t) { + } else if !rev.signature_alive(t) { t!(" ignoring revocation that is not alive ({} - {})", rev.signature_creation_time() .unwrap_or_else(time_zero).rfc822(), @@ -1062,7 +1062,7 @@ impl TPK { // No binding signature at time `t` => not alive. let selfsig = b.binding_signature(t)?; - if !selfsig.signature_alive_at(t) { + if !selfsig.signature_alive(t) { return None; } |