summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-01-23 17:48:32 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-01-25 14:04:26 +0100
commit0484d4fca48fd8201fb3506fb4c4ddf5f4c76c83 (patch)
tree23c5a87a36dcb1f4de6c01bdf7963b699ae96f57
parent43a64c0d3b5169d9ef3852b7bcbc3bc673a934d4 (diff)
openpgp-ffi: Convert PacketPile.
-rw-r--r--openpgp-ffi/src/packet_pile.rs47
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))
}