From 9d87c1b3d440a16214ee4562f086ec372fd5da7b Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Fri, 28 Dec 2018 16:23:47 +0100 Subject: ffi: Add sq_tpk_merge_packets. --- ffi/include/sequoia/openpgp.h | 13 +++++++++++++ ffi/src/openpgp.rs | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'ffi') diff --git a/ffi/include/sequoia/openpgp.h b/ffi/include/sequoia/openpgp.h index dbdaa872..01aa1aab 100644 --- a/ffi/include/sequoia/openpgp.h +++ b/ffi/include/sequoia/openpgp.h @@ -835,6 +835,19 @@ sq_tpk_t sq_tpk_merge (sq_context_t ctx, sq_tpk_t other); /*/ +/// Adds packets to the TPK. +/// +/// This recanonicalizes the TPK. If the packets are invalid, they +/// are dropped. +/// +/// Consumes `tpk` and the packets in `packets`. The buffer, however, +/// must be freed by the caller. +/*/ +sq_tpk_t sq_tpk_merge_packets (sq_context_t ctx, + sq_tpk_t tpk, + sq_packet_t *packets, + size_t packets_len); +/*/ /// Dumps the TPK. /*/ void sq_tpk_dump (const sq_tpk_t tpk); diff --git a/ffi/src/openpgp.rs b/ffi/src/openpgp.rs index 6bdac19c..9b994724 100644 --- a/ffi/src/openpgp.rs +++ b/ffi/src/openpgp.rs @@ -870,6 +870,30 @@ pub extern "system" fn sq_tpk_merge(ctx: Option<&mut Context>, fry_box!(ctx, tpk.merge(*other)) } +/// Adds packets to the TPK. +/// +/// This recanonicalizes the TPK. If the packets are invalid, they +/// are dropped. +/// +/// Consumes `tpk` and the packets in `packets`. The buffer, however, +/// must be managed by the caller. +#[no_mangle] +pub extern "system" fn sq_tpk_merge_packets(ctx: Option<&mut Context>, + tpk: *mut TPK, + packets: *mut *mut Packet, + packets_len: size_t) + -> *mut TPK { + let ctx = ctx.expect("Context is NULL"); + assert!(! tpk.is_null()); + let tpk = unsafe { Box::from_raw(tpk) }; + let packets = unsafe { + slice::from_raw_parts_mut(packets, packets_len) + }; + let packets = + packets.iter_mut().map(|p| *unsafe { Box::from_raw(*p) } ).collect(); + fry_box!(ctx, tpk.merge_packets(packets)) +} + /// Dumps the TPK. /// /// XXX Remove this. -- cgit v1.2.3