diff options
author | Neal H. Walfield <neal@pep.foundation> | 2018-07-02 11:00:00 +0200 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2018-07-02 11:08:39 +0200 |
commit | c9ee0ac8d7689aca241b9b117749a6faf4923676 (patch) | |
tree | de1b416db32a46c1edeae16d59f52596440185e9 /tool/src/sqv.rs | |
parent | 36c99d079120607a048284345d4ded09137615de (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/src/sqv.rs')
-rw-r--r-- | tool/src/sqv.rs | 10 |
1 files changed, 5 insertions, 5 deletions
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 { |