diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-08-24 15:18:36 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-08-24 15:27:36 +0200 |
commit | 14e059831e382b1cda693ed344b71a81d9d8a568 (patch) | |
tree | 98fe49abefce5158fd9842f0038956f2b8324686 /openpgp | |
parent | 30f525ee2a7b92f17878704f4bcc3cafe6006dde (diff) |
openpgp: Make PacketParser's next() and recurse() return two tuples.
- This logically groups the returned values, and makes it easier to
ignore both packet-related values.
- See #27.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/examples/decrypt-with.rs | 2 | ||||
-rw-r--r-- | openpgp/examples/notarize.rs | 2 | ||||
-rw-r--r-- | openpgp/examples/statistics.rs | 2 | ||||
-rw-r--r-- | openpgp/src/autocrypt.rs | 8 | ||||
-rw-r--r-- | openpgp/src/packet_pile.rs | 16 | ||||
-rw-r--r-- | openpgp/src/parse/packet_pile_parser.rs | 4 | ||||
-rw-r--r-- | openpgp/src/parse/parse.rs | 69 | ||||
-rw-r--r-- | openpgp/src/parse/stream.rs | 4 | ||||
-rw-r--r-- | openpgp/src/s2k.rs | 2 | ||||
-rw-r--r-- | openpgp/src/serialize/stream.rs | 8 | ||||
-rw-r--r-- | openpgp/src/signature.rs | 3 | ||||
-rw-r--r-- | openpgp/src/subpacket.rs | 2 | ||||
-rw-r--r-- | openpgp/src/tpk/mod.rs | 2 |
13 files changed, 63 insertions, 61 deletions
diff --git a/openpgp/examples/decrypt-with.rs b/openpgp/examples/decrypt-with.rs index e023bcb9..4bcd4e9c 100644 --- a/openpgp/examples/decrypt-with.rs +++ b/openpgp/examples/decrypt-with.rs @@ -93,7 +93,7 @@ pub fn main() { State::Done => State::Done, }; - let (packet, _, ppr_tmp, _) = pp.recurse() + let ((packet, _), (ppr_tmp, _)) = pp.recurse() .expect("Failed to recurse"); ppr = ppr_tmp; diff --git a/openpgp/examples/notarize.rs b/openpgp/examples/notarize.rs index d3426131..882fbb21 100644 --- a/openpgp/examples/notarize.rs +++ b/openpgp/examples/notarize.rs @@ -80,7 +80,7 @@ fn main() { _ => (), } - let (_, _, ppr_tmp, _) = pp.recurse() + let (_, (ppr_tmp, _)) = pp.recurse() .expect("Failed to recurse"); ppr = ppr_tmp; } diff --git a/openpgp/examples/statistics.rs b/openpgp/examples/statistics.rs index a5d75dda..2253cc61 100644 --- a/openpgp/examples/statistics.rs +++ b/openpgp/examples/statistics.rs @@ -59,7 +59,7 @@ fn main() { }; // Get the packet and advance the parser. - let (packet, _, tmp, _) = pp.next() + let ((packet, _), (tmp, _)) = pp.next() .expect("Failed to get next packet"); ppr = tmp; diff --git a/openpgp/src/autocrypt.rs b/openpgp/src/autocrypt.rs index 73d982bb..fc6ba419 100644 --- a/openpgp/src/autocrypt.rs +++ b/openpgp/src/autocrypt.rs @@ -476,7 +476,7 @@ impl AutocryptSetupMessage { .into()); }; - let (packet, _, ppr_, _) = pp.next()?; + let ((packet, _), (ppr_, _)) = pp.next()?; ppr = ppr_; let skesk = match packet { @@ -581,7 +581,7 @@ impl<'a> AutocryptSetupMessageParser<'a> { } // Recurse into the SEIP packet. - let (_, _, ppr_, depth) = self.pp.recurse()?; + let (_, (ppr_, depth)) = self.pp.recurse()?; let mut ppr = ppr_; if depth != 1 { return Err( @@ -633,7 +633,7 @@ impl<'a> AutocryptSetupMessageParser<'a> { (prefer_encrypt, tsk) }; - let (_, _, ppr_, _) = pp.recurse()?; + let (_, (ppr_, _)) = pp.recurse()?; ppr = ppr_; (prefer_encrypt, tsk) @@ -656,7 +656,7 @@ impl<'a> AutocryptSetupMessageParser<'a> { .into()), } - let (_, _, ppr_, _) = pp.recurse()?; + let (_, (ppr_, _)) = pp.recurse()?; ppr = ppr_; } diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index 342d5aba..89c0a3d9 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -331,7 +331,7 @@ impl PacketPile { let mut pp = ppr.unwrap(); 'outer: loop { - let (mut packet, mut position, mut ppr, _) = pp.recurse()?; + let ((mut packet, mut position), (mut ppr, _)) = pp.recurse()?; let mut relative_position : isize = position - last_position; assert!(relative_position <= 1); @@ -384,10 +384,10 @@ impl PacketPile { break; } - let result = pp.recurse()?; - packet = result.0; - assert_eq!(position, result.1); - ppr = result.2; + let ((packet_, position_), (ppr_, _)) = pp.recurse()?; + packet = packet_; + assert_eq!(position, position_); + ppr = ppr_; } } @@ -574,7 +574,7 @@ mod message_test { if let PacketParserResult::Some(pp2) = ppr { count += 1; - let (_packet, packet_depth, pp2, pp_depth) + let ((_, packet_depth), (pp2, pp_depth)) = pp2.recurse().unwrap(); eprintln!("{}, {}", packet_depth, pp_depth); assert_eq!(packet_depth as usize, count - 1); @@ -615,7 +615,7 @@ mod message_test { // recurse should now not recurse. Since there is nothing // following the compressed packet, ppr should be EOF. - let (mut packet, _, ppr, _) = pp.next().unwrap(); + let ((mut packet, _), (ppr, _)) = pp.next().unwrap(); assert!(ppr.is_none()); // Get the rest of the content and put the initial byte that @@ -632,7 +632,7 @@ mod message_test { } // And we're done... - let (_packet, _, ppr, _) = pp.next().unwrap(); + let (_, (ppr, _)) = pp.next().unwrap(); assert!(ppr.is_none()); } diff --git a/openpgp/src/parse/packet_pile_parser.rs b/openpgp/src/parse/packet_pile_parser.rs index 5517cb8c..74acde40 100644 --- a/openpgp/src/parse/packet_pile_parser.rs +++ b/openpgp/src/parse/packet_pile_parser.rs @@ -192,7 +192,7 @@ impl<'a> PacketPileParser<'a> { match self.ppr.take() { PacketParserResult::Some(pp) => { match pp.recurse() { - Ok((packet, position, ppr, _)) => { + Ok(((packet, position), (ppr, _))) => { self.insert_packet(packet, position); self.ppr = ppr; } @@ -230,7 +230,7 @@ impl<'a> PacketPileParser<'a> { match self.ppr.take() { PacketParserResult::Some(pp) => { match pp.next() { - Ok((packet, position, ppr, _)) => { + Ok(((packet, position), (ppr, _))) => { self.insert_packet(packet, position); self.ppr = ppr; } diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs index f83d43ed..8cd38a9f 100644 --- a/openpgp/src/parse/parse.rs +++ b/openpgp/src/parse/parse.rs @@ -1242,7 +1242,7 @@ fn one_pass_sig_test () { number of expected OnePassSig packets."); } - let (_, _, tmp, _) = pp.recurse().expect("Parsing message"); + let (_, (tmp, _)) = pp.recurse().expect("Parsing message"); ppr = tmp; } assert_eq!(one_pass_sigs, sigs, @@ -1582,7 +1582,7 @@ fn compressed_data_parser_test () { panic!("Wrong packet!"); } - let (_packet, _packet_depth, ppo, _pp_depth) = pp.recurse().unwrap(); + let (_, (ppo, _)) = pp.recurse().unwrap(); // ppo should be the literal data packet. let mut pp = ppo.unwrap(); @@ -1592,7 +1592,7 @@ fn compressed_data_parser_test () { let content = pp.steal_eof().unwrap(); - let (literal, _, ppo, _) = pp.recurse().unwrap(); + let ((literal, _), (ppo, _)) = pp.recurse().unwrap(); if let Packet::Literal(literal) = literal { assert_eq!(literal.filename, None); @@ -1967,7 +1967,7 @@ impl PacketParserState { /// } /// /// // Get the next packet. -/// let (_packet, _packet_depth, tmp, _pp_depth) = pp.recurse()?; +/// let (_, (tmp, _)) = pp.recurse()?; /// ppr = tmp; /// } /// # return Ok(()); @@ -2480,12 +2480,14 @@ impl <'a> PacketParser<'a> { /// [`PacketParsererBuilder`]: struct.PacketParserBuilder.html /// [`recurse()`]: #method.recurse /// - /// The return value is a tuple containing: + /// The return value is a tuple of tuples, the first containing: /// /// - A `Packet` holding the fully processed old packet; /// /// - The old packet's recursion depth; /// + /// And the second containing: + /// /// - A `PacketParser` holding the new packet; /// /// - And, the recursion depth of the new packet. @@ -2529,7 +2531,7 @@ impl <'a> PacketParser<'a> { /// container off the container stack, and returns the following /// packet in the parent container. pub fn next(mut self) - -> Result<(Packet, isize, PacketParserResult<'a>, isize)> + -> Result<((Packet, isize), (PacketParserResult<'a>, isize))> { let trace = self.state.settings.trace; @@ -2579,7 +2581,10 @@ impl <'a> PacketParser<'a> { } let eof = PacketParserResult::EOF( PacketParserEOF::new(state_)); - return Ok((self.packet, orig_depth as isize, eof, 0)); + return Ok(((self.packet, + orig_depth as isize), + (eof, + 0))); } else { self.recursion_depth -= 1; self.state = state_; @@ -2592,10 +2597,10 @@ impl <'a> PacketParser<'a> { ParserResult::Success(mut pp) => { pp.state.message_validator.push( pp.packet.tag(), self.recursion_depth as usize); - return Ok((self.packet, - orig_depth as isize, - PacketParserResult::Some(pp), - self.recursion_depth as isize)); + return Ok(((self.packet, + orig_depth as isize), + (PacketParserResult::Some(pp), + self.recursion_depth as isize))); } } } @@ -2617,7 +2622,7 @@ impl <'a> PacketParser<'a> { /// /// [`next()`]: #method.next pub fn recurse(self) - -> Result<(Packet, isize, PacketParserResult<'a>, isize)> + -> Result<((Packet, isize), (PacketParserResult<'a>, isize))> { let trace = self.state.settings.trace; @@ -2669,10 +2674,10 @@ impl <'a> PacketParser<'a> { pp.packet.tag(), self.recursion_depth as usize + 1); - return Ok((self.packet, - self.recursion_depth as isize, - PacketParserResult::Some(pp), - self.recursion_depth as isize + 1)); + return Ok(((self.packet, + self.recursion_depth as isize), + (PacketParserResult::Some(pp), + self.recursion_depth as isize + 1))); }, ParserResult::EOF(_) => { return Err(Error::MalformedPacket( @@ -2730,7 +2735,7 @@ impl <'a> PacketParser<'a> { /// } /// /// // Get the next packet. - /// let (_packet, _packet_depth, tmp, _pp_depth) = pp.recurse()?; + /// let (_, (tmp, _)) = pp.recurse()?; /// ppr = tmp; /// } /// # return Ok(()); @@ -2937,7 +2942,7 @@ fn packet_parser_reader_interface() { // // packet is the compressed data packet; ppo is the literal data // packet. - let (packet, packet_depth, ppo, pp_depth) = pp.recurse().unwrap(); + let ((packet, packet_depth), (ppo, pp_depth)) = pp.recurse().unwrap(); if let Packet::CompressedData(_) = packet { } else { panic!("Expected a compressed data packet."); @@ -2968,7 +2973,7 @@ fn packet_parser_reader_interface() { // Make sure we can still get the next packet (which in this case // is just EOF). - let (packet, _, ppo, _) = pp.recurse().unwrap(); + let ((packet, _), (ppo, _)) = pp.recurse().unwrap(); assert!(ppo.is_none()); // Since we read all of the data, we expect content to be None. assert!(packet.body.is_none()); @@ -3130,17 +3135,17 @@ mod test { pp.decrypt(test.algo, &key[..]).unwrap(); // SEIP packet. - let (packet, _, pp, _) = pp.recurse().unwrap(); + let ((packet, _), (pp, _)) = pp.recurse().unwrap(); assert_eq!(packet.tag(), Tag::SEIP); let pp = pp.expect( "Expected an compressed or literal packet, got EOF"); // Literal packet, optionally compressed - let (mut packet, _, mut pp, _) = pp.recurse().unwrap(); + let ((mut packet, _), (mut pp, _)) = pp.recurse().unwrap(); if let Packet::CompressedData(_) = packet { let pp_tmp = pp.expect( "Expected a literal packet, got EOF"); - let (packet_tmp, _, pp_tmp, _) + let ((packet_tmp, _), (pp_tmp, _)) = pp_tmp.recurse().unwrap(); packet = packet_tmp; pp = pp_tmp; @@ -3151,7 +3156,7 @@ mod test { let pp = pp.expect("Expected an MDC packet, got EOF"); // MDC packet. - let (packet, _, pp, _) = pp.recurse().unwrap(); + let ((packet, _), (pp, _)) = pp.recurse().unwrap(); if let Packet::MDC(mdc) = packet { assert_eq!(mdc.computed_hash, mdc.hash, "MDC doesn't match"); @@ -3168,7 +3173,7 @@ mod test { // This will blow up if we reach the end of the message. // But, that is what we want: we stop when we get to a // SEIP packet. - let (_, _, pp_tmp, _) = pp.recurse().unwrap(); + let (_, (pp_tmp, _)) = pp.recurse().unwrap(); pp = pp_tmp.unwrap(); } } @@ -3194,14 +3199,14 @@ mod test { pp.decrypt(test.algo, &key[..]).unwrap(); // SEIP packet. - let (packet, _, pp, _) = pp.recurse().unwrap(); + let ((packet, _), (pp, _)) = pp.recurse().unwrap(); assert_eq!(packet.tag(), Tag::SEIP); let mut pp = pp.expect( "Expected an compressed or literal packet, got EOF"); // Literal packet, optionally compressed if let Packet::CompressedData(_) = pp.packet { - let (_, _, pp_tmp, _) + let (_, (pp_tmp, _)) = pp.recurse().unwrap(); let pp_tmp = pp_tmp.expect( "Expected a literal packet, got EOF"); @@ -3223,12 +3228,12 @@ mod test { } else { panic!("Expected an Literal packet!"); } - let (_, _, pp_tmp, _) + let (_, (pp_tmp, _)) = pp.recurse().unwrap(); let pp = pp_tmp.expect("Expected an MDC packet, got EOF"); // MDC packet. - let (packet, _, pp, _) = pp.recurse().unwrap(); + let ((packet, _), (pp, _)) = pp.recurse().unwrap(); if let Packet::MDC(mdc) = packet { assert_eq!(mdc.computed_hash, mdc.hash, "MDC doesn't match"); @@ -3245,7 +3250,7 @@ mod test { // This will blow up if we reach the end of the message. // But, that is what we want: we stop when we get to a // SEIP packet. - let (_, _, pp_tmp, _) = pp.recurse().unwrap(); + let (_, (pp_tmp, _)) = pp.recurse().unwrap(); pp = pp_tmp.unwrap(); } } @@ -3277,7 +3282,7 @@ mod test { _ => {}, } - let (_, _, ppr_tmp, _) = pp.recurse().unwrap(); + let (_, (ppr_tmp, _)) = pp.recurse().unwrap(); ppr = ppr_tmp; } assert!(saw_literal); @@ -3310,7 +3315,7 @@ mod test { _ => {}, } - let (_, _, ppr_tmp, _) = pp.recurse().unwrap(); + let (_, (ppr_tmp, _)) = pp.recurse().unwrap(); ppr = ppr_tmp; } assert!(! saw_literal); @@ -3349,7 +3354,7 @@ mod test { _ => (), } - let (_, _, ppr_, _) = pp.next().unwrap(); + let (_, (ppr_, _)) = pp.next().unwrap(); ppr = ppr_; } diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index c4093e0d..73b40e75 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -241,7 +241,7 @@ impl<'a, H: VerificationHelper> Verifier<'a, H> { break; } - let (p, _, ppr_tmp, _) = pp.recurse()?; + let ((p, _), (ppr_tmp, _)) = pp.recurse()?; v.verify(p)?; ppr = ppr_tmp; } @@ -339,7 +339,7 @@ impl<'a, H: VerificationHelper> Verifier<'a, H> { break; } - let (p, _, ppr_tmp, _) = pp.recurse()?; + let ((p, _), (ppr_tmp, _)) = pp.recurse()?; self.verify(p)?; ppr = ppr_tmp; } diff --git a/openpgp/src/s2k.rs b/openpgp/src/s2k.rs index 1d80b78a..1d61823a 100644 --- a/openpgp/src/s2k.rs +++ b/openpgp/src/s2k.rs @@ -390,7 +390,7 @@ mod tests { } // Get the next packet. - let (_packet, _packet_depth, tmp, _pp_depth) = pp.next().unwrap(); + let (_, (tmp, _)) = pp.next().unwrap(); assert!(tmp.is_none()); } } diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs index 303c9af2..bc867efd 100644 --- a/openpgp/src/serialize/stream.rs +++ b/openpgp/src/serialize/stream.rs @@ -1065,8 +1065,7 @@ mod test { assert_eq!(&body, b"Hello world."); // Make sure it is the only packet. - let (_packet, _packet_depth, tmp, _pp_depth) - = pp.recurse().unwrap(); + let (_, (tmp, _)) = pp.recurse().unwrap(); assert!(tmp.is_none()); } @@ -1236,8 +1235,7 @@ mod test { } // Get the next packet. - let (_packet, _packet_depth, tmp, _pp_depth) - = pp.recurse().unwrap(); + let (_, (tmp, _)) = pp.recurse().unwrap(); ppr = tmp; } assert_eq!(good, 2); @@ -1343,7 +1341,7 @@ mod test { }; // Next? - let (_, _, tmp, _) = pp.recurse().unwrap(); + let (_, (tmp, _)) = pp.recurse().unwrap(); ppr = tmp; } assert_eq!(state, State::Done); diff --git a/openpgp/src/signature.rs b/openpgp/src/signature.rs index 2dfbf800..dd17a615 100644 --- a/openpgp/src/signature.rs +++ b/openpgp/src/signature.rs @@ -732,8 +732,7 @@ mod test { } // Get the next packet. - let (_packet, _packet_depth, tmp, _pp_depth) - = pp.recurse().unwrap(); + let (_, (tmp, _)) = pp.recurse().unwrap(); ppr = tmp; } diff --git a/openpgp/src/subpacket.rs b/openpgp/src/subpacket.rs index 729097e0..2759b5f4 100644 --- a/openpgp/src/subpacket.rs +++ b/openpgp/src/subpacket.rs @@ -47,7 +47,7 @@ //! } //! //! // Get the next packet. -//! let (_packet, _packet_depth, tmp, _pp_depth) = pp.recurse()?; +//! let (_, (tmp, _)) = pp.recurse()?; //! ppr = tmp; //! } //! # Ok(()) diff --git a/openpgp/src/tpk/mod.rs b/openpgp/src/tpk/mod.rs index 4103fa00..fd577658 100644 --- a/openpgp/src/tpk/mod.rs +++ b/openpgp/src/tpk/mod.rs @@ -861,7 +861,7 @@ impl<'a, I: Iterator<Item=Packet>> Iterator for TPKParser<'a, I> { }, PacketSource::PacketParser(pp) => { match pp.next() { - Ok((packet, _, ppr, _)) => { + Ok(((packet, _), (ppr, _))) => { if let PacketParserResult::Some(pp) = ppr { self.source = PacketSource::PacketParser(pp); } |