diff options
author | Neal H. Walfield <neal@pep.foundation> | 2018-10-09 11:41:59 +0200 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2018-10-09 12:17:00 +0200 |
commit | e139db9d16f79d7607288f78d360728b14ceed2b (patch) | |
tree | 376638073845f1b3a7bdd22425dce19efd423dce /ffi | |
parent | 482f166f799d15601c5739593189b397f20abccd (diff) |
openpgp: Don't return the depth from PacketParser::{next,recurse}
- Change PacketParser::next and PacketParser::recurse to not return
the packets' depths. Instead, require the caller to query them
using accessor functions, if they are needed (they usually
aren't).
Diffstat (limited to 'ffi')
-rw-r--r-- | ffi/include/sequoia/openpgp.h | 25 | ||||
-rw-r--r-- | ffi/src/openpgp.rs | 30 |
2 files changed, 18 insertions, 37 deletions
diff --git a/ffi/include/sequoia/openpgp.h b/ffi/include/sequoia/openpgp.h index 37b84211..476f76b2 100644 --- a/ffi/include/sequoia/openpgp.h +++ b/ffi/include/sequoia/openpgp.h @@ -806,12 +806,12 @@ uint8_t sq_packet_parser_recursion_depth (sq_packet_parser_t pp); /*/ /// Finishes parsing the current packet and starts parsing the -/// following one. +/// next one. /// /// This function finishes parsing the current packet. By /// default, any unread content is dropped. (See /// [`PacketParsererBuilder`] for how to configure this.) It then -/// creates a new packet parser for the following packet. If the +/// creates a new packet parser for the next packet. If the /// current packet is a container, this function does *not* /// recurse into the container, but skips any packets it contains. /// To recurse into the container, use the [`recurse()`] method. @@ -823,15 +823,16 @@ uint8_t sq_packet_parser_recursion_depth (sq_packet_parser_t pp); /// /// - A `Packet` holding the fully processed old packet; /// -/// - The old packet's recursion depth; -/// /// - A `PacketParser` holding the new packet; /// -/// - And, the recursion depth of the new packet. +/// To determine the two packet's position within the parse tree, +/// you can use `last_path()` and `path()`, respectively. To +/// determine their depth, you can use `last_recursion_depth()` +/// and `recursion_depth()`, respectively. /// -/// A recursion depth of 0 means that the packet is a top-level -/// packet, a recursion depth of 1 means that the packet is an -/// immediate child of a top-level-packet, etc. +/// Note: A recursion depth of 0 means that the packet is a +/// top-level packet, a recursion depth of 1 means that the packet +/// is an immediate child of a top-level-packet, etc. /// /// Since the packets are serialized in depth-first order and all /// interior nodes are visited, we know that if the recursion @@ -876,9 +877,7 @@ uint8_t sq_packet_parser_recursion_depth (sq_packet_parser_t pp); sq_status_t sq_packet_parser_next (sq_context_t ctx, sq_packet_parser_t pp, sq_packet_t *old_packet, - uint8_t *old_recursion_level, - sq_packet_parser_result_t *ppr, - uint8_t *new_recursion_level); + sq_packet_parser_result_t *ppr); /*/ /// Finishes parsing the current packet and starts parsing the @@ -905,9 +904,7 @@ sq_status_t sq_packet_parser_next (sq_context_t ctx, sq_status_t sq_packet_parser_recurse (sq_context_t ctx, sq_packet_parser_t pp, sq_packet_t *old_packet, - uint8_t *old_recursion_level, - sq_packet_parser_result_t *ppr, - uint8_t *new_recursion_level); + sq_packet_parser_result_t *ppr); /*/ /// Causes the PacketParser to buffer the packet's contents. diff --git a/ffi/src/openpgp.rs b/ffi/src/openpgp.rs index 3d808584..b2d357e6 100644 --- a/ffi/src/openpgp.rs +++ b/ffi/src/openpgp.rs @@ -1316,9 +1316,7 @@ pub extern "system" fn sq_packet_parser_next<'a> (ctx: Option<&mut Context>, pp: *mut PacketParser<'a>, old_packet: Option<&mut *mut Packet>, - old_recursion_level: Option<&mut isize>, - ppr: Option<&mut *mut PacketParserResult<'a>>, - new_recursion_level: Option<&mut isize>) + ppr: Option<&mut *mut PacketParserResult<'a>>) -> Status { let ctx = ctx.expect("Context is NULL"); assert!(! pp.is_null()); @@ -1327,19 +1325,13 @@ pub extern "system" fn sq_packet_parser_next<'a> }; match pp.next() { - Ok(((old_p, old_rl), (new_ppr, new_rl))) => { + Ok((old_p, new_ppr)) => { if let Some(p) = old_packet { *p = box_raw!(old_p); } - if let Some(p) = old_recursion_level { - *p = old_rl; - } if let Some(p) = ppr { *p = box_raw!(new_ppr); } - if let Some(p) = new_recursion_level { - *p = new_rl; - } Status::Success }, Err(e) => fry_status!(ctx, Err::<(), failure::Error>(e)), @@ -1356,9 +1348,9 @@ pub extern "system" fn sq_packet_parser_next<'a> /// recurse into the container, and return a `PacketParser` for /// its first child. Otherwise, we return the next packet in the /// packet stream. If this function recurses, then the new -/// packet's position will be old_position + 1; because we always -/// visit interior nodes, we can't recurse more than one level at -/// a time. +/// packet's recursion depth will be `last_recursion_depth() + 1`; +/// because we always visit interior nodes, we can't recurse more +/// than one level at a time. /// /// [`next()`]: #method.next /// @@ -1371,9 +1363,7 @@ pub extern "system" fn sq_packet_parser_recurse<'a> (ctx: Option<&mut Context>, pp: *mut PacketParser<'a>, old_packet: Option<&mut *mut Packet>, - old_recursion_level: Option<&mut isize>, - ppr: Option<&mut *mut PacketParserResult<'a>>, - new_recursion_level: Option<&mut isize>) + ppr: Option<&mut *mut PacketParserResult<'a>>) -> Status { let ctx = ctx.expect("Context is NULL"); assert!(! pp.is_null()); @@ -1382,19 +1372,13 @@ pub extern "system" fn sq_packet_parser_recurse<'a> }; match pp.recurse() { - Ok(((old_p, old_rl), (new_ppr, new_rl))) => { + Ok((old_p, new_ppr)) => { if let Some(p) = old_packet { *p = box_raw!(old_p); } - if let Some(p) = old_recursion_level { - *p = old_rl; - } if let Some(p) = ppr { *p = box_raw!(new_ppr); } - if let Some(p) = new_recursion_level { - *p = new_rl; - } Status::Success }, Err(e) => fry_status!(ctx, Err::<(), failure::Error>(e)), |