diff options
author | Neal H. Walfield <neal@pep.foundation> | 2020-04-26 17:36:51 +0200 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2020-04-26 17:43:36 +0200 |
commit | f4e5d2a2bd131f667c1bb532d7b35cea349c11d5 (patch) | |
tree | 62a7f7906ae6bebecd3b63133db1e71b0866cd4e | |
parent | 79bd0050384927a38a152fb90d16df6de12611a0 (diff) |
openpgp: Add a reference time to Cert::set_expiration_time.
- Don't assume that the current binding signature should be used;
include a reference time.
-rw-r--r-- | openpgp-ffi/src/cert.rs | 2 | ||||
-rw-r--r-- | openpgp/src/cert/mod.rs | 12 |
2 files changed, 7 insertions, 7 deletions
diff --git a/openpgp-ffi/src/cert.rs b/openpgp-ffi/src/cert.rs index 31872d90..d51d29ad 100644 --- a/openpgp-ffi/src/cert.rs +++ b/openpgp-ffi/src/cert.rs @@ -347,7 +347,7 @@ fn pgp_cert_set_expiration_time(errp: Option<&mut *mut crate::error::Error>, let cert = cert.move_from_raw(); let signer = ffi_param_ref_mut!(primary_signer); - cert.set_expiration_time(policy, signer.as_mut(), + cert.set_expiration_time(policy, None, signer.as_mut(), maybe_time(expiry)) .move_into_raw(errp) } diff --git a/openpgp/src/cert/mod.rs b/openpgp/src/cert/mod.rs index d8330cb2..8c9b7ed9 100644 --- a/openpgp/src/cert/mod.rs +++ b/openpgp/src/cert/mod.rs @@ -963,20 +963,20 @@ impl Cert { /// // Make cert expire now. /// let mut keypair = cert.primary_key() /// .key().clone().parts_into_secret()?.into_keypair()?; - /// let cert = cert.set_expiration_time(p, &mut keypair, + /// let cert = cert.set_expiration_time(p, None, &mut keypair, /// Some(time::SystemTime::now()))?; /// /// assert!(cert.with_policy(p, None)?.alive().is_err()); /// # Ok(()) /// # } /// ``` - pub fn set_expiration_time(self, policy: &dyn Policy, - primary_signer: &mut dyn Signer, - expiration: Option<time::SystemTime>) + pub fn set_expiration_time<T>(self, policy: &dyn Policy, t: T, + primary_signer: &mut dyn Signer, + expiration: Option<time::SystemTime>) -> Result<Cert> + where T: Into<Option<time::SystemTime>>, { - let now = time::SystemTime::now(); - let primary = self.primary_key().with_policy(policy, now)?; + let primary = self.primary_key().with_policy(policy, t.into())?; let sigs = primary.set_expiration_time(primary_signer, expiration)?; self.merge_packets(sigs) |