diff options
Diffstat (limited to 'openpgp-ffi')
-rw-r--r-- | openpgp-ffi/examples/decrypt-with.c | 32 | ||||
-rw-r--r-- | openpgp-ffi/include/sequoia/openpgp.h | 12 | ||||
-rw-r--r-- | openpgp-ffi/src/parse/stream.rs | 71 |
3 files changed, 51 insertions, 64 deletions
diff --git a/openpgp-ffi/examples/decrypt-with.c b/openpgp-ffi/examples/decrypt-with.c index 8343f34d..ada4dfd7 100644 --- a/openpgp-ffi/examples/decrypt-with.c +++ b/openpgp-ffi/examples/decrypt-with.c @@ -72,19 +72,29 @@ check_cb (void *cookie_opaque, pgp_message_structure_t structure) pgp_verification_result_iter_next (results); result; result = pgp_verification_result_iter_next (results)) { - pgp_signature_t sig; + pgp_signature_t sig = NULL; + pgp_key_t key = NULL; pgp_keyid_t keyid; char *keyid_str = NULL; switch (pgp_verification_result_variant (result)) { case PGP_VERIFICATION_RESULT_GOOD_CHECKSUM: - pgp_verification_result_good_checksum (result, &sig, NULL, - NULL, NULL, NULL); - keyid = pgp_signature_issuer (sig); + pgp_verification_result_good_checksum (result, NULL, NULL, + &key, NULL, NULL); + keyid = pgp_key_keyid (key); keyid_str = pgp_keyid_to_string (keyid); fprintf (stderr, "Good signature from %s\n", keyid_str); break; + case PGP_VERIFICATION_RESULT_NOT_ALIVE: + pgp_verification_result_not_alive (result, NULL, NULL, + &key, NULL, NULL); + keyid = pgp_key_keyid (key); + keyid_str = pgp_keyid_to_string (keyid); + fprintf (stderr, "Good checksum, but not alive signature from %s\n", + keyid_str); + break; + case PGP_VERIFICATION_RESULT_MISSING_KEY: pgp_verification_result_missing_key (result, &sig); keyid = pgp_signature_issuer (sig); @@ -93,14 +103,11 @@ check_cb (void *cookie_opaque, pgp_message_structure_t structure) break; case PGP_VERIFICATION_RESULT_BAD_CHECKSUM: - pgp_verification_result_bad_checksum (result, &sig); - keyid = pgp_signature_issuer (sig); - if (keyid) { - keyid_str = pgp_keyid_to_string (keyid); - fprintf (stderr, "Bad signature from %s\n", keyid_str); - } else { - fprintf (stderr, "Bad signature without issuer information\n"); - } + pgp_verification_result_bad_checksum (result, NULL, NULL, + &key, NULL, NULL); + keyid = pgp_key_keyid (key); + keyid_str = pgp_keyid_to_string (keyid); + fprintf (stderr, "Bad signature from %s\n", keyid_str); break; default: @@ -108,6 +115,7 @@ check_cb (void *cookie_opaque, pgp_message_structure_t structure) } free (keyid_str); pgp_signature_free (sig); + pgp_key_free (key); pgp_verification_result_free (result); } pgp_verification_result_iter_free (results); diff --git a/openpgp-ffi/include/sequoia/openpgp.h b/openpgp-ffi/include/sequoia/openpgp.h index 4339d509..6f7be6d1 100644 --- a/openpgp-ffi/include/sequoia/openpgp.h +++ b/openpgp-ffi/include/sequoia/openpgp.h @@ -1722,11 +1722,19 @@ bool pgp_verification_result_good_checksum (pgp_verification_result_t, pgp_signature_t *, pgp_revocation_status_t *); bool pgp_verification_result_not_alive (pgp_verification_result_t, - pgp_signature_t *); + pgp_signature_t *, + pgp_tpk_t *, + pgp_key_t *, + pgp_signature_t *, + pgp_revocation_status_t *); bool pgp_verification_result_missing_key (pgp_verification_result_t, pgp_signature_t *); bool pgp_verification_result_bad_checksum (pgp_verification_result_t, - pgp_signature_t *); + pgp_signature_t *, + pgp_tpk_t *, + pgp_key_t *, + pgp_signature_t *, + pgp_revocation_status_t *); /*/ /// Decrypts an OpenPGP message. diff --git a/openpgp-ffi/src/parse/stream.rs b/openpgp-ffi/src/parse/stream.rs index 0dbe3408..608c7b85 100644 --- a/openpgp-ffi/src/parse/stream.rs +++ b/openpgp-ffi/src/parse/stream.rs @@ -169,20 +169,17 @@ fn pgp_verification_result_variant(result: *const VerificationResult) { use self::stream::VerificationResult::*; match result.ref_raw() { - GoodChecksum(..) => 1, - MissingKey(_) => 2, - BadChecksum(_) => 3, - NotAlive(_) => 4, + GoodChecksum { .. } => 1, + MissingKey { .. } => 2, + BadChecksum { .. } => 3, + NotAlive { .. } => 4, } } -/// Decomposes a `VerificationResult::GoodChecksum`. -/// -/// Returns `true` iff the given value is a -/// `VerificationResult::GoodChecksum`, and returns the variants members -/// in `sig_r` and the like iff `sig_r != NULL`. +macro_rules! make_decomposition_fn { + ($fn_name:ident, $variant:path) => { #[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C" -fn pgp_verification_result_good_checksum<'a>( +fn $fn_name<'a>( result: *const VerificationResult<'a>, sig_r: Maybe<*mut Signature>, tpk_r: Maybe<*mut TPK>, @@ -193,9 +190,7 @@ fn pgp_verification_result_good_checksum<'a>( -> bool { use self::stream::VerificationResult::*; - if let GoodChecksum(ref sig, ref tpk, ref key, ref binding, ref revocation) - = result.ref_raw() - { + if let $variant { sig, tpk, key, binding, revoked } = result.ref_raw() { if let Some(mut p) = sig_r { *unsafe { p.as_mut() } = sig.move_into_raw(); } @@ -213,36 +208,29 @@ fn pgp_verification_result_good_checksum<'a>( *unsafe { p.as_mut() } = binding.move_into_raw(); } if let Some(mut p) = revocation_status_r { - *unsafe { p.as_mut() } = revocation.move_into_raw(); + *unsafe { p.as_mut() } = revoked.move_into_raw(); } true } else { false } } + } +} + +/// Decomposes a `VerificationResult::GoodChecksum`. +/// +/// Returns `true` iff the given value is a +/// `VerificationResult::GoodChecksum`, and returns the variants members +/// in `sig_r` and the like iff `sig_r != NULL`. +make_decomposition_fn!(pgp_verification_result_good_checksum, GoodChecksum); /// Decomposes a `VerificationResult::NotAlive`. /// /// Returns `true` iff the given value is a /// `VerificationResult::NotAlive`, and returns the variant's members /// in `sig_r` and the like iff `sig_r != NULL`. -#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C" -fn pgp_verification_result_not_alive<'a>( - result: *const VerificationResult<'a>, - sig_r: Maybe<*mut Signature>) - -> bool -{ - use self::stream::VerificationResult::*; - if let NotAlive(ref sig) = result.ref_raw() - { - if let Some(mut p) = sig_r { - *unsafe { p.as_mut() } = sig.move_into_raw(); - } - true - } else { - false - } -} +make_decomposition_fn!(pgp_verification_result_not_alive, NotAlive); /// Decomposes a `VerificationResult::MissingKey`. /// @@ -256,8 +244,7 @@ fn pgp_verification_result_missing_key<'a>( -> bool { use self::stream::VerificationResult::*; - if let MissingKey(ref sig) = result.ref_raw() - { + if let MissingKey { sig, .. } = result.ref_raw() { if let Some(mut p) = sig_r { *unsafe { p.as_mut() } = sig.move_into_raw(); } @@ -272,23 +259,7 @@ fn pgp_verification_result_missing_key<'a>( /// Returns `true` iff the given value is a /// `VerificationResult::BadChecksum`, and returns the variants /// members in `sig_r` and the like iff `sig_r != NULL`. -#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C" -fn pgp_verification_result_bad_checksum<'a>( - result: *const VerificationResult<'a>, - sig_r: Maybe<*mut Signature>) - -> bool -{ - use self::stream::VerificationResult::*; - if let BadChecksum(ref sig) = result.ref_raw() - { - if let Some(mut p) = sig_r { - *unsafe { p.as_mut() } = sig.move_into_raw(); - } - true - } else { - false - } -} +make_decomposition_fn!(pgp_verification_result_bad_checksum, BadChecksum); /// Passed as the first argument to the callbacks used by pgp_verify /// and pgp_decrypt. |