summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openpgp-ffi/include/sequoia/openpgp.h5
-rw-r--r--openpgp-ffi/src/common.rs1
-rw-r--r--openpgp-ffi/src/parse/stream.rs29
-rw-r--r--openpgp-ffi/src/revocation_status.rs30
-rw-r--r--openpgp-ffi/src/tpk.rs15
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()