diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-05-08 15:25:36 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-05-09 12:52:23 +0200 |
commit | 0e61680d31c7444d0163708bfd0ddf94072c6c1b (patch) | |
tree | 7f2c57cfb2002b6dd8f6b5e198de46d47a0c2df5 /openpgp-ffi | |
parent | 746e8176e9d0c92321d63adcebcd376290bda902 (diff) |
openpgp-ffi: Wrap RevocationStatus.
Diffstat (limited to 'openpgp-ffi')
-rw-r--r-- | openpgp-ffi/include/sequoia/openpgp.h | 5 | ||||
-rw-r--r-- | openpgp-ffi/src/common.rs | 1 | ||||
-rw-r--r-- | openpgp-ffi/src/parse/stream.rs | 29 | ||||
-rw-r--r-- | openpgp-ffi/src/revocation_status.rs | 30 | ||||
-rw-r--r-- | openpgp-ffi/src/tpk.rs | 15 |
5 files changed, 41 insertions, 39 deletions
diff --git a/openpgp-ffi/include/sequoia/openpgp.h b/openpgp-ffi/include/sequoia/openpgp.h index bd9063a8..db3c82aa 100644 --- a/openpgp-ffi/include/sequoia/openpgp.h +++ b/openpgp-ffi/include/sequoia/openpgp.h @@ -137,6 +137,11 @@ pgp_revocation_status_variant_t pgp_revocation_status_variant ( /*/ void pgp_revocation_status_free (pgp_revocation_status_t rs); +/*/ +/// Returns a human readable description of this object suitable for +/// debugging. +/*/ +char *pgp_revocation_status_debug (const pgp_revocation_status_t); /* openpgp::armor. */ diff --git a/openpgp-ffi/src/common.rs b/openpgp-ffi/src/common.rs index 6efa9ec4..1e7e40ee 100644 --- a/openpgp-ffi/src/common.rs +++ b/openpgp-ffi/src/common.rs @@ -287,3 +287,4 @@ pub mod parse; pub mod serialize; pub mod tpk; pub mod tsk; +pub mod revocation_status; diff --git a/openpgp-ffi/src/parse/stream.rs b/openpgp-ffi/src/parse/stream.rs index 823917ec..ebd4bc50 100644 --- a/openpgp-ffi/src/parse/stream.rs +++ b/openpgp-ffi/src/parse/stream.rs @@ -17,7 +17,6 @@ extern crate sequoia_openpgp as openpgp; extern crate time; use self::openpgp::{ - RevocationStatus, crypto::SessionKey, constants::SymmetricAlgorithm, packet::{ @@ -50,34 +49,6 @@ use super::super::{ tpk::TPK, }; -fn revocation_status_to_int(rs: &RevocationStatus) -> c_int { - match rs { - RevocationStatus::Revoked(_) => 0, - RevocationStatus::CouldBe(_) => 1, - RevocationStatus::NotAsFarAsWeKnow => 2, - } -} - -/// Returns the TPK's revocation status variant. -#[::sequoia_ffi_macros::extern_fn] #[no_mangle] -pub extern "C" fn pgp_revocation_status_variant( - rs: *mut RevocationStatus) - -> c_int -{ - let rs = ffi_param_move!(rs); - let variant = revocation_status_to_int(rs.as_ref()); - Box::into_raw(rs); - variant -} - -/// Frees a pgp_revocation_status_t. -#[::sequoia_ffi_macros::extern_fn] #[no_mangle] -pub extern "C" fn pgp_revocation_status_free( - rs: Option<&mut RevocationStatus>) -{ - ffi_free!(rs) -} - // Decryptor. /// A message's verification results. diff --git a/openpgp-ffi/src/revocation_status.rs b/openpgp-ffi/src/revocation_status.rs new file mode 100644 index 00000000..03362ec4 --- /dev/null +++ b/openpgp-ffi/src/revocation_status.rs @@ -0,0 +1,30 @@ +//! The revocation status. + +use libc::c_int; + +extern crate sequoia_openpgp as openpgp; + +use RefRaw; + +/// The revocation status. +#[::ffi_wrapper_type(prefix = "pgp_", derive = "Debug")] +pub struct RevocationStatus<'a>(openpgp::RevocationStatus<'a>); + +fn revocation_status_to_int(rs: &openpgp::RevocationStatus) -> c_int { + use self::openpgp::RevocationStatus::*; + match rs { + Revoked(_) => 0, + CouldBe(_) => 1, + NotAsFarAsWeKnow => 2, + } +} + +/// Returns the TPK's revocation status variant. +#[::sequoia_ffi_macros::extern_fn] #[no_mangle] +pub extern "C" fn pgp_revocation_status_variant( + rs: *const RevocationStatus) + -> c_int +{ + revocation_status_to_int(rs.ref_raw()) +} + diff --git a/openpgp-ffi/src/tpk.rs b/openpgp-ffi/src/tpk.rs index 991bb837..64a923e6 100644 --- a/openpgp-ffi/src/tpk.rs +++ b/openpgp-ffi/src/tpk.rs @@ -12,7 +12,6 @@ use libc::{c_char, c_int, size_t, time_t, uint8_t}; extern crate sequoia_openpgp as openpgp; use self::openpgp::{ Packet, - RevocationStatus, autocrypt::Autocrypt, crypto, constants::ReasonForRevocation, @@ -36,6 +35,8 @@ use super::packet::key::Key; use super::packet::signature::Signature; use super::packet_pile::PacketPile; use super::tsk::TSK; +use super::revocation_status::RevocationStatus; + use Maybe; use RefRaw; use MoveFromRaw; @@ -158,8 +159,7 @@ fn pgp_tpk_primary(tpk: *const TPK) -> *const Key { #[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C" fn pgp_tpk_revocation_status(tpk: *const TPK) -> *mut RevocationStatus<'static> { - let tpk = tpk.ref_raw(); - box_raw!(tpk.revoked(None)) + tpk.ref_raw().revoked(None).move_into_raw() } fn int_to_reason_for_revocation(code: c_int) -> ReasonForRevocation { @@ -442,7 +442,6 @@ pub extern "C" fn pgp_user_id_binding_iter_next<'a>( /// Wrapers a KeyIter for export via the FFI. pub struct KeyIterWrapper<'a> { iter: KeyIter<'a>, - rso: Option<RevocationStatus<'a>>, // Whether next has been called. next_called: bool, } @@ -470,7 +469,6 @@ pub extern "C" fn pgp_tpk_key_iter_valid(tpk: *const TPK) let tpk = tpk.ref_raw(); box_raw!(KeyIterWrapper { iter: tpk.keys_valid(), - rso: None, next_called: false, }) } @@ -486,7 +484,6 @@ pub extern "C" fn pgp_tpk_key_iter_all(tpk: *const TPK) let tpk = tpk.ref_raw(); box_raw!(KeyIterWrapper { iter: tpk.keys_all(), - rso: None, next_called: false, }) } @@ -657,11 +654,10 @@ pub extern "C" fn pgp_tpk_key_iter_unencrypted_secret<'a>( pub extern "C" fn pgp_tpk_key_iter_next<'a>( iter_wrapper: *mut KeyIterWrapper<'a>, sigo: Option<&mut Maybe<Signature>>, - rso: Option<&mut &'a RevocationStatus<'a>>) + rso: Option<&mut *mut RevocationStatus<'a>>) -> Maybe<Key> { let iter_wrapper = ffi_param_ref_mut!(iter_wrapper); - iter_wrapper.rso = None; iter_wrapper.next_called = true; if let Some((sig, rs, key)) = iter_wrapper.iter.next() { @@ -670,8 +666,7 @@ pub extern "C" fn pgp_tpk_key_iter_next<'a>( } if let Some(ptr) = rso { - iter_wrapper.rso = Some(rs); - *ptr = iter_wrapper.rso.as_ref().unwrap(); + *ptr = rs.move_into_raw(); } Some(key).move_into_raw() |