From 89337646884b59c894329432eea960be4b3e335e Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 26 Mar 2020 17:21:32 +0100 Subject: openpgp: Change packet bodies to be tristate. - Packet bodies can now be either unprocessed (e.g. compressed, encrypted), processed (e.g. uncompressed, decrypted), or structured (e.g. parsed into packets). - Make the container types deref to Container, and container deref to packet bodies. - This cleanly avoids the confusion when serializing containers: We can serialize compressed data packets with either body, but we can only serialize encryption containers with unprocessed bodies. - Fixes #187. --- openpgp/src/parse/packet_pile_parser.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'openpgp/src/parse/packet_pile_parser.rs') diff --git a/openpgp/src/parse/packet_pile_parser.rs b/openpgp/src/parse/packet_pile_parser.rs index 83fff632..f8c90543 100644 --- a/openpgp/src/parse/packet_pile_parser.rs +++ b/openpgp/src/parse/packet_pile_parser.rs @@ -131,9 +131,11 @@ impl<'a> PacketPileParser<'a> { for i in 0..position { // The most recent child. let tmp = container; - let packets_len = tmp.children_ref().len(); - let p = &mut tmp.children_mut()[packets_len - 1]; - if p.children().next().is_none() { + let packets_len = tmp.children_ref().expect("is a container").len(); + let p = &mut tmp.children_mut() + .expect("is a container") + [packets_len - 1]; + if p.children().expect("is a container").next().is_none() { assert!(i == position - 1, "Internal inconsistency while building message."); } @@ -141,7 +143,7 @@ impl<'a> PacketPileParser<'a> { container = p.container_mut().unwrap(); } - container.children_mut().push(packet); + container.children_mut().unwrap().push(packet); } /// Finishes parsing the current packet and starts parsing the -- cgit v1.2.3