diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-01-29 12:07:48 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-01-29 17:41:26 +0100 |
commit | 88ec4ab63f280db148da83f78afca62d5eeabf76 (patch) | |
tree | 2d92f893402c90c93bd60a4ce8bc575b2a7863a6 /openpgp-ffi | |
parent | ad0e87312c5e18945a15f5988433ee288c89cdd7 (diff) |
openpgp-ffi: Fix TPK handling.
Diffstat (limited to 'openpgp-ffi')
-rw-r--r-- | openpgp-ffi/src/common.rs | 16 | ||||
-rw-r--r-- | openpgp-ffi/src/serialize.rs | 2 | ||||
-rw-r--r-- | openpgp-ffi/src/tsk.rs | 15 |
3 files changed, 16 insertions, 17 deletions
diff --git a/openpgp-ffi/src/common.rs b/openpgp-ffi/src/common.rs index f9a2d465..0ad74ed9 100644 --- a/openpgp-ffi/src/common.rs +++ b/openpgp-ffi/src/common.rs @@ -298,7 +298,6 @@ extern crate time; use self::openpgp::{ RevocationStatus, - TPK, packet::{ PKESK, SKESK, @@ -314,6 +313,7 @@ use self::openpgp::parse::stream::{ DetachedVerifier, }; +use self::tpk::TPK; use error::Status; fn revocation_status_to_int(rs: &RevocationStatus) -> c_int { @@ -466,7 +466,7 @@ type FreeCallback = fn(*mut c_void); /// returned array of TPKs. type GetPublicKeysCallback = fn(*mut HelperCookie, *const &openpgp::KeyID, usize, - &mut *mut &mut TPK, *mut usize, + &mut *mut *mut TPK, *mut usize, *mut FreeCallback) -> Status; /// Returns a session key. @@ -506,13 +506,13 @@ impl VHelper { impl VerificationHelper for VHelper { fn get_public_keys(&mut self, ids: &[openpgp::KeyID]) - -> Result<Vec<TPK>, failure::Error> + -> Result<Vec<openpgp::TPK>, failure::Error> { // 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 mut tpk_refs_raw : *mut &mut TPK = ptr::null_mut(); + let mut tpk_refs_raw : *mut *mut TPK = ptr::null_mut(); let mut tpk_refs_raw_len = 0usize; let mut free : FreeCallback = |_| {}; @@ -533,10 +533,10 @@ impl VerificationHelper for VHelper { // Convert the array of references to TPKs to a Vec<TPK> // (i.e., not a Vec<&TPK>). - let mut tpks : Vec<TPK> = Vec::with_capacity(tpk_refs_raw_len); + let mut tpks : Vec<openpgp::TPK> = Vec::with_capacity(tpk_refs_raw_len); for i in 0..tpk_refs_raw_len { - let tpk = unsafe { ptr::read(*tpk_refs_raw.offset(i as isize)) }; - tpks.push(tpk); + let tpk_raw = unsafe { *tpk_refs_raw.offset(i as isize) }; + tpks.push(tpk_raw.move_from_raw()); } (free)(tpk_refs_raw as *mut c_void); @@ -661,7 +661,7 @@ impl DHelper { impl VerificationHelper for DHelper { fn get_public_keys(&mut self, ids: &[openpgp::KeyID]) - -> Result<Vec<TPK>, failure::Error> + -> Result<Vec<openpgp::TPK>, failure::Error> { self.vhelper.get_public_keys(ids) } diff --git a/openpgp-ffi/src/serialize.rs b/openpgp-ffi/src/serialize.rs index 65a007bf..f489ceb7 100644 --- a/openpgp-ffi/src/serialize.rs +++ b/openpgp-ffi/src/serialize.rs @@ -14,7 +14,6 @@ extern crate sequoia_openpgp as openpgp; extern crate time; use self::openpgp::{ - TPK, crypto::Password, }; use self::openpgp::constants::{ @@ -36,6 +35,7 @@ use self::openpgp::serialize::{ }, }; +use super::openpgp::TPK; /// Streams an OpenPGP message. #[::ffi_catch_abort] #[no_mangle] diff --git a/openpgp-ffi/src/tsk.rs b/openpgp-ffi/src/tsk.rs index 49a6e4a4..688a4760 100644 --- a/openpgp-ffi/src/tsk.rs +++ b/openpgp-ffi/src/tsk.rs @@ -10,13 +10,14 @@ use libc::c_char; extern crate sequoia_openpgp; use self::sequoia_openpgp::{ - TPK, TSK, packet::Signature, serialize::Serialize, }; +use super::tpk::TPK; use ::error::Status; +use MoveIntoRaw; /// Generates a new RSA 3072 bit key with UID `primary_uid`. #[::ffi_catch_abort] #[no_mangle] @@ -47,19 +48,17 @@ pub extern "system" fn pgp_tsk_free(tsk: Option<&mut TSK>) { } /// Returns a reference to the corresponding TPK. -#[::ffi_catch_abort] #[no_mangle] -pub extern "system" fn pgp_tsk_tpk(tsk: *const TSK) - -> *const TPK { - let tsk = ffi_param_ref!(tsk); - tsk.tpk() +#[::ffi_catch_abort] #[no_mangle] pub extern "system" +fn pgp_tsk_tpk(tsk: *const TSK) + -> *const TPK { + ffi_param_ref!(tsk).tpk().move_into_raw() } /// Converts the TSK into a TPK. #[::ffi_catch_abort] #[no_mangle] pub extern "system" fn pgp_tsk_into_tpk(tsk: *mut TSK) -> *mut TPK { - let tsk = ffi_param_move!(tsk); - box_raw!(tsk.into_tpk()) + ffi_param_move!(tsk).into_tpk().move_into_raw() } |