diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-02-13 15:45:57 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-02-13 15:45:57 +0100 |
commit | ca912da838bca40a2e008264a2c8c339a62df483 (patch) | |
tree | 094eb6340f0f9549c6cc9853c2780e668f64ca97 | |
parent | 2215071e140dd439d37fcbad1a57b7f04ac7ee02 (diff) |
openpgp: Improve handling of soft parsing errors.
- When we skip bytes, communicate the fact using the error embedded
in the Unknown packet.
- Fixes #41.
-rw-r--r-- | openpgp/src/parse/parse.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs index 11cd93eb..2e87094a 100644 --- a/openpgp/src/parse/parse.rs +++ b/openpgp/src/parse/parse.rs @@ -2961,7 +2961,7 @@ impl <'a> PacketParser<'a> { let consumed = if skip == 0 { bio.total_out() } else { - t!("turning {} bytes of junk into a Reserved packet", skip); + t!("turning {} bytes of junk into an Unknown packet", skip); // Fabricate a header. header = Header { @@ -3038,6 +3038,9 @@ impl <'a> PacketParser<'a> { Tag::MDC => MDC::parse(parser), Tag::PKESK => PKESK::parse(parser), Tag::AED => AED::parse(parser), + Tag::Reserved if skip > 0 => Unknown::parse( + parser, Error::MalformedPacket(format!( + "Skipped {} bytes of junk", skip)).into()), _ => Unknown::parse(parser, Error::UnsupportedPacketType(tag).into()), }?; @@ -4210,7 +4213,11 @@ mod test { Packet::PublicSubkey(_) => subkeys += 1, Packet::UserID(_) => userids += 1, Packet::UserAttribute(_) => uas += 1, - Packet::Unknown(_) => unknown += 1, + Packet::Unknown(ref u) => { + unknown += 1; + assert_match!(Some(&Error::MalformedPacket(_)) + = u.error().downcast_ref()); + }, _ => (), } |