diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-03-26 17:21:32 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-03-26 17:21:32 +0100 |
commit | 89337646884b59c894329432eea960be4b3e335e (patch) | |
tree | 349136c28ee05b1ba71773c3ff8b1a0d7e2865a2 /openpgp/src/message | |
parent | e26c4d5a8fb582ec2a3c4c373536913aa2d0a468 (diff) |
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.
Diffstat (limited to 'openpgp/src/message')
-rw-r--r-- | openpgp/src/message/mod.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/openpgp/src/message/mod.rs b/openpgp/src/message/mod.rs index 1e3f3e69..dce7f11a 100644 --- a/openpgp/src/message/mod.rs +++ b/openpgp/src/message/mod.rs @@ -386,9 +386,7 @@ impl Message { // we treat the content as an opaque message. path.push(0); - if packet.children().next().is_none() - && packet.body().is_some() - { + if packet.children().is_none() { v.push_token(Token::OpaqueContent, &path); } } @@ -1003,9 +1001,9 @@ mod tests { // 1: MDC // => good. let mut seip = SEIP1::new(); - seip.children_mut().push( + seip.children_mut().unwrap().push( lit.clone().into()); - seip.children_mut().push( + seip.children_mut().unwrap().push( MDC::from([0u8; 20]).into()); packets[1] = seip.into(); @@ -1086,7 +1084,7 @@ mod tests { // => bad. packets.remove(3); packets[2].container_mut().unwrap() - .children_mut().push(lit.clone().into()); + .children_mut().unwrap().push(lit.clone().into()); assert!(packets.iter().map(|p| p.tag()).collect::<Vec<Tag>>() == [ Tag::SKESK, Tag::SKESK, Tag::SEIP ]); @@ -1100,7 +1098,8 @@ mod tests { // 2: SEIP // 0: Literal // => good. - packets[2].container_mut().unwrap().children_mut().pop().unwrap(); + packets[2].container_mut().unwrap() + .children_mut().unwrap().pop().unwrap(); #[allow(deprecated)] packets.insert( |