diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-02-12 15:39:03 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-02-12 15:54:41 +0100 |
commit | 251e9fa5dccdde942109dfd72c2469991fc566fb (patch) | |
tree | 3a8bab6b23abe26d3c8c21983e6902a0d6fcee74 | |
parent | a1f3d6263ceddad1304e642e316fbd461b0478e1 (diff) |
openpgp-ffi: Reduce FFI additions.
- See #154.
-rw-r--r-- | openpgp-ffi/include/sequoia/openpgp.h | 63 | ||||
-rw-r--r-- | openpgp-ffi/src/packet/key.rs | 65 | ||||
-rw-r--r-- | openpgp-ffi/src/packet/signature.rs | 39 |
3 files changed, 68 insertions, 99 deletions
diff --git a/openpgp-ffi/include/sequoia/openpgp.h b/openpgp-ffi/include/sequoia/openpgp.h index 5156d1df..19a98391 100644 --- a/openpgp-ffi/include/sequoia/openpgp.h +++ b/openpgp-ffi/include/sequoia/openpgp.h @@ -704,6 +704,34 @@ bool pgp_signature_expired(pgp_signature_t signature); bool pgp_signature_expired_at(pgp_signature_t signature, time_t when); /*/ +/// Returns whether the signature is alive. +/// +/// A signature is alive if the creation date is in the past, and the +/// signature has not expired. +/*/ +bool pgp_signature_key_alive(pgp_signature_t signature, pgp_key_t key); + +/*/ +/// Returns whether the signature is alive at the specified time. +/// +/// A signature is alive if the creation date is in the past, and the +/// signature has not expired at the specified time. +/*/ +bool pgp_signature_key_alive_at(pgp_signature_t signature, pgp_key_t key, + time_t when); + +/*/ +/// Returns whether the signature is expired. +/*/ +bool pgp_signature_key_expired(pgp_signature_t signature, pgp_key_t key); + +/*/ +/// Returns whether the signature is expired at the specified time. +/*/ +bool pgp_signature_key_expired_at(pgp_signature_t signature, pgp_key_t key, + time_t when); + +/*/ /// Returns the PKESK's recipient. /// /// The return value is a reference ot a `KeyID`. The caller must not @@ -1200,41 +1228,6 @@ pgp_fingerprint_t pgp_key_fingerprint (pgp_key_t p); /*/ pgp_keyid_t pgp_key_keyid (pgp_key_t p); -/*/ -/// Returns whether the key is expired according to the provided -/// self-signature. -/// -/// Note: this is with respect to the provided signature, which is not -/// checked for validity. That is, we do not check whether the -/// signature is a valid self-signature for the given key. -/*/ -bool pgp_key_expired(pgp_key_t key, pgp_signature_t self_signature); - -/*/ -/// Like pgp_key_expired, but at a specific time. -/*/ -bool pgp_key_expired_at(pgp_key_t key, pgp_signature_t self_signature, - time_t when); - -/*/ -/// Returns whether the key is alive according to the provided -/// self-signature. -/// -/// A key is alive if the creation date is in the past, and the key -/// has not expired. -/// -/// Note: this is with respect to the provided signature, which is not -/// checked for validity. That is, we do not check whether the -/// signature is a valid self-signature for the given key. -/*/ -bool pgp_key_alive(pgp_key_t key, pgp_signature_t self_signature); - -/*/ -/// Like pgp_key_alive, but at a specific time. -/*/ -bool pgp_key_alive_at(pgp_key_t key, pgp_signature_t self_signature, - time_t when); - typedef enum pgp_public_key_algorithm { /*/ /// RSA (Encrypt or Sign) diff --git a/openpgp-ffi/src/packet/key.rs b/openpgp-ffi/src/packet/key.rs index cca2a512..29c1d384 100644 --- a/openpgp-ffi/src/packet/key.rs +++ b/openpgp-ffi/src/packet/key.rs @@ -4,7 +4,7 @@ //! //! [Section 5.5 of RFC 4880]: https://tools.ietf.org/html/rfc4880#section-5.5 -use libc::{c_int, time_t}; +use libc::c_int; extern crate sequoia_openpgp as openpgp; use self::openpgp::{ @@ -41,69 +41,6 @@ pub extern "system" fn pgp_key_keyid(key: *const packet::Key) key.keyid().move_into_raw() } -/// Returns whether the key is expired according to the provided -/// self-signature. -/// -/// Note: this is with respect to the provided signature, which is not -/// checked for validity. That is, we do not check whether the -/// signature is a valid self-signature for the given key. -#[::sequoia_ffi_macros::extern_fn] #[no_mangle] -pub extern "system" fn pgp_key_expired(key: *const packet::Key, - sig: *const packet::Signature) - -> bool -{ - let key = ffi_param_ref!(key); - let sig = ffi_param_ref!(sig); - - sig.key_expired(key) -} - -/// Like pgp_key_expired, but at a specific time. -#[::sequoia_ffi_macros::extern_fn] #[no_mangle] -pub extern "system" fn pgp_key_expired_at(key: *const packet::Key, - sig: *const packet::Signature, - when: time_t) - -> bool -{ - let key = ffi_param_ref!(key); - let sig = ffi_param_ref!(sig); - - sig.key_expired_at(key, time::at(time::Timespec::new(when as i64, 0))) -} - -/// Returns whether the key is alive according to the provided -/// self-signature. -/// -/// A key is alive if the creation date is in the past, and the key -/// has not expired. -/// -/// Note: this is with respect to the provided signature, which is not -/// checked for validity. That is, we do not check whether the -/// signature is a valid self-signature for the given key. -#[::sequoia_ffi_macros::extern_fn] #[no_mangle] -pub extern "system" fn pgp_key_alive(key: *const packet::Key, - sig: *const packet::Signature) - -> bool -{ - let key = ffi_param_ref!(key); - let sig = ffi_param_ref!(sig); - - sig.key_alive(key) -} - -/// Like pgp_key_alive, but at a specific time. -#[::sequoia_ffi_macros::extern_fn] #[no_mangle] -pub extern "system" fn pgp_key_alive_at(key: *const packet::Key, - sig: *const packet::Signature, - when: time_t) - -> bool -{ - let key = ffi_param_ref!(key); - let sig = ffi_param_ref!(sig); - - sig.key_alive_at(key, time::at(time::Timespec::new(when as i64, 0))) -} - /// Returns the key's creation time. #[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system" fn pgp_key_creation_time(key: *const packet::Key) diff --git a/openpgp-ffi/src/packet/signature.rs b/openpgp-ffi/src/packet/signature.rs index 09eb7c6e..4425bc35 100644 --- a/openpgp-ffi/src/packet/signature.rs +++ b/openpgp-ffi/src/packet/signature.rs @@ -10,6 +10,7 @@ use libc::time_t; extern crate sequoia_openpgp as openpgp; +use self::openpgp::packet; use super::super::fingerprint::Fingerprint; use super::super::keyid::KeyID; @@ -144,3 +145,41 @@ fn pgp_signature_expired_at(sig: *const Signature, when: time_t) -> bool { sig.ref_raw() .signature_expired_at(time::at(time::Timespec::new(when as i64, 0))) } + +/// Returns whether the signature is alive. +/// +/// A signature is alive if the creation date is in the past, and the +/// signature has not expired. +#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system" +fn pgp_signature_key_alive(sig: *const Signature, key: *const packet::Key) + -> bool { + sig.ref_raw().key_alive(ffi_param_ref!(key)) +} + +/// Returns whether the signature is alive at the specified time. +/// +/// A signature is alive if the creation date is in the past, and the +/// signature has not expired at the specified time. +#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system" +fn pgp_signature_key_alive_at(sig: *const Signature, key: *const packet::Key, + when: time_t) -> bool { + sig.ref_raw() + .key_alive_at(ffi_param_ref!(key), + time::at(time::Timespec::new(when as i64, 0))) +} + +/// Returns whether the signature is expired. +#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system" +fn pgp_signature_key_expired(sig: *const Signature, key: *const packet::Key) + -> bool { + sig.ref_raw().key_expired(ffi_param_ref!(key)) +} + +/// Returns whether the signature is expired at the specified time. +#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "system" +fn pgp_signature_key_expired_at(sig: *const Signature, key: *const packet::Key, + when: time_t) -> bool { + sig.ref_raw() + .key_expired_at(ffi_param_ref!(key), + time::at(time::Timespec::new(when as i64, 0))) +} |