diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-11-22 14:26:14 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-11-22 14:26:14 +0100 |
commit | ced195eb1a7d9151640f1ffacd890839a55b8680 (patch) | |
tree | 53001af1ba91361bfa2ed4b585686781983c6603 /openpgp-ffi/src/common.rs | |
parent | 28be944bd9f6548b2eee5fc222ffeb52c9d2f8aa (diff) |
openpgp: Make conversions into Key<SecretParts, _> fallible.
- Fixes #380.
Diffstat (limited to 'openpgp-ffi/src/common.rs')
-rw-r--r-- | openpgp-ffi/src/common.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/openpgp-ffi/src/common.rs b/openpgp-ffi/src/common.rs index 078c035e..7c615bab 100644 --- a/openpgp-ffi/src/common.rs +++ b/openpgp-ffi/src/common.rs @@ -164,6 +164,30 @@ macro_rules! ffi_make_fry_from_errp { /// Like try! for ffi glue. /// + /// Evaluates the given expression. `Ok(v)` evaluates to `v`. + /// On failure, stashes the error in the context and returns + /// the appropriate Status code. + #[allow(unused_macros)] + macro_rules! ffi_try_or_status { + ($expr:expr) => { + match $expr { + Ok(v) => v, + Err(e) => { + use crate::MoveIntoRaw; + use failure::Error; + let status = crate::error::Status::from(&e); + if let Some(errp) = $errp { + let e : Error = e.into(); + *errp = e.move_into_raw(); + } + return status; + }, + } + }; + } + + /// Like try! for ffi glue. + /// /// Unwraps the given expression. On failure, stashes the /// error in the context and returns $or. #[allow(unused_macros)] |