From e8b55c27a98a332dd69113e3c07e98cbbce8bb7b Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 19 Dec 2019 17:08:05 +0100 Subject: openpgp: Embed struct Container in the container packets. - This allows us to implement PartialEq and related traits more selectively. See #93. --- openpgp/src/parse/packet_pile_parser.rs | 2 +- openpgp/src/parse/parse.rs | 38 ++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-) (limited to 'openpgp/src/parse') diff --git a/openpgp/src/parse/packet_pile_parser.rs b/openpgp/src/parse/packet_pile_parser.rs index 223b212b..8c6512a2 100644 --- a/openpgp/src/parse/packet_pile_parser.rs +++ b/openpgp/src/parse/packet_pile_parser.rs @@ -138,7 +138,7 @@ impl<'a> PacketPileParser<'a> { "Internal inconsistency while building message."); } - container = p.children_mut().unwrap(); + container = p.container_mut().unwrap(); } container.packets.push(packet); diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs index 3a3686a8..085b1108 100644 --- a/openpgp/src/parse/parse.rs +++ b/openpgp/src/parse/parse.rs @@ -3624,17 +3624,45 @@ impl <'a> PacketParser<'a> { Ok(p.body()) }, - p => { + Packet::CompressedData(p) => { + if rest.len() > 0 { + if p.body().map(|b| b.len()).unwrap_or(0) > 0 { + p.body_mut().unwrap().append(&mut rest); + } else { + p.set_body(rest); + } + } + + Ok(p.body().unwrap_or(&b""[..])) + }, + Packet::SEIP(p) => { if rest.len() > 0 { - if let Some(body) = p.body_mut() { - body.append(&mut rest); + if p.body().map(|b| b.len()).unwrap_or(0) > 0 { + p.body_mut().unwrap().append(&mut rest); } else { p.set_body(rest); } } - if let Some(body) = p.body() { - Ok(&body[..]) + Ok(p.body().unwrap_or(&b""[..])) + }, + Packet::AED(p) => { + if rest.len() > 0 { + if p.body().map(|b| b.len()).unwrap_or(0) > 0 { + p.body_mut().unwrap().append(&mut rest); + } else { + p.set_body(rest); + } + } + + Ok(p.body().unwrap_or(&b""[..])) + }, + p => { + if rest.len() > 0 { + Err(Error::MalformedPacket( + format!("Unexpected body data for {:?}: {}", + p, crate::fmt::hex::encode_pretty(rest))) + .into()) } else { Ok(&b""[..]) } -- cgit v1.2.3