diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-11-20 19:02:34 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-11-21 16:25:30 +0100 |
commit | b251f9e8857fba284f515061ac62013519997e30 (patch) | |
tree | 8cb3501b8cb32e43496e56dd76446ba7559c7eed /openpgp | |
parent | 13c437470cc7377d7b761b5bb9b8d4efb0ba385e (diff) |
openpgp: Replace time crate with std::time.
- In sq and sqv, use chrono to interface with the user.
- Fixes #341.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/Cargo.toml | 1 | ||||
-rw-r--r-- | openpgp/src/conversions.rs | 41 | ||||
-rw-r--r-- | openpgp/src/lib.rs | 6 | ||||
-rw-r--r-- | openpgp/src/packet/key/mod.rs | 75 | ||||
-rw-r--r-- | openpgp/src/packet/literal.rs | 20 | ||||
-rw-r--r-- | openpgp/src/packet/pkesk.rs | 3 | ||||
-rw-r--r-- | openpgp/src/packet/signature/mod.rs | 14 | ||||
-rw-r--r-- | openpgp/src/packet/signature/subpacket.rs | 102 | ||||
-rw-r--r-- | openpgp/src/parse/parse.rs | 13 | ||||
-rw-r--r-- | openpgp/src/parse/stream.rs | 62 | ||||
-rw-r--r-- | openpgp/src/serialize/stream.rs | 7 | ||||
-rw-r--r-- | openpgp/src/serialize/tpk_armored.rs | 2 | ||||
-rw-r--r-- | openpgp/src/tpk/bindings.rs | 33 | ||||
-rw-r--r-- | openpgp/src/tpk/builder.rs | 14 | ||||
-rw-r--r-- | openpgp/src/tpk/keyiter.rs | 11 | ||||
-rw-r--r-- | openpgp/src/tpk/mod.rs | 143 | ||||
-rw-r--r-- | openpgp/src/tpk/revoke.rs | 22 |
17 files changed, 316 insertions, 253 deletions
diff --git a/openpgp/Cargo.toml b/openpgp/Cargo.toml index 1cb26f49..020a9bc9 100644 --- a/openpgp/Cargo.toml +++ b/openpgp/Cargo.toml @@ -35,7 +35,6 @@ nettle = "5.0.2" quickcheck = { version = "0.9", default-features = false } rand = { version = "0.7", default-features = false } regex = "1.3.1" -time = "0.1.40" [build-dependencies] lalrpop = "0.17" diff --git a/openpgp/src/conversions.rs b/openpgp/src/conversions.rs index a53dc524..30157bce 100644 --- a/openpgp/src/conversions.rs +++ b/openpgp/src/conversions.rs @@ -1,6 +1,5 @@ //! Conversions for primitive OpenPGP types. -use time; use crate::Error; use crate::Result; @@ -16,24 +15,28 @@ pub trait Time { fn canonicalize(self) -> Self; } -impl Time for time::Tm { +impl Time for std::time::SystemTime { fn from_pgp(timestamp: u32) -> Self { - time::at_utc(time::Timespec::new(timestamp as i64, 0)) + std::time::UNIX_EPOCH + std::time::Duration::new(timestamp as u64, 0) } fn to_pgp(&self) -> Result<u32> { - let epoch = self.to_timespec().sec; - if epoch > ::std::u32::MAX as i64 { - return Err(Error::InvalidArgument( + match self.duration_since(std::time::UNIX_EPOCH) { + Ok(d) if d.as_secs() <= std::u32::MAX as u64 => + Ok(d.as_secs() as u32), + _ => Err(Error::InvalidArgument( format!("Time exceeds u32 epoch: {:?}", self)) - .into()); + .into()), } - Ok(epoch as u32) } - fn canonicalize(mut self) -> Self { - self.tm_nsec = 0; - self.to_utc() + fn canonicalize(self) -> Self { + match self.duration_since(std::time::UNIX_EPOCH) { + Ok(d) if d.as_secs() <= std::u32::MAX as u64 => + Self::from_pgp(d.as_secs() as u32), + _ => + Self::from_pgp(0), // XXX + } } } @@ -47,23 +50,23 @@ pub trait Duration { fn canonicalize(self) -> Self; } -impl Duration for time::Duration { +impl Duration for std::time::Duration { fn from_pgp(duration: u32) -> Self { - time::Duration::seconds(duration as i64) + std::time::Duration::new(duration as u64, 0) } fn to_pgp(&self) -> Result<u32> { - let secs = self.num_seconds(); - if secs > ::std::u32::MAX as i64 { - return Err(Error::InvalidArgument( + if self.as_secs() <= std::u32::MAX as u64 { + Ok(self.as_secs() as u32) + } else { + Err(Error::InvalidArgument( format!("Duration exceeds u32: {:?}", self)) - .into()); + .into()) } - Ok(secs as u32) } fn canonicalize(self) -> Self { - time::Duration::seconds(self.num_seconds()) + std::time::Duration::new(self.as_secs(), 0) } } diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs index 1dede3d9..a4c54f6e 100644 --- a/openpgp/src/lib.rs +++ b/openpgp/src/lib.rs @@ -64,8 +64,6 @@ extern crate quickcheck; extern crate rand; -extern crate time; - #[macro_use] extern crate lazy_static; extern crate idna; @@ -156,9 +154,9 @@ mod tests; /// The time is chosen to that the subkeys in /// openpgp/tests/data/keys/neal.pgp are not expired. #[cfg(test)] -fn frozen_time() -> time::Tm { +fn frozen_time() -> std::time::SystemTime { use crate::conversions::Time; - time::Tm::from_pgp(1554542220 - 1) + std::time::SystemTime::from_pgp(1554542220 - 1) } /// Crate result specialization. diff --git a/openpgp/src/packet/key/mod.rs b/openpgp/src/packet/key/mod.rs index 5cea7423..b6337ce0 100644 --- a/openpgp/src/packet/key/mod.rs +++ b/openpgp/src/packet/key/mod.rs @@ -52,7 +52,7 @@ use std::fmt; use std::cmp::Ordering; -use time; +use std::time; use crate::Error; use crate::crypto::{self, mem::{self, Protected}, mpis, hash::Hash}; @@ -515,7 +515,7 @@ pub struct Key4<P, R> /// CTB packet header fields. pub(crate) common: packet::Common, /// When the key was created. - creation_time: time::Tm, + creation_time: time::SystemTime, /// Public key algorithm of this signature. pk_algo: PublicKeyAlgorithm, /// Public key MPIs. @@ -535,7 +535,7 @@ impl<P, R> fmt::Debug for Key4<P, R> fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Key4") .field("fingerprint", &self.fingerprint()) - .field("creation_time", &format!("{}", self.creation_time.rfc3339())) + .field("creation_time", &self.creation_time) .field("pk_algo", &self.pk_algo) .field("mpis", &self.mpis) .field("secret", &self.secret) @@ -582,13 +582,14 @@ impl<P, R> Key4<P, R> R: key::KeyRole, { /// Creates a new OpenPGP key packet. - pub fn new(creation_time: time::Tm, pk_algo: PublicKeyAlgorithm, - mpis: mpis::PublicKey, secret: Option<SecretKeyMaterial>) - -> Result<Self> + pub fn new<T>(creation_time: T, pk_algo: PublicKeyAlgorithm, + mpis: mpis::PublicKey, secret: Option<SecretKeyMaterial>) + -> Result<Self> + where T: Into<time::SystemTime> { Ok(Key4 { common: Default::default(), - creation_time: creation_time, + creation_time: creation_time.into(), pk_algo: pk_algo, mpis: mpis, secret: secret, @@ -607,14 +608,15 @@ impl<P, R> Key4<P, R> hash: H, sym: S, ctime: T) -> Result<Self> where H: Into<Option<HashAlgorithm>>, S: Into<Option<SymmetricAlgorithm>>, - T: Into<Option<time::Tm>> + T: Into<Option<time::SystemTime>> { let mut point = Vec::from(public_key); point.insert(0, 0x40); Ok(Key4 { common: Default::default(), - creation_time: ctime.into().unwrap_or(time::now()), + creation_time: ctime.into() + .unwrap_or_else(|| time::SystemTime::now().canonicalize()), pk_algo: PublicKeyAlgorithm::ECDH, mpis: mpis::PublicKey::ECDH{ curve: Curve::Cv25519, @@ -638,7 +640,7 @@ impl<P, R> Key4<P, R> hash: H, sym: S, ctime: T) -> Result<Self> where H: Into<Option<HashAlgorithm>>, S: Into<Option<SymmetricAlgorithm>>, - T: Into<Option<time::Tm>> + T: Into<Option<time::SystemTime>> { use nettle::curve25519::{self, CURVE25519_SIZE}; @@ -650,7 +652,8 @@ impl<P, R> Key4<P, R> Ok(Key4 { common: Default::default(), - creation_time: ctime.into().unwrap_or(time::now()), + creation_time: ctime.into() + .unwrap_or_else(|| time::SystemTime::now().canonicalize()), pk_algo: PublicKeyAlgorithm::ECDH, mpis: mpis::PublicKey::ECDH{ curve: Curve::Cv25519, @@ -673,14 +676,15 @@ impl<P, R> Key4<P, R> /// will be used. The key will have it's creation date set to /// `ctime` or the current time if `None` is given. pub fn import_public_ed25519<T>(public_key: &[u8], ctime: T) -> Result<Self> - where T: Into<Option<time::Tm>> + where T: Into<Option<time::SystemTime>> { let mut point = Vec::from(public_key); point.insert(0, 0x40); Ok(Key4 { common: Default::default(), - creation_time: ctime.into().unwrap_or(time::now()), + creation_time: ctime.into() + .unwrap_or_else(|| time::SystemTime::now().canonicalize()), pk_algo: PublicKeyAlgorithm::EdDSA, mpis: mpis::PublicKey::EdDSA{ curve: Curve::Ed25519, @@ -699,7 +703,7 @@ impl<P, R> Key4<P, R> /// will be used. The key will have it's creation date set to /// `ctime` or the current time if `None` is given. pub fn import_secret_ed25519<T>(private_key: &[u8], ctime: T) - -> Result<Self> where T: Into<Option<time::Tm>> + -> Result<Self> where T: Into<Option<time::SystemTime>> { use nettle::ed25519::{self, ED25519_KEY_SIZE}; @@ -708,7 +712,8 @@ impl<P, R> Key4<P, R> Ok(Key4 { common: Default::default(), - creation_time: ctime.into().unwrap_or(time::now()), + creation_time: ctime.into() + .unwrap_or_else(|| time::SystemTime::now().canonicalize()), pk_algo: PublicKeyAlgorithm::EdDSA, mpis: mpis::PublicKey::EdDSA{ curve: Curve::Ed25519, @@ -728,11 +733,12 @@ impl<P, R> Key4<P, R> /// have it's creation date set to `ctime` or the current time if `None` /// is given. pub fn import_public_rsa<T>(e: &[u8], n: &[u8], ctime: T) - -> Result<Self> where T: Into<Option<time::Tm>> + -> Result<Self> where T: Into<Option<time::SystemTime>> { Ok(Key4 { common: Default::default(), - creation_time: ctime.into().unwrap_or(time::now()), + creation_time: ctime.into() + .unwrap_or_else(|| time::SystemTime::now().canonicalize()), pk_algo: PublicKeyAlgorithm::RSAEncryptSign, mpis: mpis::PublicKey::RSA { e: mpis::MPI::new(e), @@ -750,7 +756,7 @@ impl<P, R> Key4<P, R> /// have it's creation date set to `ctime` or the current time if `None` /// is given. pub fn import_secret_rsa<T>(d: &[u8], p: &[u8], q: &[u8], ctime: T) - -> Result<Self> where T: Into<Option<time::Tm>> + -> Result<Self> where T: Into<Option<time::SystemTime>> { use nettle::rsa; @@ -760,7 +766,8 @@ impl<P, R> Key4<P, R> Ok(Key4 { common: Default::default(), - creation_time: ctime.into().unwrap_or(time::now()), + creation_time: ctime.into() + .unwrap_or_else(|| time::SystemTime::now().canonicalize()), pk_algo: PublicKeyAlgorithm::RSAEncryptSign, mpis: mpis::PublicKey::RSA { e: mpis::MPI::new(&key.e()[..]), @@ -799,7 +806,7 @@ impl<P, R> Key4<P, R> Ok(Key4 { common: Default::default(), - creation_time: time::now().canonicalize(), + creation_time: time::SystemTime::now().canonicalize(), pk_algo: PublicKeyAlgorithm::RSAEncryptSign, mpis: public_mpis, secret: sec, @@ -954,7 +961,7 @@ impl<P, R> Key4<P, R> Ok(Key4 { common: Default::default(), - creation_time: time::now().canonicalize(), + creation_time: time::SystemTime::now().canonicalize(), pk_algo: pk_algo, mpis: mpis, secret: secret, @@ -964,12 +971,13 @@ impl<P, R> Key4<P, R> } /// Gets the key packet's creation time field. - pub fn creation_time(&self) -> &time::Tm { - &self.creation_time + pub fn creation_time(&self) -> time::SystemTime { + self.creation_time } /// Sets the key packet's creation time field. - pub fn set_creation_time(&mut self, timestamp: time::Tm) -> time::Tm { + pub fn set_creation_time(&mut self, timestamp: time::SystemTime) + -> time::SystemTime { ::std::mem::replace(&mut self.creation_time, timestamp.canonicalize()) } @@ -1408,10 +1416,10 @@ mod tests { fn import_cv25519() { use crate::crypto::{ecdh, mem, SessionKey}; use self::mpis::{MPI, Ciphertext}; - use time::{at, Timespec}; // X25519 key - let ctime = at(Timespec::new(0x5c487129,0)); + let ctime = + time::UNIX_EPOCH + time::Duration::new(0x5c487129, 0); let public = b"\xed\x59\x0a\x15\x08\x95\xe9\x92\xd2\x2c\x14\x01\xb3\xe9\x3b\x7f\xff\xe6\x6f\x22\x65\xec\x69\xd9\xb8\xda\x24\x2c\x64\x84\x44\x11"; let key : key::SecretKey = Key4::import_public_cv25519(&public[..], @@ -1443,10 +1451,10 @@ mod tests { fn import_cv25519_sec() { use crate::crypto::ecdh; use self::mpis::{MPI, Ciphertext}; - use time::{at, Timespec}; // X25519 key - let ctime = at(Timespec::new(0x5c487129,0)); + let ctime = + time::UNIX_EPOCH + time::Duration::new(0x5c487129, 0); let public = b"\xed\x59\x0a\x15\x08\x95\xe9\x92\xd2\x2c\x14\x01\xb3\xe9\x3b\x7f\xff\xe6\x6f\x22\x65\xec\x69\xd9\xb8\xda\x24\x2c\x64\x84\x44\x11"; let secret = b"\xa0\x27\x13\x99\xc9\xe3\x2e\xd2\x47\xf6\xd6\x63\x9d\xe6\xec\xcb\x57\x0b\x92\xbb\x17\xfe\xb8\xf1\xc4\x1f\x06\x7c\x55\xfc\xdd\x58"; let key: key::PublicKey @@ -1484,10 +1492,10 @@ mod tests { fn import_rsa() { use crate::crypto::SessionKey; use self::mpis::{MPI, Ciphertext}; - use time::{at, Timespec}; // RSA key - let ctime = at(Timespec::new(1548950502,0)); + let ctime = + time::UNIX_EPOCH + time::Duration::new(1548950502, 0); let d = b"\x14\xC4\x3A\x0C\x3A\x79\xA4\xF7\x63\x0D\x89\x93\x63\x8B\x56\x9C\x29\x2E\xCD\xCF\xBF\xB0\xEC\x66\x52\xC3\x70\x1B\x19\x21\x73\xDE\x8B\xAC\x0E\xF2\xE1\x28\x42\x66\x56\x55\x00\x3B\xFD\x50\xC4\x7C\xBC\x9D\xEB\x7D\xF4\x81\xFC\xC3\xBF\xF7\xFF\xD0\x41\x3E\x50\x3B\x5F\x5D\x5F\x56\x67\x5E\x00\xCE\xA4\x53\xB8\x59\xA0\x40\xC8\x96\x6D\x12\x09\x27\xBE\x1D\xF1\xC2\x68\xFC\xF0\x14\xD6\x52\x77\x07\xC8\x12\x36\x9C\x9A\x5C\xAF\x43\xCC\x95\x20\xBB\x0A\x44\x94\xDD\xB4\x4F\x45\x4E\x3A\x1A\x30\x0D\x66\x40\xAC\x68\xE8\xB0\xFD\xCD\x6C\x6B\x6C\xB5\xF7\xE4\x36\x95\xC2\x96\x98\xFD\xCA\x39\x6C\x1A\x2E\x55\xAD\xB6\xE0\xF8\x2C\xFF\xBC\xD3\x32\x15\x52\x39\xB3\x92\x35\xDB\x8B\x68\xAF\x2D\x4A\x6E\x64\xB8\x28\x63\xC4\x24\x94\x2D\xA9\xDB\x93\x56\xE3\xBC\xD0\xB6\x38\x84\x04\xA4\xC6\x18\x48\xFE\xB2\xF8\xE1\x60\x37\x52\x96\x41\xA5\x79\xF6\x3D\xB7\x2A\x71\x5B\x7A\x75\xBF\x7F\xA2\x5A\xC8\xA1\x38\xF2\x5A\xBD\x14\xFC\xAF\xB4\x54\x83\xA4\xBD\x49\xA2\x8B\x91\xB0\xE0\x4A\x1B\x21\x54\x07\x19\x70\x64\x7C\x3E\x9F\x8D\x8B\xE4\x70\xD1\xE7\xBE\x4E\x5C\xCE\xF1"; let p = b"\xC8\x32\xD1\x17\x41\x4D\x8F\x37\x09\x18\x32\x4C\x4C\xF4\xA2\x15\x27\x43\x3D\xBB\xB5\xF6\x1F\xCF\xD2\xE4\x43\x61\x07\x0E\x9E\x35\x1F\x0A\x5D\xFB\x3A\x45\x74\x61\x73\x73\x7B\x5F\x1F\x87\xFB\x54\x8D\xA8\x85\x3E\xB0\xB7\xC7\xF5\xC9\x13\x99\x8D\x40\xE6\xA6\xD0\x71\x3A\xE3\x2D\x4A\xC3\xA3\xFF\xF7\x72\x82\x14\x52\xA4\xBA\x63\x0E\x17\xCA\xCA\x18\xC4\x3A\x40\x79\xF1\x86\xB3\x10\x4B\x9F\xB2\xAE\x2E\x13\x38\x8D\x2C\xF9\x88\x4C\x25\x53\xEF\xF9\xD1\x8B\x1A\x7C\xE7\xF6\x4B\x73\x51\x31\xFA\x44\x1D\x36\x65\x71\xDA\xFC\x6F"; let q = b"\xCC\x30\xE9\xCC\xCB\x31\x28\xB5\x90\xFF\x06\x62\x42\x5B\x24\x0E\x00\xFE\xE2\x37\xC4\xAC\xBB\x3B\x8F\xF2\x0E\x3F\x78\xCF\x6B\x7C\xE8\x75\x57\x7C\x15\x9D\x1A\x66\xF2\x0A\xE5\xD3\x0B\xE7\x40\xF7\xE7\x00\xB6\x86\xB5\xD9\x20\x67\xE0\x4A\xC0\x90\xA4\x13\x4D\xC9\xB0\x12\xC5\xCD\x4C\xEB\xA1\x91\x2D\x43\x58\x6E\xB6\x75\xA0\x93\xF0\x5B\xC5\x31\xCA\xB7\xC6\x22\x0C\xD3\xEC\x84\xC5\x91\xA1\x5F\x2C\x8E\x07\x5D\xA1\x98\x67\xC5\x7A\x58\x16\x71\x3D\xED\x91\x03\x0D\xD4\x25\x07\x89\x9B\x33\x98\xA3\x70\xD9\xE7\xC8\x17\xA3\xD9"; @@ -1516,7 +1524,6 @@ mod tests { #[test] fn import_ed25519() { - use time::{at, Timespec}; use crate::{Fingerprint, KeyID}; use crate::constants::SignatureType; use crate::packet::signature::Signature4; @@ -1524,7 +1531,8 @@ mod tests { Subpacket, SubpacketValue, SubpacketArea}; // Ed25519 key - let ctime = at(Timespec::new(1548249630,0)); + let ctime = + time::UNIX_EPOCH + time::Duration::new(1548249630, 0); let q = b"\x57\x15\x45\x1B\x68\xA5\x13\xA2\x20\x0F\x71\x9D\xE3\x05\x3B\xED\xA2\x21\xDE\x61\x5A\xF5\x67\x45\xBB\x97\x99\x43\x53\x59\x7C\x3F"; let key: key::PublicKey = Key4::import_public_ed25519(q, ctime).unwrap().into(); @@ -1533,7 +1541,8 @@ mod tests { let mut unhashed = SubpacketArea::empty(); let fpr = Fingerprint::from_hex("D81A 5DC0 DEBF EE5F 9AC8 20EB 6769 5DB9 920D 4FAC").unwrap(); let kid = KeyID::from_hex("6769 5DB9 920D 4FAC").unwrap(); - let ctime = at(Timespec::new(1549460479,0)); + let ctime = + time::UNIX_EPOCH + time::Duration::new(1549460479, 0); let r = b"\x5A\xF9\xC7\x42\x70\x24\x73\xFF\x7F\x27\xF9\x20\x9D\x20\x0F\xE3\x8F\x71\x3C\x5F\x97\xFD\x60\x80\x39\x29\xC2\x14\xFD\xC2\x4D\x70"; let s = b"\x6E\x68\x74\x11\x72\xF4\x9C\xE1\x99\x99\x1F\x67\xFC\x3A\x68\x33\xF9\x3F\x3A\xB9\x1A\xA5\x72\x4E\x78\xD4\x81\xCB\x7B\xA5\xE5\x0A"; diff --git a/openpgp/src/packet/literal.rs b/openpgp/src/packet/literal.rs index 590e2554..be21c337 100644 --- a/openpgp/src/packet/literal.rs +++ b/openpgp/src/packet/literal.rs @@ -1,6 +1,6 @@ use std::fmt; use std::cmp; -use time; +use std::time; use quickcheck::{Arbitrary, Gen}; use crate::constants::DataFormat; @@ -35,7 +35,7 @@ pub struct Literal { filename: Option<Vec<u8>>, /// A four-octet number that indicates a date associated with the /// literal data. - date: time::Tm, + date: time::SystemTime, // XXX Should be Option<SystemTime> } impl fmt::Debug for Literal { @@ -76,7 +76,7 @@ impl Literal { common: Default::default(), format: format, filename: None, - date: time::Tm::from_pgp(0), + date: time::SystemTime::from_pgp(0), } } @@ -147,11 +147,11 @@ impl Literal { /// Note: when a literal data packet is protected by a signature, /// only the literal data packet's body is protected, not the /// meta-data. As such, this field should normally be ignored. - pub fn date(&self) -> Option<&time::Tm> { + pub fn date(&self) -> Option<time::SystemTime> { if self.date.to_pgp().unwrap_or(0) == 0 { None } else { - Some(&self.date) + Some(self.date) } } @@ -160,13 +160,14 @@ impl Literal { /// Note: when a literal data packet is protected by a signature, /// only the literal data packet's body is protected, not the /// meta-data. As such, this field should not be used. - pub fn set_date(&mut self, timestamp: Option<time::Tm>) -> Option<time::Tm> + pub fn set_date(&mut self, timestamp: Option<time::SystemTime>) + -> Option<time::SystemTime> { let old = ::std::mem::replace( &mut self.date, timestamp.map(|t| t.canonicalize()) - .unwrap_or(time::Tm::from_pgp(0))); - if old == time::Tm::from_pgp(0) { + .unwrap_or(time::SystemTime::from_pgp(0))); + if old == time::SystemTime::from_pgp(0) { None } else { Some(old) @@ -187,7 +188,8 @@ impl Arbitrary for Literal { while let Err(_) = l.set_filename_from_bytes(&Vec::<u8>::arbitrary(g)) { // Too long, try again. } - l.set_date(Option::<u32>::arbitrary(g).map(|t| time::Tm::from_pgp(t))); + l.set_date(Option::<u32>::arbitrary(g) + .map(|t| time::SystemTime::from_pgp(t))); l } } diff --git a/openpgp/src/packet/pkesk.rs b/openpgp/src/packet/pkesk.rs index 3b3897a0..b2e9a0f4 100644 --- a/openpgp/src/packet/pkesk.rs +++ b/openpgp/src/packet/pkesk.rs @@ -340,7 +340,6 @@ mod tests { use crate::packet::key; use crate::packet::key::Key4; use nettle::curve25519; - use time; // 20 byte sec key let mut sec = [ @@ -363,7 +362,7 @@ mod tests { scalar: MPI::new(&sec[..]).into(), }; let mut key: key::UnspecifiedPublic - = Key4::new(time::now().canonicalize(), + = Key4::new(std::time::SystemTime::now().canonicalize(), PublicKeyAlgorithm::ECDH, public_mpis, None) .unwrap().into(); diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs index fb1a1224..ab7762b9 100644 --- a/openpgp/src/packet/signature/mod.rs +++ b/openpgp/src/packet/signature/mod.rs @@ -1097,6 +1097,7 @@ impl From<Signature4> for super::Signature { #[cfg(test)] mod test { use super::*; + use crate::conversions::Time; use crate::crypto; use crate::crypto::mpis::MPI; use crate::TPK; @@ -1284,7 +1285,6 @@ mod test { #[test] fn sign_message() { - use time; use crate::constants::Curve; let key: Key<key::SecretParts, key::PrimaryRole> @@ -1293,7 +1293,8 @@ mod test { let msg = b"Hello, World"; let mut pair = key.into_keypair().unwrap(); let sig = Builder::new(SignatureType::Binary) - .set_signature_creation_time(time::now()).unwrap() + .set_signature_creation_time( + std::time::SystemTime::now().canonicalize()).unwrap() .set_issuer_fingerprint(pair.public().fingerprint()).unwrap() .set_issuer(pair.public().keyid()).unwrap() .sign_message(&mut pair, msg).unwrap(); @@ -1322,7 +1323,6 @@ mod test { fn sign_with_short_ed25519_secret_key() { use crate::conversions::Time; use nettle; - use time; // 20 byte sec key let sec = [ @@ -1342,7 +1342,7 @@ mod test { scalar: MPI::new(&sec[..]).into(), }; let key : key::SecretKey - = Key4::new(time::now().canonicalize(), + = Key4::new(std::time::SystemTime::now().canonicalize(), PublicKeyAlgorithm::EdDSA, public_mpis, Some(private_mpis.into())) .unwrap() @@ -1441,7 +1441,8 @@ mod test { let mut pair = key.into_keypair().unwrap(); let sig = Builder::new(SignatureType::Standalone) - .set_signature_creation_time(time::now()).unwrap() + .set_signature_creation_time( + std::time::SystemTime::now().canonicalize()).unwrap() .set_issuer_fingerprint(pair.public().fingerprint()).unwrap() .set_issuer(pair.public().keyid()).unwrap() .sign_standalone(&mut pair) @@ -1472,7 +1473,8 @@ mod test { let mut pair = key.into_keypair().unwrap(); let sig = Builder::new(SignatureType::Timestamp) - .set_signature_creation_time(time::now()).unwrap() + .set_signature_creation_time( + std::time::SystemTime::now().canonicalize()).unwrap() .set_issuer_fingerprint(pair.public().fingerprint()).unwrap() .set_issuer(pair.public().keyid()).unwrap() .sign_timestamp(&mut pair) diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs index 219251f3..b801eb6c 100644 --- a/openpgp/src/packet/signature/subpacket.rs +++ b/openpgp/src/packet/signature/subpacket.rs @@ -63,7 +63,7 @@ use std::ops::{Deref, DerefMut}; use std::fmt; use std::io; use std::cmp; -use time; +use std::time; use quickcheck::{Arbitrary, Gen}; @@ -127,7 +127,7 @@ lazy_static!{ /// If te is close to t1, then t1 may be considered valid, which /// is probably not what you want. pub static ref CLOCK_SKEW_TOLERANCE: time::Duration - = time::Duration::seconds(30 * 60); + = time::Duration::new(30 * 60, 0); } /// The subpacket types specified by [Section 5.2.3.1 of RFC 4880]. @@ -702,7 +702,7 @@ pub enum SubpacketValue<'a> { Invalid(&'a [u8]), /// 4-octet time field - SignatureCreationTime(time::Tm), + SignatureCreationTime(time::SystemTime), /// 4-octet time field SignatureExpirationTime(time::Duration), /// 1 octet of exportability, 0 for not, 1 for exportable @@ -992,7 +992,8 @@ impl<'a> From<SubpacketRaw<'a>> for Subpacket<'a> { SubpacketTag::SignatureCreationTime => // The timestamp is in big endian format. from_be_u32(raw.value).map(|v| { - SubpacketValue |