diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-01-29 16:38:24 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-01-29 17:41:26 +0100 |
commit | ca715fb46d371a49492c51f829ea61f6883782ab (patch) | |
tree | 4019f7f6b5338063d70c7063fb0dd0fb041378f1 /openpgp-ffi | |
parent | 6b06c05cb99d2e7396fdf3d3d1c2e6f92d954dad (diff) |
openpgp-ffi: Add a Fallible<()> to Status conversion.
Diffstat (limited to 'openpgp-ffi')
-rw-r--r-- | openpgp-ffi/src/error.rs | 17 | ||||
-rw-r--r-- | openpgp-ffi/src/tpk.rs | 6 | ||||
-rw-r--r-- | openpgp-ffi/src/tsk.rs | 6 |
3 files changed, 21 insertions, 8 deletions
diff --git a/openpgp-ffi/src/error.rs b/openpgp-ffi/src/error.rs index 6eb63000..ffed2be7 100644 --- a/openpgp-ffi/src/error.rs +++ b/openpgp-ffi/src/error.rs @@ -13,6 +13,23 @@ extern crate sequoia_openpgp as openpgp; #[::ffi_wrapper_type(prefix = "pgp_", derive = "Display")] pub struct Error(failure::Error); +impl MoveResultIntoRaw<::error::Status> for ::failure::Fallible<()> +{ + fn move_into_raw(self, errp: Option<&mut *mut ::error::Error>) + -> ::error::Status { + match self { + Ok(_) => ::error::Status::Success, + Err(e) => { + let status = ::error::Status::from(&e); + if let Some(errp) = errp { + *errp = e.move_into_raw(); + } + status + }, + } + } +} + /// Returns the error status code. #[::ffi_catch_abort] #[no_mangle] pub extern "system" fn pgp_error_status(error: *const Error) diff --git a/openpgp-ffi/src/tpk.rs b/openpgp-ffi/src/tpk.rs index 606a58e6..90e88448 100644 --- a/openpgp-ffi/src/tpk.rs +++ b/openpgp-ffi/src/tpk.rs @@ -118,10 +118,9 @@ fn pgp_tpk_serialize(errp: Option<&mut *mut ::error::Error>, tpk: *const TPK, writer: *mut Box<Write>) -> Status { - ffi_make_fry_from_errp!(errp); let tpk = tpk.ref_raw(); let writer = ffi_param_ref_mut!(writer); - ffi_try_status!(tpk.serialize(writer)) + tpk.serialize(writer).move_into_raw(errp) } /// Merges `other` into `tpk`. @@ -678,7 +677,6 @@ pub extern "system" fn pgp_tpk_builder_generate revocation_out: *mut *mut Signature) -> Status { - ffi_make_fry_from_errp!(errp); let tpk_out = ffi_param_ref_mut!(tpk_out); let revocation_out = ffi_param_ref_mut!(revocation_out); let tpkb = ffi_param_move!(tpkb); @@ -690,7 +688,7 @@ pub extern "system" fn pgp_tpk_builder_generate }, Err(e) => { *tpk_out = None; - ffi_try_status!(Err::<(), failure::Error>(e)) + Err::<(), failure::Error>(e).move_into_raw(errp) }, } } diff --git a/openpgp-ffi/src/tsk.rs b/openpgp-ffi/src/tsk.rs index effd4293..b3254456 100644 --- a/openpgp-ffi/src/tsk.rs +++ b/openpgp-ffi/src/tsk.rs @@ -39,7 +39,6 @@ fn pgp_tsk_new(errp: Option<&mut *mut ::error::Error>, revocation_out: *mut *mut Signature) -> Status { - ffi_make_fry_from_errp!(errp); let tsk_out = ffi_param_ref_mut!(tsk_out); let revocation_out = ffi_param_ref_mut!(revocation_out); let primary_uid = ffi_param_cstr!(primary_uid).to_string_lossy(); @@ -49,7 +48,7 @@ fn pgp_tsk_new(errp: Option<&mut *mut ::error::Error>, *revocation_out = box_raw!(revocation); Status::Success }, - Err(e) => ffi_try_status!(Err::<(), failure::Error>(e)), + Err(e) => Err::<(), failure::Error>(e).move_into_raw(errp), } } @@ -74,8 +73,7 @@ fn pgp_tsk_serialize(errp: Option<&mut *mut ::error::Error>, tsk: *const TSK, writer: *mut Box<Write>) -> Status { - ffi_make_fry_from_errp!(errp); let tsk = tsk.ref_raw(); let writer = ffi_param_ref_mut!(writer); - ffi_try_status!(tsk.serialize(writer)) + tsk.serialize(writer).move_into_raw(errp) } |