summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2017-12-11 22:30:47 +0100
committerNeal H. Walfield <neal@pep.foundation>2017-12-11 22:30:47 +0100
commit97b11c2b633f67df659a7c2965dc2ac9535214a2 (patch)
tree3a012e030f87a078f348a7ba6475b55759105ac1 /src
parent21bfc0fba28916aa7f0af7b0237158b766ab53b9 (diff)
Add an "unknown" packet.
- If a packet is unsupported, instead of failing, we create a special unknown packet.
Diffstat (limited to 'src')
-rw-r--r--src/openpgp/openpgp.rs8
-rw-r--r--src/openpgp/parse/parse.rs25
2 files changed, 27 insertions, 6 deletions
diff --git a/src/openpgp/openpgp.rs b/src/openpgp/openpgp.rs
index 9df0d0e7..9f8639f2 100644
--- a/src/openpgp/openpgp.rs
+++ b/src/openpgp/openpgp.rs
@@ -189,6 +189,11 @@ pub struct Header {
length: BodyLength,
}
+#[derive(PartialEq,Debug)]
+pub struct Unknown {
+ common: PacketCommon,
+}
+
#[derive(PartialEq)]
pub struct Signature {
common: PacketCommon,
@@ -368,6 +373,7 @@ impl std::fmt::Debug for CompressedData {
#[derive(Debug)]
#[derive(PartialEq)]
pub enum Packet {
+ Unknown(Unknown),
Signature(Signature),
PublicKey(Key),
PublicSubkey(Key),
@@ -384,6 +390,7 @@ impl<'a> Deref for Packet {
fn deref(&self) -> &Self::Target {
match self {
+ &Packet::Unknown(ref packet) => &packet.common,
&Packet::Signature(ref packet) => &packet.common,
&Packet::PublicKey(ref packet) => &packet.common,
&Packet::PublicSubkey(ref packet) => &packet.common,
@@ -399,6 +406,7 @@ impl<'a> Deref for Packet {
impl<'a> DerefMut for Packet {
fn deref_mut(&mut self) -> &mut PacketCommon {
match self {
+ &mut Packet::Unknown(ref mut packet) => &mut packet.common,
&mut Packet::Signature(ref mut packet) => &mut packet.common,
&mut Packet::PublicKey(ref mut packet) => &mut packet.common,
&mut Packet::PublicSubkey(ref mut packet) => &mut packet.common,
diff --git a/src/openpgp/parse/parse.rs b/src/openpgp/parse/parse.rs
index 9708cd00..16af1098 100644
--- a/src/openpgp/parse/parse.rs
+++ b/src/openpgp/parse/parse.rs
@@ -174,6 +174,22 @@ fn header<R: BufferedReader> (bio: &mut R)
return Ok(Header { ctb: ctb, length: length });
}
+fn unknown_parser<'a, R: BufferedReader + 'a>(bio: R)
+ -> Result<PacketParser<'a>, std::io::Error> {
+ return Ok(PacketParser {
+ packet: Packet::Unknown(Unknown {
+ common: PacketCommon {
+ tag: Tag::Signature,
+ children: None,
+ content: None,
+ },
+ }),
+ reader: Box::new(bio),
+ recursion_depth: 0,
+ max_recursion_depth: MAX_RECURSION_DEPTH,
+ });
+}
+
fn signature_parser<'a, R: BufferedReader + 'a>(mut bio: R)
-> Result<PacketParser<'a>, std::io::Error> {
let version = bio.data_consume_hard(1)?[0];
@@ -607,11 +623,8 @@ impl <'a> PacketParser<'a> {
literal_parser(bio)?,
Tag::CompressedData =>
compressed_data_parser(bio)?,
- _ => {
- // XXX: Return an "unknown" packet instead of erroring out.
- eprintln!("Unsupported packet type: {:?}", header);
- return Err(Error::new(ErrorKind::UnexpectedEof, "EOF"));
- },
+ _ =>
+ unknown_parser(bio)?,
};
return Ok(PacketParserOrBufferedReader::PacketParser(result));
@@ -715,7 +728,7 @@ impl <'a> PacketParser<'a> {
}
},
// Packets that don't recurse.
- Packet::Signature(_)
+ Packet::Unknown(_) | Packet::Signature(_)
| Packet::PublicKey(_) | Packet::PublicSubkey(_)
| Packet::SecretKey(_) | Packet::SecretSubkey(_)
| Packet::UserID(_) | Packet::Literal(_) => {