diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-01-22 13:40:18 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-01-22 17:47:45 +0100 |
commit | 865096185b5d52fc98f799b2d2b8cb5ef62bdc02 (patch) | |
tree | 7517b18efbc324662ea42408ad631e365b639675 /openpgp-ffi | |
parent | ebb0d43ba773ec13e47d74b7baf035aaf7f0fb17 (diff) |
openpgp-ffi: Wrap PacketPile.
Diffstat (limited to 'openpgp-ffi')
-rw-r--r-- | openpgp-ffi/include/sequoia/openpgp.h | 6 | ||||
-rw-r--r-- | openpgp-ffi/src/packet_pile.rs | 43 |
2 files changed, 24 insertions, 25 deletions
diff --git a/openpgp-ffi/include/sequoia/openpgp.h b/openpgp-ffi/include/sequoia/openpgp.h index 0756e6b6..4c1e9997 100644 --- a/openpgp-ffi/include/sequoia/openpgp.h +++ b/openpgp-ffi/include/sequoia/openpgp.h @@ -540,6 +540,12 @@ void pgp_packet_pile_free (pgp_packet_pile_t message); pgp_packet_pile_t pgp_packet_pile_clone (pgp_packet_pile_t message); /*/ +/// Returns a human readable description of this object suitable for +/// debugging. +/*/ +char *pgp_packet_pile_debug (const pgp_packet_pile_t); + +/*/ /// Serializes the packet pile. /*/ pgp_status_t pgp_packet_pile_serialize (pgp_error_t *errp, diff --git a/openpgp-ffi/src/packet_pile.rs b/openpgp-ffi/src/packet_pile.rs index 43f3bdeb..f693012f 100644 --- a/openpgp-ffi/src/packet_pile.rs +++ b/openpgp-ffi/src/packet_pile.rs @@ -9,15 +9,23 @@ use std::slice; use std::io::{Read, Write}; use libc::{uint8_t, c_char, size_t}; -extern crate sequoia_openpgp; -use self::sequoia_openpgp::{ - PacketPile, +extern crate sequoia_openpgp as openpgp; +use self::openpgp::{ parse::Parse, serialize::Serialize, }; use ::error::Status; +/// A `PacketPile` holds a deserialized sequence of OpenPGP messages. +/// +/// Wraps [`sequoia-openpgp::PacketPile`]. +/// +/// [`sequoia-openpgp::PacketPile`]: ../../sequoia_openpgp/struct.PacketPile.html +#[::ffi_wrapper_type(prefix = "pgp_", + derive = "Clone, Debug, PartialEq")] +pub struct PacketPile(openpgp::PacketPile); + /// Deserializes the OpenPGP message stored in a `std::io::Read` /// object. /// @@ -31,10 +39,10 @@ use ::error::Status; #[::ffi_catch_abort] #[no_mangle] pub extern "system" fn pgp_packet_pile_from_reader(errp: Option<&mut *mut failure::Error>, reader: *mut Box<Read>) - -> *mut PacketPile { + -> *mut openpgp::PacketPile { ffi_make_fry_from_errp!(errp); let reader = ffi_param_ref_mut!(reader); - ffi_try_box!(PacketPile::from_reader(reader)) + ffi_try_box!(openpgp::PacketPile::from_reader(reader)) } /// Deserializes the OpenPGP message stored in the file named by @@ -44,10 +52,10 @@ pub extern "system" fn pgp_packet_pile_from_reader(errp: Option<&mut *mut failur #[::ffi_catch_abort] #[no_mangle] pub extern "system" fn pgp_packet_pile_from_file(errp: Option<&mut *mut failure::Error>, filename: *const c_char) - -> *mut PacketPile { + -> *mut openpgp::PacketPile { ffi_make_fry_from_errp!(errp); let filename = ffi_param_cstr!(filename).to_string_lossy().into_owned(); - ffi_try_box!(PacketPile::from_file(&filename)) + ffi_try_box!(openpgp::PacketPile::from_file(&filename)) } /// Deserializes the OpenPGP message stored in the provided buffer. @@ -56,35 +64,20 @@ pub extern "system" fn pgp_packet_pile_from_file(errp: Option<&mut *mut failure: #[::ffi_catch_abort] #[no_mangle] pub extern "system" fn pgp_packet_pile_from_bytes(errp: Option<&mut *mut failure::Error>, b: *const uint8_t, len: size_t) - -> *mut PacketPile { + -> *mut openpgp::PacketPile { ffi_make_fry_from_errp!(errp); assert!(!b.is_null()); let buf = unsafe { slice::from_raw_parts(b, len as usize) }; - ffi_try_box!(PacketPile::from_bytes(buf)) -} - -/// Frees the packet_pile. -#[::ffi_catch_abort] #[no_mangle] -pub extern "system" fn pgp_packet_pile_free(packet_pile: Option<&mut PacketPile>) -{ - ffi_free!(packet_pile) -} - -/// Clones the PacketPile. -#[::ffi_catch_abort] #[no_mangle] -pub extern "system" fn pgp_packet_pile_clone(packet_pile: *const PacketPile) - -> *mut PacketPile { - let packet_pile = ffi_param_ref!(packet_pile); - box_raw!(packet_pile.clone()) + ffi_try_box!(openpgp::PacketPile::from_bytes(buf)) } /// Serializes the packet pile. #[::ffi_catch_abort] #[no_mangle] pub extern "system" fn pgp_packet_pile_serialize(errp: Option<&mut *mut failure::Error>, - packet_pile: *const PacketPile, + packet_pile: *const openpgp::PacketPile, writer: *mut Box<Write>) -> Status { ffi_make_fry_from_errp!(errp); |