diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-12-09 12:32:35 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-12-09 13:28:28 +0100 |
commit | 88f43e115383c89fb83714e5dd6fbd2f9df16047 (patch) | |
tree | 865b76d3e02ac77b69b80eeac321f0105e1ff3a4 | |
parent | fe8093bc1aef8c6a79fd1dc76f5cc857eae05d50 (diff) |
openpgp: Return result from Cert::alive, remove Cert::expired.
- See #371.
-rw-r--r-- | openpgp-ffi/include/sequoia/openpgp.h | 9 | ||||
-rw-r--r-- | openpgp-ffi/src/cert.rs | 15 | ||||
-rw-r--r-- | openpgp/src/cert/mod.rs | 18 |
3 files changed, 8 insertions, 34 deletions
diff --git a/openpgp-ffi/include/sequoia/openpgp.h b/openpgp-ffi/include/sequoia/openpgp.h index b93ebb05..a5e4b603 100644 --- a/openpgp-ffi/include/sequoia/openpgp.h +++ b/openpgp-ffi/include/sequoia/openpgp.h @@ -894,18 +894,11 @@ pgp_cert_t pgp_cert_revoke_in_place (pgp_error_t *errp, const char *reason); /*/ -/// Returns whether the Cert has expired. -/// -/// If `when` is 0, then the current time is used. -/*/ -int pgp_cert_expired(pgp_cert_t cert, time_t at); - -/*/ /// Returns whether the Cert is alive at the specified time. /// /// If `when` is 0, then the current time is used. /*/ -int pgp_cert_alive(pgp_cert_t cert, time_t when); +pgp_status_t pgp_cert_alive(pgp_error_t *errp, pgp_cert_t cert, time_t when); /*/ /// Changes the Cert's expiration. diff --git a/openpgp-ffi/src/cert.rs b/openpgp-ffi/src/cert.rs index 00e7b3b4..c85be4f6 100644 --- a/openpgp-ffi/src/cert.rs +++ b/openpgp-ffi/src/cert.rs @@ -315,21 +315,14 @@ fn pgp_cert_revoke_in_place(errp: Option<&mut *mut crate::error::Error>, cert.revoke_in_place(signer.as_mut(), code, reason).move_into_raw(errp) } -/// Returns whether the Cert has expired. -/// -/// If `when` is 0, then the current time is used. -#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C" -fn pgp_cert_expired(cert: *const Cert, when: time_t) -> c_int { - cert.ref_raw().expired(maybe_time(when)) as c_int -} - /// Returns whether the Cert is alive at the specified time. /// /// If `when` is 0, then the current time is used. #[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C" -fn pgp_cert_alive(cert: *const Cert, when: time_t) - -> c_int { - cert.ref_raw().alive(maybe_time(when)) as c_int +fn pgp_cert_alive(errp: Option<&mut *mut crate::error::Error>, + cert: *const Cert, when: time_t) -> Status { + ffi_make_fry_from_errp!(errp); + ffi_try_status!(cert.ref_raw().alive(maybe_time(when))) } /// Changes the Cert's expiration. diff --git a/openpgp/src/cert/mod.rs b/openpgp/src/cert/mod.rs index ff209d0b..a118dc62 100644 --- a/openpgp/src/cert/mod.rs +++ b/openpgp/src/cert/mod.rs @@ -1109,27 +1109,15 @@ impl Cert { self.merge_packets(vec![sig.into()]) } - /// Returns whether or not the Cert is expired at `t`. - pub fn expired<T>(&self, t: T) -> bool - where T: Into<Option<time::SystemTime>> - { - let t = t.into(); - if let Some(Signature::V4(sig)) = self.primary_key_signature(t) { - sig.key_expired(self.primary(), t) - } else { - false - } - } - /// Returns whether or not the Cert is alive at `t`. - pub fn alive<T>(&self, t: T) -> bool + pub fn alive<T>(&self, t: T) -> Result<()> where T: Into<Option<time::SystemTime>> { let t = t.into(); if let Some(sig) = self.primary_key_signature(t) { - sig.key_alive(self.primary(), t).is_ok() + sig.key_alive(self.primary(), t) } else { - false + Err(Error::MalformedCert("No primary key signature".into()).into()) } } |