summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-02-12 15:40:16 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-02-12 15:53:05 +0100
commita1f3d6263ceddad1304e642e316fbd461b0478e1 (patch)
treedaff9b061e153b808069838f223e4722becd501a /openpgp-ffi
parentcb73fa51b3a7c93784cf565da61d863dc619f547 (diff)
openpgp-ffi: Fix wrapping of Fingerprints and KeyIDs.
Diffstat (limited to 'openpgp-ffi')
-rw-r--r--openpgp-ffi/src/common.rs7
-rw-r--r--openpgp-ffi/src/packet/key.rs10
-rw-r--r--openpgp-ffi/src/packet/pkesk.rs8
3 files changed, 16 insertions, 9 deletions
diff --git a/openpgp-ffi/src/common.rs b/openpgp-ffi/src/common.rs
index d76ea7a1..0ee14566 100644
--- a/openpgp-ffi/src/common.rs
+++ b/openpgp-ffi/src/common.rs
@@ -467,7 +467,7 @@ type FreeCallback = fn(*mut c_void);
/// If the free callback is not NULL, then it is called to free the
/// returned array of TPKs.
type GetPublicKeysCallback = fn(*mut HelperCookie,
- *const &openpgp::KeyID, usize,
+ *const *mut keyid::KeyID, usize,
&mut *mut *mut TPK, *mut usize,
*mut FreeCallback) -> Status;
@@ -512,7 +512,8 @@ impl VerificationHelper for VHelper {
{
// The size of KeyID is not known in C. Convert from an array
// of KeyIDs to an array of KeyID refs.
- let ids : Vec<&openpgp::KeyID> = ids.iter().collect();
+ let ids : Vec<*mut keyid::KeyID> =
+ ids.iter().map(|k| k.move_into_raw()).collect();
let mut tpk_refs_raw : *mut *mut TPK = ptr::null_mut();
let mut tpk_refs_raw_len = 0usize;
@@ -524,6 +525,8 @@ impl VerificationHelper for VHelper {
ids.as_ptr(), ids.len(),
&mut tpk_refs_raw, &mut tpk_refs_raw_len as *mut usize,
&mut free);
+ ids.into_iter().for_each(|k| { k.move_from_raw(); });
+
if result != Status::Success {
// XXX: We need to convert the status to an error. A
// status contains less information, but we should do the
diff --git a/openpgp-ffi/src/packet/key.rs b/openpgp-ffi/src/packet/key.rs
index 83785efc..cca2a512 100644
--- a/openpgp-ffi/src/packet/key.rs
+++ b/openpgp-ffi/src/packet/key.rs
@@ -8,10 +8,12 @@ use libc::{c_int, time_t};
extern crate sequoia_openpgp as openpgp;
use self::openpgp::{
- Fingerprint,
- KeyID,
packet,
};
+use super::super::fingerprint::Fingerprint;
+use super::super::keyid::KeyID;
+
+use MoveIntoRaw;
/// Clones the key.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
@@ -27,7 +29,7 @@ pub extern "system" fn pgp_key_clone(key: *const packet::Key)
pub extern "system" fn pgp_key_fingerprint(key: *const packet::Key)
-> *mut Fingerprint {
let key = ffi_param_ref!(key);
- box_raw!(key.fingerprint())
+ key.fingerprint().move_into_raw()
}
/// Computes and returns the key's key ID as per Section 12.2 of RFC
@@ -36,7 +38,7 @@ pub extern "system" fn pgp_key_fingerprint(key: *const packet::Key)
pub extern "system" fn pgp_key_keyid(key: *const packet::Key)
-> *mut KeyID {
let key = ffi_param_ref!(key);
- box_raw!(key.keyid())
+ key.keyid().move_into_raw()
}
/// Returns whether the key is expired according to the provided
diff --git a/openpgp-ffi/src/packet/pkesk.rs b/openpgp-ffi/src/packet/pkesk.rs
index 057eabff..7df0d51c 100644
--- a/openpgp-ffi/src/packet/pkesk.rs
+++ b/openpgp-ffi/src/packet/pkesk.rs
@@ -4,20 +4,22 @@ use failure;
use libc::{uint8_t, size_t};
extern crate sequoia_openpgp as openpgp;
-use self::openpgp::KeyID;
use self::openpgp::packet::{Key, PKESK, key::SecretKey};
+use super::super::keyid::KeyID;
use error::Status;
+use MoveIntoRaw;
+
/// Returns the PKESK's recipient.
///
/// The return value is a reference ot a `KeyID`. The caller must not
/// modify or free it.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle]
pub extern "system" fn pgp_pkesk_recipient(pkesk: *const PKESK)
- -> *const KeyID {
+ -> *const KeyID {
let pkesk = ffi_param_ref!(pkesk);
- pkesk.recipient()
+ pkesk.recipient().move_into_raw()
}
/// Returns the session key.