summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2020-03-20 16:49:07 +0100
committerNeal H. Walfield <neal@pep.foundation>2020-03-20 19:03:16 +0100
commit40eacf4c92c229600ccf1f328504b271fdf9d37b (patch)
treea136d3cfce4bbfff9dc9bcc7cedc55bded025023
parentff1f37a7b86780ef8d533b66f6aaea9a0f393956 (diff)
openpgp: Add a function to set the expiry of subkeys using the FFI.
- Expose `ValidKeyAmalgamation::set_expiration_time` to the C FFI.
-rw-r--r--openpgp-ffi/include/sequoia/openpgp.h14
-rw-r--r--openpgp-ffi/src/key_amalgamation.rs50
2 files changed, 64 insertions, 0 deletions
diff --git a/openpgp-ffi/include/sequoia/openpgp.h b/openpgp-ffi/include/sequoia/openpgp.h
index c9ced255..6b3e90c0 100644
--- a/openpgp-ffi/include/sequoia/openpgp.h
+++ b/openpgp-ffi/include/sequoia/openpgp.h
@@ -1096,6 +1096,20 @@ pgp_revocation_status_t pgp_valid_key_amalgamation_revocation_status (pgp_valid_
pgp_signature_t pgp_valid_key_amalgamation_binding_signature (pgp_valid_key_amalgamation_t ka);
/*/
+/// Creates one or more self-signatures that when merged with the
+/// certificate cause the key to expire at the specified time.
+///
+/// The returned buffer must be freed using libc's allocator.
+/*/
+pgp_status_t pgp_valid_key_amalgamation_set_expiration_time
+ (pgp_error_t *errp,
+ pgp_valid_key_amalgamation_t ka,
+ pgp_signer_t signer,
+ time_t time,
+ pgp_packet_t **packets,
+ size_t *packet_count);
+
+/*/
/// Frees the Valid Key Amalgamation.
/*/
void pgp_valid_key_amalgamation_free (pgp_valid_key_amalgamation_t ka);
diff --git a/openpgp-ffi/src/key_amalgamation.rs b/openpgp-ffi/src/key_amalgamation.rs
index 68144e30..a7bbeeec 100644
--- a/openpgp-ffi/src/key_amalgamation.rs
+++ b/openpgp-ffi/src/key_amalgamation.rs
@@ -5,16 +5,24 @@
//!
//! [`sequoia-openpgp::cert::key_amalgamation::KeyAmalgamation`]: ../../../sequoia_openpgp/cert/key_amalgamation/struct.KeyAmalgamation.html
+use std::slice;
+use libc::{size_t, time_t};
+
extern crate sequoia_openpgp as openpgp;
use self::openpgp::packet::key;
use self::openpgp::cert::amalgamation::ValidAmalgamation;
+use self::openpgp::crypto;
use super::packet::key::Key;
use super::packet::signature::Signature;
+use super::packet::Packet;
use super::revocation_status::RevocationStatus;
+use crate::error::Status;
use crate::MoveIntoRaw;
+use crate::MoveResultIntoRaw;
use crate::RefRaw;
+use crate::maybe_time;
/// A local alias to appease the proc macro transformation.
type ErasedKeyAmalgamation<'a> =
@@ -84,3 +92,45 @@ pub extern "C" fn pgp_valid_key_amalgamation_binding_signature<'a>(ka: *const Va
.binding_signature()
.move_into_raw()
}
+
+/// Creates one or more self-signatures that when merged with the
+/// certificate cause the key to expire at the specified time.
+///
+/// The returned buffer must be freed using libc's allocator.
+#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C"
+fn pgp_valid_key_amalgamation_set_expiration_time(
+ errp: Option<&mut *mut crate::error::Error>,
+ ka: *const ValidKeyAmalgamation,
+ primary_signer: *mut Box<dyn crypto::Signer>,
+ expiry: time_t,
+ packets: *mut *mut *mut Packet, packet_count: *mut size_t)
+ -> Status
+{
+ ffi_make_fry_from_errp!(errp);
+
+ let ka = ka.ref_raw();
+ let signer = ffi_param_ref_mut!(primary_signer);
+ let expiry = maybe_time(expiry);
+ let packets = ffi_param_ref_mut!(packets);
+ let packet_count = ffi_param_ref_mut!(packet_count);
+
+ match ka.set_expiration_time(signer.as_mut(), expiry) {
+ Ok(sigs) => {
+ let buffer = unsafe {
+ libc::calloc(sigs.len(), std::mem::size_of::<*mut Packet>())
+ as *mut *mut Packet
+ };
+ let sl = unsafe {
+ slice::from_raw_parts_mut(buffer, sigs.len())
+ };
+ *packet_count = sigs.len();
+ sl.iter_mut().zip(sigs.into_iter())
+ .for_each(|(e, sig)| *e = sig.move_into_raw());
+ *packets = buffer;
+ Status::Success
+ }
+ Err(err) => {
+ Err::<(), anyhow::Error>(err).move_into_raw(errp)
+ }
+ }
+}