From 88f43e115383c89fb83714e5dd6fbd2f9df16047 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Mon, 9 Dec 2019 12:32:35 +0100 Subject: openpgp: Return result from Cert::alive, remove Cert::expired. - See #371. --- openpgp-ffi/include/sequoia/openpgp.h | 9 +-------- openpgp-ffi/src/cert.rs | 15 ++++----------- 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 @@ -893,19 +893,12 @@ pgp_cert_t pgp_cert_revoke_in_place (pgp_error_t *errp, pgp_reason_for_revocation_t code, 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(&self, t: T) -> bool - where T: Into> - { - 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(&self, t: T) -> bool + pub fn alive(&self, t: T) -> Result<()> where T: Into> { 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()) } } -- cgit v1.2.3