summaryrefslogtreecommitdiffstats
path: root/ffi
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-01-16 15:56:06 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-01-16 16:32:57 +0100
commite8d2b7cd2aad554e52e1b0a1fcf7a5647562e327 (patch)
tree41747a54172f12c71d11c94a9c9c8ea3a254c303 /ffi
parente76820f4750e83897de5087c082d0e546ed70a00 (diff)
ffi: Rework complex error handling macros.
- Introduce a macro that emits local macros that implicitly use the given context to store complex errors. - This prepares us to decouple error handling from contexts, at least for the functions that otherwise do not use the context.
Diffstat (limited to 'ffi')
-rw-r--r--ffi/src/core.rs12
-rw-r--r--ffi/src/lib.rs110
-rw-r--r--ffi/src/net.rs17
-rw-r--r--ffi/src/openpgp/armor.rs7
-rw-r--r--ffi/src/openpgp/crypto.rs3
-rw-r--r--ffi/src/openpgp/mod.rs64
-rw-r--r--ffi/src/openpgp/packet_pile.rs12
-rw-r--r--ffi/src/openpgp/tpk.rs36
-rw-r--r--ffi/src/openpgp/tsk.rs6
-rw-r--r--ffi/src/store.rs69
10 files changed, 212 insertions, 124 deletions
diff --git a/ffi/src/core.rs b/ffi/src/core.rs
index 5f545702..de44a8bd 100644
--- a/ffi/src/core.rs
+++ b/ffi/src/core.rs
@@ -246,8 +246,9 @@ pub extern "system" fn sq_reader_from_file(ctx: *mut Context,
filename: *const c_char)
-> *mut Box<Read> {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let filename = ffi_param_cstr!(filename).to_string_lossy().into_owned();
- fry_box!(ctx, File::open(Path::new(&filename))
+ ffi_try_box!(File::open(Path::new(&filename))
.map(|r| Box::new(r))
.map_err(|e| e.into()))
}
@@ -285,12 +286,13 @@ pub extern "system" fn sq_reader_read(ctx: *mut Context,
buf: *mut uint8_t, len: size_t)
-> ssize_t {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let reader = ffi_param_ref_mut!(reader);
assert!(!buf.is_null());
let buf = unsafe {
slice::from_raw_parts_mut(buf, len as usize)
};
- fry_or!(ctx, reader.read(buf).map_err(|e| e.into()), -1) as ssize_t
+ ffi_try_or!(reader.read(buf).map_err(|e| e.into()), -1) as ssize_t
}
@@ -303,8 +305,9 @@ pub extern "system" fn sq_writer_from_file(ctx: *mut Context,
filename: *const c_char)
-> *mut Box<Write> {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let filename = ffi_param_cstr!(filename).to_string_lossy().into_owned();
- fry_box!(ctx, File::create(Path::new(&filename))
+ ffi_try_box!(File::create(Path::new(&filename))
.map(|r| Box::new(r))
.map_err(|e| e.into()))
}
@@ -396,10 +399,11 @@ pub extern "system" fn sq_writer_write(ctx: *mut Context,
buf: *const uint8_t, len: size_t)
-> ssize_t {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let writer = ffi_param_ref_mut!(writer);
assert!(!buf.is_null());
let buf = unsafe {
slice::from_raw_parts(buf, len as usize)
};
- fry_or!(ctx, writer.write(buf).map_err(|e| e.into()), -1) as ssize_t
+ ffi_try_or!(writer.write(buf).map_err(|e| e.into()), -1) as ssize_t
}
diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs
index a2b8269c..f50c5d36 100644
--- a/ffi/src/lib.rs
+++ b/ffi/src/lib.rs
@@ -259,60 +259,72 @@ macro_rules! ffi_return_maybe_string {
}};
}
-/// Like try! for ffi glue.
-///
-/// Evaluates the given expression. On success, evaluate to
-/// `Status.Success`. On failure, stashes the error in the context and
-/// evaluates to the appropriate Status code.
-macro_rules! fry_status {
- ($ctx:expr, $expr:expr) => {
- match $expr {
- Ok(_) => Status::Success,
- Err(e) => {
- let status = Status::from(&e);
- $ctx.e = Some(e);
- status
- },
+/* Error handling with implicit context. */
+
+/// Emits local macros for error handling that use the given context
+/// to store complex errors.
+macro_rules! ffi_make_fry_from_ctx {
+ ($ctx:ident) => {
+ /// Like try! for ffi glue.
+ ///
+ /// Evaluates the given expression. On success, evaluate to
+ /// `Status.Success`. On failure, stashes the error in the
+ /// context and evaluates to the appropriate Status code.
+ #[allow(unused_macros)]
+ macro_rules! ffi_try_status {
+ ($expr:expr) => {
+ match $expr {
+ Ok(_) => Status::Success,
+ Err(e) => {
+ let status = Status::from(&e);
+ $ctx.e = Some(e);
+ status
+ },
+ }
+ };
}
- };
-}
-/// Like try! for ffi glue.
-///
-/// Unwraps the given expression. On failure, stashes the error in
-/// the context and returns $or.
-macro_rules! fry_or {
- ($ctx:expr, $expr:expr, $or:expr) => {
- match $expr {
- Ok(v) => v,
- Err(e) => {
- $ctx.e = Some(e);
- return $or;
- },
+ /// Like try! for ffi glue.
+ ///
+ /// Unwraps the given expression. On failure, stashes the
+ /// error in the context and returns $or.
+ #[allow(unused_macros)]
+ macro_rules! ffi_try_or {
+ ($expr:expr, $or:expr) => {
+ match $expr {
+ Ok(v) => v,
+ Err(e) => {
+ $ctx.e = Some(e);
+ return $or;
+ },
+ }
+ };
}
- };
-}
-/// Like try! for ffi glue.
-///
-/// Unwraps the given expression. On failure, stashes the error in
-/// the context and returns NULL.
-macro_rules! fry {
- ($ctx:expr, $expr:expr) => {
- fry_or!($ctx, $expr, ::std::ptr::null_mut())
- };
-}
+ /// Like try! for ffi glue.
+ ///
+ /// Unwraps the given expression. On failure, stashes the
+ /// error in the context and returns NULL.
+ #[allow(unused_macros)]
+ macro_rules! ffi_try {
+ ($expr:expr) => {
+ ffi_try_or!($expr, ::std::ptr::null_mut())
+ };
+ }
-/// Like try! for ffi glue, then box into raw pointer.
-///
-/// This is used to transfer ownership from Rust to C.
-///
-/// Unwraps the given expression. On success, it boxes the value
-/// and turns it into a raw pointer. On failure, stashes the
-/// error in the context and returns NULL.
-macro_rules! fry_box {
- ($ctx:expr, $expr:expr) => {
- Box::into_raw(Box::new(fry!($ctx, $expr)))
+ /// Like try! for ffi glue, then box into raw pointer.
+ ///
+ /// This is used to transfer ownership from Rust to C.
+ ///
+ /// Unwraps the given expression. On success, it boxes the
+ /// value and turns it into a raw pointer. On failure,
+ /// stashes the error in the context and returns NULL.
+ #[allow(unused_macros)]
+ macro_rules! ffi_try_box {
+ ($expr:expr) => {
+ Box::into_raw(Box::new(ffi_try!($expr)))
+ }
+ }
}
}
diff --git a/ffi/src/net.rs b/ffi/src/net.rs
index 7d1558f6..ab0800eb 100644
--- a/ffi/src/net.rs
+++ b/ffi/src/net.rs
@@ -51,9 +51,10 @@ use super::core::Context;
pub extern "system" fn sq_keyserver_new(ctx: *mut Context,
uri: *const c_char) -> *mut KeyServer {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let uri = ffi_param_cstr!(uri).to_string_lossy();
- fry_box!(ctx, KeyServer::new(&ctx.c, &uri))
+ ffi_try_box!(KeyServer::new(&ctx.c, &uri))
}
/// Returns a handle for the given URI.
@@ -69,6 +70,7 @@ pub extern "system" fn sq_keyserver_with_cert(ctx: *mut Context,
cert: *const uint8_t,
len: size_t) -> *mut KeyServer {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let uri = ffi_param_cstr!(uri).to_string_lossy();
if cert.is_null() {
@@ -79,9 +81,9 @@ pub extern "system" fn sq_keyserver_with_cert(ctx: *mut Context,
slice::from_raw_parts(cert, len as usize)
};
- let cert = fry!(ctx, Certificate::from_der(cert)
+ let cert = ffi_try!(Certificate::from_der(cert)
.map_err(|e| e.into()));
- fry_box!(ctx, KeyServer::with_cert(&ctx.c, &uri, cert))
+ ffi_try_box!(KeyServer::with_cert(&ctx.c, &uri, cert))
}
/// Returns a handle for the SKS keyserver pool.
@@ -95,7 +97,8 @@ pub extern "system" fn sq_keyserver_with_cert(ctx: *mut Context,
pub extern "system" fn sq_keyserver_sks_pool(ctx: *mut Context)
-> *mut KeyServer {
let ctx = ffi_param_ref_mut!(ctx);
- fry_box!(ctx, KeyServer::sks_pool(&ctx.c))
+ ffi_make_fry_from_ctx!(ctx);
+ ffi_try_box!(KeyServer::sks_pool(&ctx.c))
}
/// Frees a keyserver object.
@@ -113,10 +116,11 @@ pub extern "system" fn sq_keyserver_get(ctx: *mut Context,
id: *const KeyID)
-> *mut TPK {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let ks = ffi_param_ref_mut!(ks);
let id = ffi_param_ref!(id);
- fry_box!(ctx, ks.get(&id))
+ ffi_try_box!(ks.get(&id))
}
/// Sends the given key to the server.
@@ -128,8 +132,9 @@ pub extern "system" fn sq_keyserver_send(ctx: *mut Context,
tpk: *const TPK)
-> Status {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let ks = ffi_param_ref_mut!(ks);
let tpk = ffi_param_ref!(tpk);
- fry_status!(ctx, ks.send(tpk))
+ ffi_try_status!(ks.send(tpk))
}
diff --git a/ffi/src/openpgp/armor.rs b/ffi/src/openpgp/armor.rs
index 3680b74e..7616a03d 100644
--- a/ffi/src/openpgp/armor.rs
+++ b/ffi/src/openpgp/armor.rs
@@ -145,10 +145,11 @@ pub extern "system" fn sq_armor_reader_from_file(ctx: *mut Context,
kind: c_int)
-> *mut Box<Read> {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let filename = ffi_param_cstr!(filename).to_string_lossy().into_owned();
let kind = int_to_kind(kind);
- fry_box!(ctx, armor::Reader::from_file(&filename, kind)
+ ffi_try_box!(armor::Reader::from_file(&filename, kind)
.map(|r| Box::new(r))
.map_err(|e| e.into()))
}
@@ -214,6 +215,7 @@ pub extern "system" fn sq_armor_reader_headers(ctx: *mut Context,
len: *mut size_t)
-> *mut ArmorHeader {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let len = ffi_param_ref_mut!(len);
// We need to downcast `reader`. To do that, we need to do a
@@ -349,6 +351,7 @@ pub extern "system" fn sq_armor_writer_new
-> *mut Box<Write>
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let inner = ffi_param_ref_mut!(inner);
let kind = int_to_kind(kind).expect("KIND must not be SQ_ARMOR_KIND_ANY");
@@ -369,7 +372,7 @@ pub extern "system" fn sq_armor_writer_new
let header: Vec<(&str, &str)> =
header_.iter().map(|h| (h.0.as_ref(), h.1.as_ref())).collect();
- fry_box!(ctx, armor::Writer::new(inner, kind, &header)
+ ffi_try_box!(armor::Writer::new(inner, kind, &header)
.map(|r| Box::new(r))
.map_err(|e| e.into()))
}
diff --git a/ffi/src/openpgp/crypto.rs b/ffi/src/openpgp/crypto.rs
index b4da7553..0055d68f 100644
--- a/ffi/src/openpgp/crypto.rs
+++ b/ffi/src/openpgp/crypto.rs
@@ -27,9 +27,10 @@ pub extern "system" fn sq_key_pair_new
-> *mut crypto::KeyPair
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let public = ffi_param_move!(public);
let secret = ffi_param_move!(secret);
- fry_box!(ctx, crypto::KeyPair::new(*public, *secret))
+ ffi_try_box!(crypto::KeyPair::new(*public, *secret))
}
/// Frees a key pair.
diff --git a/ffi/src/openpgp/mod.rs b/ffi/src/openpgp/mod.rs
index 3f74263b..8dba85a1 100644
--- a/ffi/src/openpgp/mod.rs
+++ b/ffi/src/openpgp/mod.rs
@@ -459,8 +459,9 @@ pub extern "system" fn sq_p_key_into_key_pair(ctx: *mut Context,
-> *mut self::openpgp::crypto::KeyPair
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let key = ffi_param_move!(key);
- fry_box!(ctx, key.into_keypair())
+ ffi_try_box!(key.into_keypair())
}
/// Returns the value of the User ID Packet.
@@ -517,6 +518,7 @@ pub extern "system" fn sq_skesk_decrypt(ctx: *mut Context,
key_len: *mut size_t)
-> Status {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let skesk = ffi_param_ref!(skesk);
assert!(!password.is_null());
let password = unsafe {
@@ -539,7 +541,7 @@ pub extern "system" fn sq_skesk_decrypt(ctx: *mut Context,
*key_len = k.len();
Status::Success
},
- Err(e) => fry_status!(ctx, Err::<(), failure::Error>(e)),
+ Err(e) => ffi_try_status!(Err::<(), failure::Error>(e)),
}
} else {
panic!("Not a SKESK packet");
@@ -572,6 +574,7 @@ pub extern "system" fn sq_pkesk_decrypt(ctx: *mut Context,
key_len: *mut size_t)
-> Status {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let pkesk = ffi_param_ref!(pkesk);
let secret_key = ffi_param_ref!(secret_key);
let algo = ffi_param_ref_mut!(algo);
@@ -591,7 +594,7 @@ pub extern "system" fn sq_pkesk_decrypt(ctx: *mut Context,
*key_len = k.len();
Status::Success
},
- Err(e) => fry_status!(ctx, Err::<(), failure::Error>(e)),
+ Err(e) => ffi_try_status!(Err::<(), failure::Error>(e)),
}
} else {
// XXX: Better message.
@@ -611,8 +614,9 @@ pub extern "system" fn sq_packet_parser_from_reader<'a>
(ctx: *mut Context, reader: *mut Box<'a + Read>)
-> *mut PacketParserResult<'a> {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let reader = ffi_param_ref_mut!(reader);
- fry_box!(ctx, PacketParser::from_reader(reader))
+ ffi_try_box!(PacketParser::from_reader(reader))
}
/// Starts parsing OpenPGP packets stored in a file named `path`.
@@ -624,8 +628,9 @@ pub extern "system" fn sq_packet_parser_from_file
(ctx: *mut Context, filename: *const c_char)
-> *mut PacketParserResult<'static> {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let filename = ffi_param_cstr!(filename).to_string_lossy().into_owned();
- fry_box!(ctx, PacketParser::from_file(&filename))
+ ffi_try_box!(PacketParser::from_file(&filename))
}
/// Starts parsing OpenPGP packets stored in a buffer.
@@ -637,12 +642,13 @@ pub extern "system" fn sq_packet_parser_from_bytes
(ctx: *mut Context, b: *const uint8_t, len: size_t)
-> *mut PacketParserResult<'static> {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
assert!(!b.is_null());
let buf = unsafe {
slice::from_raw_parts(b, len as usize)
};
- fry_box!(ctx, PacketParser::from_bytes(buf))
+ ffi_try_box!(PacketParser::from_bytes(buf))
}
/// Frees the packet parser result
@@ -773,6 +779,7 @@ pub extern "system" fn sq_packet_parser_next<'a>
ppr: Option<&mut *mut PacketParserResult<'a>>)
-> Status {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let pp = ffi_param_move!(pp);
match pp.next() {
@@ -785,7 +792,7 @@ pub extern "system" fn sq_packet_parser_next<'a>
}
Status::Success
},
- Err(e) => fry_status!(ctx, Err::<(), failure::Error>(e)),
+ Err(e) => ffi_try_status!(Err::<(), failure::Error>(e)),
}
}
@@ -817,6 +824,7 @@ pub extern "system" fn sq_packet_parser_recurse<'a>
ppr: Option<&mut *mut PacketParserResult<'a>>)
-> Status {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let pp = ffi_param_move!(pp);
match pp.recurse() {
@@ -829,7 +837,7 @@ pub extern "system" fn sq_packet_parser_recurse<'a>
}
Status::Success
},
- Err(e) => fry_status!(ctx, Err::<(), failure::Error>(e)),
+ Err(e) => ffi_try_status!(Err::<(), failure::Error>(e)),
}
}
@@ -846,9 +854,10 @@ pub extern "system" fn sq_packet_parser_buffer_unread_content<'a>
len: *mut usize)
-> *const uint8_t {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let pp = ffi_param_ref_mut!(pp);
let len = ffi_param_ref_mut!(len);
- let buf = fry!(ctx, pp.buffer_unread_content());
+ let buf = ffi_try!(pp.buffer_unread_content());
*len = buf.len();
buf.as_ptr()
}
@@ -864,6 +873,7 @@ pub extern "system" fn sq_packet_parser_finish<'a>
-> Status
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let pp = ffi_param_ref_mut!(pp);
match pp.finish() {
Ok(p) => {
@@ -897,12 +907,13 @@ pub extern "system" fn sq_packet_parser_decrypt<'a>
key: *const uint8_t, key_len: size_t)
-> Status {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let pp = ffi_param_ref_mut!(pp);
let key = unsafe {
slice::from_raw_parts(key, key_len as usize)
};
let key = key.to_owned().into();
- fry_status!(ctx, pp.decrypt((algo as u8).into(), &key))
+ ffi_try_status!(pp.decrypt((algo as u8).into(), &key))
}
@@ -1019,12 +1030,13 @@ pub extern "system" fn sq_writer_stack_write
-> ssize_t
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let writer = ffi_param_ref_mut!(writer);
assert!(!buf.is_null());
let buf = unsafe {
slice::from_raw_parts(buf, len as usize)
};
- fry_or!(ctx, writer.write(buf).map_err(|e| e.into()), -1) as ssize_t
+ ffi_try_or!(writer.write(buf).map_err(|e| e.into()), -1) as ssize_t
}
/// Writes up to `len` bytes of `buf` into `writer`.
@@ -1040,12 +1052,13 @@ pub extern "system" fn sq_writer_stack_write_all
-> Status
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let writer = ffi_param_ref_mut!(writer);
assert!(!buf.is_null());
let buf = unsafe {
slice::from_raw_parts(buf, len as usize)
};
- fry_status!(ctx, writer.write_all(buf).map_err(|e| e.into()))
+ ffi_try_status!(writer.write_all(buf).map_err(|e| e.into()))
}
/// Finalizes this writer, returning the underlying writer.
@@ -1056,9 +1069,10 @@ pub extern "system" fn sq_writer_stack_finalize_one
-> *mut writer::Stack<'static, Cookie>
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
if !writer.is_null() {
let writer = ffi_param_move!(writer);
- maybe_box_raw!(fry!(ctx, writer.finalize_one()))
+ maybe_box_raw!(ffi_try!(writer.finalize_one()))
} else {
ptr::null_mut()
}
@@ -1072,9 +1086,10 @@ pub extern "system" fn sq_writer_stack_finalize
-> Status
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
if !writer.is_null() {
let writer = ffi_param_move!(writer);
- fry_status!(ctx, writer.finalize())
+ ffi_try_status!(writer.finalize())
} else {
Status::Success
}
@@ -1093,8 +1108,9 @@ pub extern "system" fn sq_arbitrary_writer_new
-> *mut writer::Stack<'static, Cookie>
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let inner = ffi_param_move!(inner);
- fry_box!(ctx, ArbitraryWriter::new(*inner, tag.into()))
+ ffi_try_box!(ArbitraryWriter::new(*inner, tag.into()))
}
/// Signs a packet stream.
@@ -1111,6 +1127,7 @@ pub extern "system" fn sq_signer_new
-> *mut writer::Stack<'static, Cookie>
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let inner = ffi_param_move!(inner);
let signers = ffi_param_ref!(signers);
let signers = unsafe {
@@ -1122,7 +1139,7 @@ pub extern "system" fn sq_signer_new
ffi_param_ref_mut!(signer).as_mut()
}
).collect();
- fry_box!(ctx, Signer::new(*inner, signers))
+ ffi_try_box!(Signer::new(*inner, signers))
}
/// Creates a signer for a detached signature.
@@ -1135,6 +1152,7 @@ pub extern "system" fn sq_signer_new_detached
-> *mut writer::Stack<'static, Cookie>
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let inner = ffi_param_move!(inner);
let signers = ffi_param_ref!(signers);
let signers = unsafe {
@@ -1146,7 +1164,7 @@ pub extern "system" fn sq_signer_new_detached
ffi_param_ref_mut!(signer).as_mut()
}
).collect();
- fry_box!(ctx, Signer::detached(*inner, signers))
+ ffi_try_box!(Signer::detached(*inner, signers))
}
/// Writes a literal data packet.
@@ -1160,8 +1178,9 @@ pub extern "system" fn sq_literal_writer_new
-> *mut writer::Stack<'static, Cookie>
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let inner = ffi_param_move!(inner);
- fry_box!(ctx, LiteralWriter::new(*inner,
+ ffi_try_box!(LiteralWriter::new(*inner,
DataFormat::Binary,
None,
None))
@@ -1185,6 +1204,7 @@ pub extern "system" fn sq_encryptor_new
-> *mut writer::Stack<'static, Cookie>
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let inner = ffi_param_move!(inner);
let mut passwords_ = Vec::new();
if passwords_len > 0 {
@@ -1210,7 +1230,7 @@ pub extern "system" fn sq_encryptor_new
1 => EncryptionMode::ForTransport,
_ => panic!("Bad encryption mode: {}", encryption_mode),
};
- fry_box!(ctx, Encryptor::new(*inner,
+ ffi_try_box!(Encryptor::new(*inner,
&passwords_.iter().collect::<Vec<&Password>>(),
&recipients,
encryption_mode))
@@ -1503,12 +1523,13 @@ pub fn sq_verify<'a>(ctx: *mut Context,
-> Status
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let input = ffi_param_ref_mut!(input);
let r = verify_real(input, dsig, output,
get_public_keys, check_signatures, cookie);
- fry_status!(ctx, r)
+ ffi_try_status!(r)
}
@@ -1626,11 +1647,12 @@ pub fn sq_decrypt<'a>(ctx: *mut Context,
-> Status
{
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let input = ffi_param_ref_mut!(input);
let output = ffi_param_ref_mut!(output);
let r = decrypt_real(input, output,
get_public_keys, get_secret_keys, check_signatures, cookie);
- fry_status!(ctx, r)
+ ffi_try_status!(r)
}
diff --git a/ffi/src/openpgp/packet_pile.rs b/ffi/src/openpgp/packet_pile.rs
index 6f798359..139a4861 100644
--- a/ffi/src/openpgp/packet_pile.rs
+++ b/ffi/src/openpgp/packet_pile.rs
@@ -33,8 +33,9 @@ pub extern "system" fn sq_packet_pile_from_reader(ctx: *mut Context,
reader: *mut Box<Read>)
-> *mut PacketPile {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let reader = ffi_param_ref_mut!(reader);
- fry_box!(ctx, PacketPile::from_reader(reader))
+ ffi_try_box!(PacketPile::from_reader(reader))
}
/// Deserializes the OpenPGP message stored in the file named by
@@ -46,8 +47,9 @@ pub extern "system" fn sq_packet_pile_from_file(ctx: *mut Context,
filename: *const c_char)
-> *mut PacketPile {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let filename = ffi_param_cstr!(filename).to_string_lossy().into_owned();
- fry_box!(ctx, PacketPile::from_file(&filename))
+ ffi_try_box!(PacketPile::from_file(&filename))
}
/// Deserializes the OpenPGP message stored in the provided buffer.
@@ -58,12 +60,13 @@ pub extern "system" fn sq_packet_pile_from_bytes(ctx: *mut Context,
b: *const uint8_t, len: size_t)
-> *mut PacketPile {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
assert!(!b.is_null());
let buf = unsafe {
slice::from_raw_parts(b, len as usize)
};
- fry_box!(ctx, PacketPile::from_bytes(buf))
+ ffi_try_box!(PacketPile::from_bytes(buf))
}
/// Frees the packet_pile.
@@ -88,7 +91,8 @@ pub extern "system" fn sq_packet_pile_serialize(ctx: *mut Context,
writer: *mut Box<Write>)
-> Status {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let packet_pile = ffi_param_ref!(packet_pile);
let writer = ffi_param_ref_mut!(writer);
- fry_status!(ctx, packet_pile.serialize(writer))
+ ffi_try_status!(packet_pile.serialize(writer))
}
diff --git a/ffi/src/openpgp/tpk.rs b/ffi/src/openpgp/tpk.rs
index 1a5e9ec6..0df7071f 100644
--- a/ffi/src/openpgp/tpk.rs
+++ b/ffi/src/openpgp/tpk.rs
@@ -43,8 +43,9 @@ pub extern "system" fn sq_tpk_from_reader(ctx: *mut Context,
reader: *mut Box<Read>)
-> *mut TPK {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let reader = ffi_param_ref_mut!(reader);
- fry_box!(ctx, TPK::from_reader(reader))
+ ffi_try_box!(TPK::from_reader(reader))
}
/// Returns the first TPK encountered in the file.
@@ -53,8 +54,9 @@ pub extern "system" fn sq_tpk_from_file(ctx: *mut Context,
filename: *const c_char)
-> *mut TPK {
let ctx = ffi_param_ref_mut!(ctx);
+ ffi_make_fry_from_ctx!(ctx);
let filename = ffi_param_cstr!(filename).to_string_lossy().into_owned();
- fry_box!