summaryrefslogtreecommitdiffstats
path: root/tool
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2018-07-02 11:00:00 +0200
committerNeal H. Walfield <neal@pep.foundation>2018-07-02 11:08:39 +0200
commitc9ee0ac8d7689aca241b9b117749a6faf4923676 (patch)
treede1b416db32a46c1edeae16d59f52596440185e9 /tool
parent36c99d079120607a048284345d4ded09137615de (diff)
openpgp: Create a special Option-like type for PacketParser.
- In the future, we want to return some summary information about a parsed packet sequence after the packet sequence is fully parsed. Currently, PacketParser::next() and PacketParser::recurse() consume the PacketParser and return None on EOF. Thus, even if the summary information were stored in the PacketParser, it becomes inaccessible on EOF. - This change introduces a new type, PacketParserResult, that contains either a PacketParser or a PacketParserEOF. PacketParserEOF is returned on EOF instead of None. Since it is a struct, it can hold only any information that we want to return to the caller.
Diffstat (limited to 'tool')
-rw-r--r--tool/src/commands.rs25
-rw-r--r--tool/src/sqv.rs10
2 files changed, 18 insertions, 17 deletions
diff --git a/tool/src/commands.rs b/tool/src/commands.rs
index a262a7c6..95f5b2ea 100644
--- a/tool/src/commands.rs
+++ b/tool/src/commands.rs
@@ -7,6 +7,7 @@ use rpassword;
extern crate openpgp;
use openpgp::Packet;
use openpgp::packet::Tag;
+use openpgp::parse::PacketParserResult;
use openpgp::serialize::stream::{
wrap, LiteralWriter, Encryptor, EncryptionMode,
};
@@ -26,11 +27,11 @@ pub fn decrypt(input: &mut io::Read, output: &mut io::Write,
Done,
}
let mut state = State::Start(vec![], vec![]);
- let mut ppo
+ let mut ppr
= openpgp::parse::PacketParserBuilder::from_reader(input)?
.map(map).finalize()?;
- while let Some(mut pp) = ppo {
+ while let PacketParserResult::Some(mut pp) = ppr {
if dump || map {
eprintln!("{}{:?}",
&INDENT[0..pp.recursion_depth as usize], pp.packet);
@@ -89,8 +90,8 @@ pub fn decrypt(input: &mut io::Read, output: &mut io::Write,
State::Done => State::Done,
};
- let (packet, _, ppo_tmp, _) = pp.recurse()?;
- ppo = ppo_tmp;
+ let (packet, _, ppr_tmp, _) = pp.recurse()?;
+ ppr = ppr_tmp;
state = match state {
// Look for an PKESK or SKESK packet.
@@ -165,11 +166,11 @@ pub fn encrypt(store: &mut store::Store,
pub fn dump(input: &mut io::Read, output: &mut io::Write, map: bool)
-> Result<(), failure::Error> {
- let mut ppo
+ let mut ppr
= openpgp::parse::PacketParserBuilder::from_reader(input)?
.map(map).finalize()?;
- while let Some(mut pp) = ppo {
+ while let PacketParserResult::Some(mut pp) = ppr {
if let Some(ref map) = pp.map {
let mut hd = HexDumper::new();
writeln!(output, "{}{:?}\n",
@@ -190,8 +191,8 @@ pub fn dump(input: &mut io::Read, output: &mut io::Write, map: bool)
&INDENT[0..pp.recursion_depth as usize], pp.packet)?;
}
- let (_, _, ppo_, _) = pp.recurse()?;
- ppo = ppo_;
+ let (_, _, ppr_, _) = pp.recurse()?;
+ ppr = ppr_;
}
Ok(())
}
@@ -200,14 +201,14 @@ pub fn split(input: &mut io::Read, prefix: &str)
-> Result<(), failure::Error> {
// We (ab)use the mapping feature to create byte-accurate dumps of
// nested packets.
- let mut ppo =
+ let mut ppr =
openpgp::parse::PacketParserBuilder::from_reader(input)?
.map(true).finalize()?;
// This encodes our position in the tree.
let mut pos = vec![0];
- while let Some(pp) = ppo {
+ while let PacketParserResult::Some(pp) = ppr {
if let Some(ref map) = pp.map {
let filename = format!(
"{}{}--{:?}", prefix,
@@ -223,8 +224,8 @@ pub fn split(input: &mut io::Read, prefix: &str)
}
}
- let (_, old_depth, ppo_, new_depth) = pp.recurse()?;
- ppo = ppo_;
+ let (_, old_depth, ppr_, new_depth) = pp.recurse()?;
+ ppr = ppr_;
// Update pos.
match old_depth.cmp(&new_depth) {
diff --git a/tool/src/sqv.rs b/tool/src/sqv.rs
index 67264f90..fe9c3a24 100644
--- a/tool/src/sqv.rs
+++ b/tool/src/sqv.rs
@@ -16,7 +16,7 @@ use clap::{App, Arg, AppSettings};
use openpgp::{TPK, Packet, Signature, KeyID};
use openpgp::constants::HashAlgorithm;
-use openpgp::parse::PacketParser;
+use openpgp::parse::{PacketParserResult, PacketParser};
use openpgp::tpk::TPKParser;
// The argument parser.
@@ -82,7 +82,7 @@ fn real_main() -> Result<(), failure::Error> {
// .unwrap() is safe, because "sig-file" is required.
let sig_file = matches.value_of_os("sig-file").unwrap();
- let mut ppo = PacketParser::from_reader(
+ let mut ppr = PacketParser::from_reader(
openpgp::Reader::from_file(sig_file)?)?;
let mut sigs : Vec<(Signature, KeyID, Option<TPK>)> = Vec::new();
@@ -92,7 +92,7 @@ fn real_main() -> Result<(), failure::Error> {
// sigs.
let mut sig_i = 0;
- while let Some(pp) = ppo {
+ while let PacketParserResult::Some(pp) = ppr {
match pp.packet {
Packet::Signature(ref sig) => {
sig_i += 1;
@@ -129,8 +129,8 @@ fn real_main() -> Result<(), failure::Error> {
}
}
- let (_packet_tmp, _, ppo_tmp, _) = pp.recurse().unwrap();
- ppo = ppo_tmp;
+ let (_packet_tmp, _, ppr_tmp, _) = pp.recurse().unwrap();
+ ppr = ppr_tmp;
}
if sigs.len() == 0 {