diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-03-13 15:45:32 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-03-13 16:41:26 +0100 |
commit | bfeda8e25b13a4221d63a0b9978ef55a77cd33f5 (patch) | |
tree | fc0f3dbee2fefc47df4abab50356380d961f0cea /openpgp | |
parent | f9aa80d1adb056091e4d12d8d042b54750348d61 (diff) |
openpgp: Decouple PacketPile and Container.
- Likewise for the test.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/message/mod.rs | 2 | ||||
-rw-r--r-- | openpgp/src/packet_pile.rs | 36 | ||||
-rw-r--r-- | openpgp/src/parse/packet_pile_parser.rs | 6 |
3 files changed, 22 insertions, 22 deletions
diff --git a/openpgp/src/message/mod.rs b/openpgp/src/message/mod.rs index 7ec6d0ef..1e3f3e69 100644 --- a/openpgp/src/message/mod.rs +++ b/openpgp/src/message/mod.rs @@ -1100,7 +1100,7 @@ mod tests { // 2: SEIP // 0: Literal // => good. - packets[2].container_mut().unwrap().packets.pop().unwrap(); + packets[2].container_mut().unwrap().children_mut().pop().unwrap(); #[allow(deprecated)] packets.insert( diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index e51c78de..0cc8ce35 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -20,7 +20,7 @@ use crate::parse::Cookie; impl fmt::Debug for PacketPile { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("PacketPile") - .field("packets", &self.top_level.packets) + .field("packets", &self.top_level.children_ref()) .finish() } } @@ -123,8 +123,8 @@ impl PacketPile { let mut cont = Some(&self.top_level); for i in pathspec { if let Some(ref c) = cont.take() { - if *i < c.packets.len() { - let p = &c.packets[*i]; + if *i < c.children_ref().len() { + let p = &c.children_ref()[*i]; packet = Some(p); cont = p.container_ref(); continue; @@ -146,11 +146,11 @@ impl PacketPile { for (level, &i) in pathspec.iter().enumerate() { let tmp = container; - if i >= tmp.packets.len() { + if i >= tmp.children_ref().len() { return None; } - let p = &mut tmp.packets[i]; + let p = &mut tmp.children_mut()[i]; if level == pathspec.len() - 1 { return Some(p) @@ -218,33 +218,33 @@ impl PacketPile { let tmp = container; if level == pathspec.len() - 1 { - if i + count > tmp.packets.len() { + if i + count > tmp.children_ref().len() { return Err(Error::IndexOutOfRange.into()); } // Out with the old... - let old = tmp.packets + let old = tmp.children_mut() .drain(i..i + count) .collect::<Vec<Packet>>(); assert_eq!(old.len(), count); // In with the new... - let mut tail = tmp.packets + let mut tail = tmp.children_mut() .drain(i..) .collect::<Vec<Packet>>(); - tmp.packets.append(&mut packets); - tmp.packets.append(&mut tail); + tmp.children_mut().append(&mut packets); + tmp.children_mut().append(&mut tail); return Ok(old) } - if i >= tmp.packets.len() { + if i >= tmp.children_ref().len() { return Err(Error::IndexOutOfRange.into()); } - match tmp.packets[i] { + match tmp.children_ref()[i] { // The structured container types. Packet::CompressedData(_) | Packet::SEIP(_) @@ -252,7 +252,7 @@ impl PacketPile { => (), // Ok. _ => return Err(Error::IndexOutOfRange.into()), } - container = tmp.packets[i].container_mut() + container = tmp.children_mut()[i].container_mut() .expect("The above packets are structured containers"); } @@ -325,8 +325,8 @@ impl PacketPile { // being reborrowed and preventing us from // assigning to it. let tmp = container; - let packets_len = tmp.packets.len(); - let p = &mut tmp.packets[packets_len - 1]; + let packets_len = tmp.children_ref().len(); + let p = &mut tmp.children_mut()[packets_len - 1]; container = p.container_mut().unwrap(); } @@ -342,11 +342,11 @@ impl PacketPile { if relative_position == 1 { // Create a new container. let tmp = container; - let i = tmp.packets.len() - 1; - container = tmp.packets[i].container_mut().unwrap(); + let i = tmp.children_ref().len() - 1; + container = tmp.children_mut()[i].container_mut().unwrap(); } - container.packets.push(packet); + container.children_mut().push(packet); if ppr.is_none() { break 'outer; diff --git a/openpgp/src/parse/packet_pile_parser.rs b/openpgp/src/parse/packet_pile_parser.rs index 8c6512a2..83fff632 100644 --- a/openpgp/src/parse/packet_pile_parser.rs +++ b/openpgp/src/parse/packet_pile_parser.rs @@ -131,8 +131,8 @@ impl<'a> PacketPileParser<'a> { for i in 0..position { // The most recent child. let tmp = container; - let packets_len = tmp.packets.len(); - let p = &mut tmp.packets[packets_len - 1]; + let packets_len = tmp.children_ref().len(); + let p = &mut tmp.children_mut()[packets_len - 1]; if p.children().next().is_none() { assert!(i == position - 1, "Internal inconsistency while building message."); @@ -141,7 +141,7 @@ impl<'a> PacketPileParser<'a> { container = p.container_mut().unwrap(); } - container.packets.push(packet); + container.children_mut().push(packet); } /// Finishes parsing the current packet and starts parsing the |