diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-12-19 17:08:05 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-12-20 18:04:56 +0100 |
commit | e8b55c27a98a332dd69113e3c07e98cbbce8bb7b (patch) | |
tree | 4eae88561988f41545698cc42411454952003970 /openpgp/src/parse | |
parent | 56c114e51e6cd74719bdfd90f160eb6220f63ae6 (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/parse')
-rw-r--r-- | openpgp/src/parse/packet_pile_parser.rs | 2 | ||||
-rw-r--r-- | openpgp/src/parse/parse.rs | 38 |
2 files changed, 34 insertions, 6 deletions
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""[..]) } |