diff options
-rw-r--r-- | ffi/src/net.rs | 5 | ||||
-rw-r--r-- | ffi/src/store.rs | 8 | ||||
-rw-r--r-- | openpgp-ffi/src/keyid.rs | 14 |
3 files changed, 14 insertions, 13 deletions
diff --git a/ffi/src/net.rs b/ffi/src/net.rs index 8a0cf600..9c462f4e 100644 --- a/ffi/src/net.rs +++ b/ffi/src/net.rs @@ -35,11 +35,12 @@ use std::slice; extern crate sequoia_openpgp as openpgp; use self::openpgp::TPK; -use self::openpgp::KeyID; use sequoia_net::KeyServer; use super::error::Status; use super::core::Context; +use ::openpgp::keyid::KeyID; +use ::RefRaw; /// Returns a handle for the given URI. /// @@ -118,7 +119,7 @@ pub extern "system" fn sq_keyserver_get(ctx: *mut Context, 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); + let id = id.ref_raw(); ffi_try_box!(ks.get(&id)) } diff --git a/ffi/src/store.rs b/ffi/src/store.rs index 7d7302d9..b0917196 100644 --- a/ffi/src/store.rs +++ b/ffi/src/store.rs @@ -31,7 +31,6 @@ extern crate sequoia_openpgp as openpgp; use self::openpgp::TPK; use self::openpgp::{ Fingerprint, - KeyID }; use sequoia_store::{ self, Store, StoreIter, Binding, BindingIter, Key, KeyIter, LogIter, Pool, @@ -40,6 +39,9 @@ use sequoia_store::{ use super::error::Status; use super::core::Context; +use ::openpgp::keyid::KeyID; +use RefRaw; +use Maybe; /// Lists all stores with the given prefix. #[::ffi_catch_abort] #[no_mangle] @@ -256,7 +258,7 @@ pub extern "system" fn sq_store_lookup_by_keyid(ctx: *mut Context, { let ctx = ffi_param_ref_mut!(ctx); ffi_make_fry_from_ctx!(ctx); - let keyid = ffi_param_ref!(keyid); + let keyid = keyid.ref_raw(); ffi_try_box!(Pool::lookup_by_keyid(&ctx.c, keyid)) } @@ -269,7 +271,7 @@ pub extern "system" fn sq_store_lookup_by_subkeyid(ctx: *mut Context, { let ctx = ffi_param_ref_mut!(ctx); ffi_make_fry_from_ctx!(ctx); - let keyid = ffi_param_ref!(keyid); + let keyid = keyid.ref_raw(); ffi_try_box!(Pool::lookup_by_subkeyid(&ctx.c, keyid)) } diff --git a/openpgp-ffi/src/keyid.rs b/openpgp-ffi/src/keyid.rs index 229b97e6..96df52ca 100644 --- a/openpgp-ffi/src/keyid.rs +++ b/openpgp-ffi/src/keyid.rs @@ -10,12 +10,13 @@ //! //! [`sequoia-openpgp::KeyID`]: ../../sequoia_openpgp/enum.KeyID.html -use std::ptr; use std::slice; use libc::{uint8_t, c_char}; extern crate sequoia_openpgp as openpgp; +use Maybe; + /// Holds a KeyID. /// /// A KeyID is a fingerprint fragment. It identifies a public key, @@ -53,7 +54,7 @@ pub struct KeyID(openpgp::KeyID); fn pgp_keyid_from_bytes(id: *const uint8_t) -> *mut openpgp::KeyID { assert!(!id.is_null()); let id = unsafe { slice::from_raw_parts(id, 8) }; - Box::into_raw(Box::new(openpgp::KeyID::from_bytes(id))) + openpgp::KeyID::from_bytes(id).move_into_raw() } /// Reads a hex-encoded Key ID. @@ -75,16 +76,13 @@ fn pgp_keyid_from_bytes(id: *const uint8_t) -> *mut openpgp::KeyID { /// pgp_keyid_free (mr_b); /// ``` #[::ffi_catch_abort] #[no_mangle] pub extern "system" -fn pgp_keyid_from_hex(id: *const c_char) -> *mut openpgp::KeyID { +fn pgp_keyid_from_hex(id: *const c_char) -> Maybe<openpgp::KeyID> { let id = ffi_param_cstr!(id).to_string_lossy(); - openpgp::KeyID::from_hex(&id) - .map(|id| Box::into_raw(Box::new(id))) - .unwrap_or(ptr::null_mut()) + openpgp::KeyID::from_hex(&id).ok().move_into_raw() } /// Converts the KeyID to a hexadecimal number. #[::ffi_catch_abort] #[no_mangle] pub extern "system" fn pgp_keyid_to_hex(id: *const openpgp::KeyID) -> *mut c_char { - let id = ffi_param_ref!(id); - ffi_return_string!(id.to_hex()) + ffi_return_string!(id.ref_raw().to_hex()) } |