summaryrefslogtreecommitdiffstats
path: root/openpgp/src/packet_pile.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-12-19 17:08:05 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-12-20 18:04:56 +0100
commite8b55c27a98a332dd69113e3c07e98cbbce8bb7b (patch)
tree4eae88561988f41545698cc42411454952003970 /openpgp/src/packet_pile.rs
parent56c114e51e6cd74719bdfd90f160eb6220f63ae6 (diff)
openpgp: Embed struct Container in the container packets.
- This allows us to implement PartialEq and related traits more selectively. See #93.
Diffstat (limited to 'openpgp/src/packet_pile.rs')
-rw-r--r--openpgp/src/packet_pile.rs29
1 files changed, 9 insertions, 20 deletions
diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs
index 5b548de1..c3f95625 100644
--- a/openpgp/src/packet_pile.rs
+++ b/openpgp/src/packet_pile.rs
@@ -126,7 +126,7 @@ impl PacketPile {
if *i < c.packets.len() {
let p = &c.packets[*i];
packet = Some(p);
- cont = p.children_ref();
+ cont = p.container_ref();
continue;
}
}
@@ -156,7 +156,7 @@ impl PacketPile {
return Some(p)
}
- container = p.children_mut().unwrap();
+ container = p.container_mut().unwrap();
}
None
@@ -243,20 +243,10 @@ impl PacketPile {
return Err(Error::IndexOutOfRange.into());
}
- let p = &mut tmp.packets[i];
- if p.children_ref().is_none() {
- match p {
- Packet::CompressedData(_)
- | Packet::SEIP(_)
- | Packet::AED(_)
- => (), // Ok.
- _ => {
- return Err(Error::IndexOutOfRange.into());
- }
- }
- }
-
- container = p.children_mut().unwrap();
+ container = match tmp.packets[i].container_mut() {
+ Some(c) => c,
+ None => return Err(Error::IndexOutOfRange.into()),
+ };
}
return Err(Error::IndexOutOfRange.into());
@@ -331,7 +321,7 @@ impl PacketPile {
let packets_len = tmp.packets.len();
let p = &mut tmp.packets[packets_len - 1];
- container = p.children_mut().unwrap();
+ container = p.container_mut().unwrap();
}
if relative_position < 0 {
@@ -346,8 +336,7 @@ impl PacketPile {
// Create a new container.
let tmp = container;
let i = tmp.packets.len() - 1;
- assert!(tmp.packets[i].children_ref().is_none());
- container = tmp.packets[i].children_mut().unwrap();
+ container = tmp.packets[i].container_mut().unwrap();
}
container.packets.push(packet);
@@ -638,7 +627,7 @@ mod test {
}
let mut seip = SEIP1::new();
- seip.children_mut().unwrap().push(cd.into());
+ seip.container_mut().push(cd.into());
packets.push(seip.into());
eprintln!("{:#?}", packets);