diff options
author | Igor Matuszewski <igor@sequoia-pgp.org> | 2020-04-07 15:29:59 +0200 |
---|---|---|
committer | Igor Matuszewski <xanewok@gmail.com> | 2020-04-07 15:26:40 +0000 |
commit | 5a85ee090d6626456771c7505e407a894b9e3267 (patch) | |
tree | e0091a01e98da2862284cc51b89bcd5f86158ab1 /openpgp/src | |
parent | 803c8b7bfad326711893aff39ddd15605f6e3e11 (diff) |
openpgp: Simplify some default time unwrapping
Diffstat (limited to 'openpgp/src')
-rw-r--r-- | openpgp/src/cert/bundle.rs | 5 | ||||
-rw-r--r-- | openpgp/src/cert/revoke.rs | 2 | ||||
-rw-r--r-- | openpgp/src/packet/key.rs | 18 | ||||
-rw-r--r-- | openpgp/src/packet/signature/subpacket.rs | 3 | ||||
-rw-r--r-- | openpgp/src/parse/stream.rs | 3 |
5 files changed, 11 insertions, 20 deletions
diff --git a/openpgp/src/cert/bundle.rs b/openpgp/src/cert/bundle.rs index 4bbe9e4f..11ebb28c 100644 --- a/openpgp/src/cert/bundle.rs +++ b/openpgp/src/cert/bundle.rs @@ -105,7 +105,7 @@ impl<C> ComponentBundle<C> { -> Result<&Signature> where T: Into<Option<time::SystemTime>> { - let t = t.into().unwrap_or_else(|| time::SystemTime::now()); + let t = t.into().unwrap_or_else(time::SystemTime::now); // Recall: the signatures are sorted by their creation time in // descending order, i.e., newest first. @@ -247,8 +247,7 @@ impl<C> ComponentBundle<C> { { // Fallback time. let time_zero = || time::UNIX_EPOCH; - let t = t.into() - .unwrap_or_else(|| time::SystemTime::now()); + let t = t.into().unwrap_or_else(time::SystemTime::now); let selfsig_creation_time = selfsig.and_then(|s| s.signature_creation_time()) .unwrap_or_else(time_zero); diff --git a/openpgp/src/cert/revoke.rs b/openpgp/src/cert/revoke.rs index 7970bc6d..f5e3a627 100644 --- a/openpgp/src/cert/revoke.rs +++ b/openpgp/src/cert/revoke.rs @@ -114,7 +114,7 @@ impl CertRevocationBuilder { let creation_time = self.signature_creation_time() - .unwrap_or_else(|| time::SystemTime::now()); + .unwrap_or_else(time::SystemTime::now); self.builder // If not set, set it to now. diff --git a/openpgp/src/packet/key.rs b/openpgp/src/packet/key.rs index 500e899e..5fb91aea 100644 --- a/openpgp/src/packet/key.rs +++ b/openpgp/src/packet/key.rs @@ -948,8 +948,7 @@ impl<R> Key4<key::PublicParts, R> point.insert(0, 0x40); Self::new( - ctime.into() - .unwrap_or_else(|| time::SystemTime::now()), + ctime.into().unwrap_or_else(time::SystemTime::now), PublicKeyAlgorithm::ECDH, mpis::PublicKey::ECDH { curve: Curve::Cv25519, @@ -972,8 +971,7 @@ impl<R> Key4<key::PublicParts, R> point.insert(0, 0x40); Self::new( - ctime.into() - .unwrap_or_else(|| time::SystemTime::now()), + ctime.into().unwrap_or_else(time::SystemTime::now), PublicKeyAlgorithm::EdDSA, mpis::PublicKey::EdDSA { curve: Curve::Ed25519, @@ -990,8 +988,7 @@ impl<R> Key4<key::PublicParts, R> -> Result<Self> where T: Into<Option<time::SystemTime>> { Self::new( - ctime.into() - .unwrap_or_else(|| time::SystemTime::now()), + ctime.into().unwrap_or_else(time::SystemTime::now), PublicKeyAlgorithm::RSAEncryptSign, mpis::PublicKey::RSA { e: mpis::MPI::new(e), @@ -1042,8 +1039,7 @@ impl<R> Key4<SecretParts, R> private_key.reverse(); Self::with_secret( - ctime.into() - .unwrap_or_else(|| time::SystemTime::now()), + ctime.into().unwrap_or_else(time::SystemTime::now), PublicKeyAlgorithm::ECDH, mpis::PublicKey::ECDH { curve: Curve::Cv25519, @@ -1071,8 +1067,7 @@ impl<R> Key4<SecretParts, R> ed25519::public_key(&mut public_key[1..], private_key).unwrap(); Self::with_secret( - ctime.into() - .unwrap_or_else(|| time::SystemTime::now()), + ctime.into().unwrap_or_else(time::SystemTime::now), PublicKeyAlgorithm::EdDSA, mpis::PublicKey::EdDSA { curve: Curve::Ed25519, @@ -1098,8 +1093,7 @@ impl<R> Key4<SecretParts, R> let (a, b, c) = sec.as_rfc4880(); Self::with_secret( - ctime.into() - .unwrap_or_else(|| time::SystemTime::now()), + ctime.into().unwrap_or_else(time::SystemTime::now), PublicKeyAlgorithm::RSAEncryptSign, mpis::PublicKey::RSA { e: mpis::MPI::new(&key.e()[..]), diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index 4bcfc0f3..2e7294cd 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -1862,8 +1862,7 @@ impl SubpacketAreas { R: key::KeyRole, T: Into<Option<time::SystemTime>> { - let t = t.into() - .unwrap_or_else(|| time::SystemTime::now()); + let t = t.into().unwrap_or_else(time::SystemTime::now); match self.key_validity_period() { Some(e) if e.as_secs() > 0 && key.creation_time() + e <= t => diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index 5ed3cae8..81e73094 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -1068,8 +1068,7 @@ impl<'a, H: VerificationHelper + DecryptionHelper> Decryptor<'a, H> { .map(|_| time::Duration::new(0, 0)) .unwrap_or( *crate::packet::signature::subpacket::CLOCK_SKEW_TOLERANCE); - let time = time - .unwrap_or_else(|| time::SystemTime::now()); + let time = time.unwrap_or_else(time::SystemTime::now); let mut ppr = PacketParserBuilder::from_buffered_reader(bio)? .map(helper.mapping()).finalize()?; |