summaryrefslogtreecommitdiffstats
path: root/openpgp-ffi
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-05-06 13:32:13 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-05-06 18:38:19 +0200
commit320884d10326fe186e974352391d51caa5cde571 (patch)
tree141d749c79f46183dfb2bd01e7cd7ae659292921 /openpgp-ffi
parentc575a9b4d3d0644457d3a2ddfbfa0160d3490f19 (diff)
openpgp: Streamline iteration over MessageStructure.
- Implement IntoIter and Deref to &'a [MessageLayer<'a>], drop the custom iteration structs.
Diffstat (limited to 'openpgp-ffi')
-rw-r--r--openpgp-ffi/examples/decrypt-with.c4
-rw-r--r--openpgp-ffi/include/sequoia/openpgp.h2
-rw-r--r--openpgp-ffi/src/parse/stream.rs18
3 files changed, 11 insertions, 13 deletions
diff --git a/openpgp-ffi/examples/decrypt-with.c b/openpgp-ffi/examples/decrypt-with.c
index 8bdb2d9d..4519a2f1 100644
--- a/openpgp-ffi/examples/decrypt-with.c
+++ b/openpgp-ffi/examples/decrypt-with.c
@@ -41,7 +41,8 @@ get_certs_cb (void *cookie_raw,
static pgp_status_t
check_cb (void *cookie_opaque, pgp_message_structure_t structure)
{
- pgp_message_structure_iter_t iter = pgp_message_structure_iter (structure);
+ pgp_message_structure_iter_t iter =
+ pgp_message_structure_into_iter (structure);
for (pgp_message_layer_t layer = pgp_message_structure_iter_next (iter);
layer;
@@ -142,7 +143,6 @@ check_cb (void *cookie_opaque, pgp_message_structure_t structure)
}
pgp_message_structure_iter_free (iter);
- pgp_message_structure_free (structure);
/* Implement your verification policy here. */
return PGP_STATUS_SUCCESS;
diff --git a/openpgp-ffi/include/sequoia/openpgp.h b/openpgp-ffi/include/sequoia/openpgp.h
index d6a7b219..580134ee 100644
--- a/openpgp-ffi/include/sequoia/openpgp.h
+++ b/openpgp-ffi/include/sequoia/openpgp.h
@@ -1823,7 +1823,7 @@ void pgp_message_structure_free (pgp_message_structure_t);
char *pgp_message_structure_debug (const pgp_message_structure_t);
pgp_message_structure_iter_t
-pgp_message_structure_iter (pgp_message_structure_t);
+pgp_message_structure_into_iter (pgp_message_structure_t);
/*/
/// Frees this object.
diff --git a/openpgp-ffi/src/parse/stream.rs b/openpgp-ffi/src/parse/stream.rs
index 9e23cb47..da9d45c3 100644
--- a/openpgp-ffi/src/parse/stream.rs
+++ b/openpgp-ffi/src/parse/stream.rs
@@ -59,14 +59,15 @@ pub struct MessageStructure<'a>(stream::MessageStructure<'a>);
/// Iterates over the message structure.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C"
-fn pgp_message_structure_iter(structure: *const MessageStructure)
- -> *mut MessageStructureIter {
- structure.ref_raw().iter().move_into_raw()
+fn pgp_message_structure_into_iter(structure: *mut MessageStructure)
+ -> *mut MessageStructureIter {
+ structure.move_from_raw().into_iter().move_into_raw()
}
/// Iterates over the message structure.
#[crate::ffi_wrapper_type(prefix = "pgp_", derive = "Iterator(MessageLayer)")]
-pub struct MessageStructureIter<'a>(stream::MessageStructureIter<'a>);
+pub struct MessageStructureIter<'a>(
+ std::vec::IntoIter<stream::MessageLayer<'a>>);
/// Represents a layer of the message structure.
#[crate::ffi_wrapper_type(prefix = "pgp_", derive = "Debug")]
@@ -570,7 +571,7 @@ impl VerificationHelper for VHelper {
/// check_cb (void *cookie_opaque, pgp_message_structure_t structure)
/// {
/// pgp_message_structure_iter_t iter =
-/// pgp_message_structure_iter (structure);
+/// pgp_message_structure_into_iter (structure);
/// pgp_message_layer_t layer = pgp_message_structure_iter_next (iter);
/// assert (layer);
/// assert (pgp_message_layer_compression (layer, NULL));
@@ -591,7 +592,6 @@ impl VerificationHelper for VHelper {
/// pgp_verification_result_iter_free (results);
/// pgp_message_layer_free (layer);
/// pgp_message_structure_iter_free (iter);
-/// pgp_message_structure_free (structure);
/// return PGP_STATUS_SUCCESS;
/// }
///
@@ -697,7 +697,7 @@ pub struct DetachedVerifier(openpgp::parse::stream::DetachedVerifier<'static, VH
/// check_cb (void *cookie_opaque, pgp_message_structure_t structure)
/// {
/// pgp_message_structure_iter_t iter =
-/// pgp_message_structure_iter (structure);
+/// pgp_message_structure_into_iter (structure);
/// pgp_message_layer_t layer = pgp_message_structure_iter_next (iter);
/// assert (layer);
/// pgp_verification_result_iter_t results;
@@ -714,7 +714,6 @@ pub struct DetachedVerifier(openpgp::parse::stream::DetachedVerifier<'static, VH
/// pgp_verification_result_iter_free (results);
/// pgp_message_layer_free (layer);
/// pgp_message_structure_iter_free (iter);
-/// pgp_message_structure_free (structure);
/// return PGP_STATUS_SUCCESS;
/// }
///
@@ -932,13 +931,12 @@ impl DecryptionHelper for DHelper {
/// check_cb (void *cookie_opaque, pgp_message_structure_t structure)
/// {
/// pgp_message_structure_iter_t iter =
-/// pgp_message_structure_iter (structure);
+/// pgp_message_structure_into_iter (structure);
/// pgp_message_layer_t layer = pgp_message_structure_iter_next (iter);
/// assert (layer);
/// assert (pgp_message_layer_encryption (layer, NULL, NULL));
/// pgp_message_layer_free (layer);
/// pgp_message_structure_iter_free (iter);
-/// pgp_message_structure_free (structure);
/// return PGP_STATUS_SUCCESS;
/// }
///