diff options
Diffstat (limited to 'openpgp-ffi')
-rw-r--r-- | openpgp-ffi/src/packet_pile.rs | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/openpgp-ffi/src/packet_pile.rs b/openpgp-ffi/src/packet_pile.rs index f693012f..c379a8e8 100644 --- a/openpgp-ffi/src/packet_pile.rs +++ b/openpgp-ffi/src/packet_pile.rs @@ -15,6 +15,7 @@ use self::openpgp::{ serialize::Serialize, }; +use Maybe; use ::error::Status; /// A `PacketPile` holds a deserialized sequence of OpenPGP messages. @@ -36,52 +37,48 @@ pub struct PacketPile(openpgp::PacketPile); /// too large. /// /// Note: this interface *does* buffer the contents of packets. -#[::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 openpgp::PacketPile { - ffi_make_fry_from_errp!(errp); +#[::ffi_catch_abort] #[no_mangle] pub extern "system" +fn pgp_packet_pile_from_reader(errp: Option<&mut *mut failure::Error>, + reader: *mut Box<Read>) + -> Maybe<openpgp::PacketPile> { let reader = ffi_param_ref_mut!(reader); - ffi_try_box!(openpgp::PacketPile::from_reader(reader)) + openpgp::PacketPile::from_reader(reader).move_into_raw(errp) } /// Deserializes the OpenPGP message stored in the file named by /// `filename`. /// /// See `pgp_packet_pile_from_reader` for more details and caveats. -#[::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 openpgp::PacketPile { - ffi_make_fry_from_errp!(errp); +#[::ffi_catch_abort] #[no_mangle] pub extern "system" +fn pgp_packet_pile_from_file(errp: Option<&mut *mut failure::Error>, + filename: *const c_char) + -> Maybe<openpgp::PacketPile> { let filename = ffi_param_cstr!(filename).to_string_lossy().into_owned(); - ffi_try_box!(openpgp::PacketPile::from_file(&filename)) + openpgp::PacketPile::from_file(&filename).move_into_raw(errp) } /// Deserializes the OpenPGP message stored in the provided buffer. /// /// See `pgp_packet_pile_from_reader` for more details and caveats. -#[::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 openpgp::PacketPile { - ffi_make_fry_from_errp!(errp); +#[::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) + -> Maybe<openpgp::PacketPile> { assert!(!b.is_null()); let buf = unsafe { slice::from_raw_parts(b, len as usize) }; - ffi_try_box!(openpgp::PacketPile::from_bytes(buf)) + openpgp::PacketPile::from_bytes(buf).move_into_raw(errp) } /// 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 openpgp::PacketPile, - writer: *mut Box<Write>) - -> Status { +#[::ffi_catch_abort] #[no_mangle] pub extern "system" +fn pgp_packet_pile_serialize(errp: Option<&mut *mut failure::Error>, + packet_pile: *const openpgp::PacketPile, + writer: *mut Box<Write>) + -> Status { ffi_make_fry_from_errp!(errp); - let packet_pile = ffi_param_ref!(packet_pile); let writer = ffi_param_ref_mut!(writer); - ffi_try_status!(packet_pile.serialize(writer)) + ffi_try_status!(packet_pile.ref_raw().serialize(writer)) } |