diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-04-09 17:29:50 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-04-09 18:18:18 +0200 |
commit | c1516c59709fa47d13100daddb57657008a793c3 (patch) | |
tree | 25a93149cd56546cdff6b383288cffc0b82941a1 | |
parent | dbaf698a597a018d9522e8025e9b56e784f0d60b (diff) |
openpgp: Remove convenience functions.
-rw-r--r-- | autocrypt/src/lib.rs | 2 | ||||
-rw-r--r-- | openpgp/src/packet_pile.rs | 11 | ||||
-rw-r--r-- | openpgp/src/parse.rs | 31 | ||||
-rw-r--r-- | openpgp/src/parse/packet_pile_parser.rs | 6 | ||||
-rw-r--r-- | tool/src/commands/dump.rs | 2 | ||||
-rw-r--r-- | tool/src/commands/mod.rs | 4 |
6 files changed, 16 insertions, 40 deletions
diff --git a/autocrypt/src/lib.rs b/autocrypt/src/lib.rs index 9187d1d3..ca517cc0 100644 --- a/autocrypt/src/lib.rs +++ b/autocrypt/src/lib.rs @@ -683,7 +683,7 @@ impl<'a> AutocryptSetupMessageParser<'a> { // Recurse into the SEIP packet. let mut ppr = self.pp.recurse()?.1; - if ppr.recursion_depth() != Some(1) { + if ppr.as_ref().map(|pp| pp.recursion_depth()) != Some(1) { return Err( Error::MalformedMessage( "SEIP container empty, but expected a Literal Data packet" diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index 346b666c..250d9f14 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -370,8 +370,9 @@ impl<'a> TryFrom<PacketParserResult<'a>> for PacketPile { let mut pp = ppr.unwrap(); 'outer: loop { + let recursion_depth = pp.recursion_depth(); let (mut packet, mut ppr) = pp.recurse()?; - let mut position = ppr.last_recursion_depth().unwrap() as isize; + let mut position = recursion_depth as isize; let mut relative_position : isize = position - last_position; assert!(relative_position <= 1); @@ -428,11 +429,11 @@ impl<'a> TryFrom<PacketParserResult<'a>> for PacketPile { break; } + let recursion_depth = pp.recursion_depth(); let (packet_, ppr_) = pp.recurse()?; packet = packet_; ppr = ppr_; - assert_eq!(position, - ppr.last_recursion_depth().unwrap() as isize); + assert_eq!(position, recursion_depth as isize); } } @@ -622,11 +623,11 @@ mod test { if let PacketParserResult::Some(pp2) = ppr { count += 1; + let packet_depth = pp2.recursion_depth(); let pp2 = pp2.recurse().unwrap().1; - let packet_depth = pp2.last_recursion_depth().unwrap(); assert_eq!(packet_depth, count - 1); if pp2.is_some() { - assert_eq!(pp2.recursion_depth(), Some(count)); + assert_eq!(pp2.as_ref().unwrap().recursion_depth(), count); } ppr = pp2; } else { diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index 5543ab60..c8c42a29 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -2998,33 +2998,6 @@ impl<'a> PacketParserResult<'a> { PacketParserResult::EOF(_) => None, } } - - /// The current packet's recursion depth. - /// - /// A top-level packet has a recursion depth of 0. Packets in a - /// top-level container have a recursion depth of 1, etc. - /// - /// Note: if the PacketParser has reached the end of the packet - /// sequence and is not parsing a packet, then this returns None. - pub fn recursion_depth(&self) -> Option<isize> { - match self { - PacketParserResult::Some(pp) => Some(pp.recursion_depth()), - PacketParserResult::EOF(_) => None, - } - } - - /// The last packet's recursion depth. - /// - /// A top-level packet has a recursion depth of 0. Packets in a - /// top-level container have a recursion depth of 1, etc. - /// - /// Note: if no packet has been returned yet, this returns None. - pub fn last_recursion_depth(&self) -> Option<isize> { - match self { - PacketParserResult::Some(pp) => pp.last_recursion_depth(), - PacketParserResult::EOF(eof) => eof.last_recursion_depth(), - } - } } impl<'a> Parse<'a, PacketParserResult<'a>> for PacketParser<'a> { @@ -4012,9 +3985,9 @@ fn packet_parser_reader_interface() { // // packet is the compressed data packet; ppo is the literal data // packet. + let packet_depth = pp.recursion_depth(); let (packet, ppr) = pp.recurse().unwrap(); - let packet_depth = ppr.last_recursion_depth().unwrap(); - let pp_depth = ppr.recursion_depth().unwrap(); + let pp_depth = ppr.as_ref().unwrap().recursion_depth(); if let Packet::CompressedData(_) = packet { } else { panic!("Expected a compressed data packet."); diff --git a/openpgp/src/parse/packet_pile_parser.rs b/openpgp/src/parse/packet_pile_parser.rs index 9c568a25..b0a7b97b 100644 --- a/openpgp/src/parse/packet_pile_parser.rs +++ b/openpgp/src/parse/packet_pile_parser.rs @@ -160,10 +160,11 @@ impl<'a> PacketPileParser<'a> { if self.returned_first { match self.ppr.take() { PacketParserResult::Some(pp) => { + let recursion_depth = pp.recursion_depth(); let (packet, ppr) = pp.recurse()?; self.insert_packet( packet, - ppr.last_recursion_depth().unwrap() as isize); + recursion_depth as isize); self.ppr = ppr; } eof @ PacketParserResult::EOF(_) => { @@ -189,10 +190,11 @@ impl<'a> PacketPileParser<'a> { if self.returned_first { match self.ppr.take() { PacketParserResult::Some(pp) => { + let recursion_depth = pp.recursion_depth(); let (packet, ppr) = pp.next()?; self.insert_packet( packet, - ppr.last_recursion_depth().unwrap() as isize); + recursion_depth as isize); self.ppr = ppr; }, eof @ PacketParserResult::EOF(_) => { diff --git a/tool/src/commands/dump.rs b/tool/src/commands/dump.rs index 7f0cc350..53c84fd6 100644 --- a/tool/src/commands/dump.rs +++ b/tool/src/commands/dump.rs @@ -137,9 +137,9 @@ pub fn dump<W>(input: &mut dyn io::Read, output: &mut dyn io::Write, let header = pp.header().clone(); let map = pp.take_map(); + let recursion_depth = pp.recursion_depth(); let (packet, ppr_) = pp.recurse()?; ppr = ppr_; - let recursion_depth = ppr.last_recursion_depth().unwrap(); dumper.packet(output, recursion_depth as usize, header, packet, map, additional_fields)?; diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs index ace0ad8d..fa8ed857 100644 --- a/tool/src/commands/mod.rs +++ b/tool/src/commands/mod.rs @@ -443,9 +443,9 @@ pub fn split(input: &mut dyn io::Read, prefix: &str) } } + let old_depth = Some(pp.recursion_depth()); ppr = pp.recurse()?.1; - let old_depth = ppr.last_recursion_depth(); - let new_depth = ppr.recursion_depth(); + let new_depth = ppr.as_ref().map(|pp| pp.recursion_depth()); // Update pos. match old_depth.cmp(&new_depth) { |