diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-04-09 16:42:59 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-04-09 18:18:30 +0200 |
commit | 2e1eec5fe4157a391a13554ff7df3075cfe043cc (patch) | |
tree | 03ac579ba58d27c08a7ac16ca16f687d1a9456ed /tool | |
parent | c1516c59709fa47d13100daddb57657008a793c3 (diff) |
openpgp: Make PacketParserResult a std::result::Result.
- This avoids the partial implementation imitating
std::option::Option, replacing it with std::result::Result.
- As a benefit, std::result::Result is in the prelude, simplifying a
lot of parsing loops.
Diffstat (limited to 'tool')
-rw-r--r-- | tool/src/commands/decrypt.rs | 5 | ||||
-rw-r--r-- | tool/src/commands/dump.rs | 6 | ||||
-rw-r--r-- | tool/src/commands/inspect.rs | 6 | ||||
-rw-r--r-- | tool/src/commands/mod.rs | 6 | ||||
-rw-r--r-- | tool/src/commands/sign.rs | 7 |
5 files changed, 14 insertions, 16 deletions
diff --git a/tool/src/commands/decrypt.rs b/tool/src/commands/decrypt.rs index ddfa2a5c..b6d27aa2 100644 --- a/tool/src/commands/decrypt.rs +++ b/tool/src/commands/decrypt.rs @@ -15,8 +15,7 @@ use crate::openpgp::packet::prelude::*; use crate::openpgp::parse::{ Parse, PacketParser, - PacketParserResult, -}; + }; use crate::openpgp::parse::stream::{ VerificationHelper, DecryptionHelper, Decryptor, MessageStructure, }; @@ -312,7 +311,7 @@ pub fn decrypt_unwrap(ctx: &Context, policy: &dyn Policy, let mut pkesks: Vec<packet::PKESK> = Vec::new(); let mut skesks: Vec<packet::SKESK> = Vec::new(); - while let PacketParserResult::Some(mut pp) = ppr { + while let Ok(mut pp) = ppr { let sym_algo_hint = if let Packet::AED(ref aed) = pp.packet { Some(aed.symmetric_algo()) } else { diff --git a/tool/src/commands/dump.rs b/tool/src/commands/dump.rs index 53c84fd6..8156f853 100644 --- a/tool/src/commands/dump.rs +++ b/tool/src/commands/dump.rs @@ -10,7 +10,7 @@ use self::openpgp::packet::header::CTB; use self::openpgp::packet::{Header, header::BodyLength, Signature}; use self::openpgp::packet::signature::subpacket::{Subpacket, SubpacketValue}; use self::openpgp::crypto::{SessionKey, S2K}; -use self::openpgp::parse::{map::Map, Parse, PacketParserResult}; +use self::openpgp::parse::{map::Map, Parse}; #[derive(Debug)] pub enum Kind { @@ -65,7 +65,7 @@ pub fn dump<W>(input: &mut dyn io::Read, output: &mut dyn io::Write, let width = width.into().unwrap_or(80); let mut dumper = PacketDumper::new(width, mpis); - while let PacketParserResult::Some(mut pp) = ppr { + while let Ok(mut pp) = ppr { let additional_fields = match pp.packet { Packet::Literal(_) => { let mut prefix = vec![0; 40]; @@ -147,7 +147,7 @@ pub fn dump<W>(input: &mut dyn io::Read, output: &mut dyn io::Write, dumper.flush(output)?; - if let PacketParserResult::EOF(eof) = ppr { + if let Err(eof) = ppr { if eof.is_message().is_ok() { Ok(Kind::Message { encrypted: message_encrypted, diff --git a/tool/src/commands/inspect.rs b/tool/src/commands/inspect.rs index 43e3d262..ff0b2571 100644 --- a/tool/src/commands/inspect.rs +++ b/tool/src/commands/inspect.rs @@ -6,7 +6,7 @@ extern crate sequoia_openpgp as openpgp; use crate::openpgp::{Packet, Result}; use crate::openpgp::cert::prelude::*; use openpgp::packet::key::PublicParts; -use crate::openpgp::parse::{Parse, PacketParserResult}; +use crate::openpgp::parse::Parse; use crate::openpgp::policy::Policy; use super::dump::Convert; @@ -30,7 +30,7 @@ pub fn inspect(m: &clap::ArgMatches, policy: &dyn Policy, output: &mut dyn io::W let mut ppr = openpgp::parse::PacketParser::from_reader(crate::open_or_stdin(input)?)?; - while let PacketParserResult::Some(mut pp) = ppr { + while let Ok(mut pp) = ppr { match pp.packet { Packet::PublicKey(_) | Packet::SecretKey(_) => { if pp.possible_cert().is_err() @@ -73,7 +73,7 @@ pub fn inspect(m: &clap::ArgMatches, policy: &dyn Policy, output: &mut dyn io::W } } - if let PacketParserResult::EOF(eof) = ppr { + if let Err(eof) = ppr { let is_message = eof.is_message(); let is_cert = eof.is_cert(); let is_keyring = eof.is_keyring(); diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs index fa8ed857..71f7aa85 100644 --- a/tool/src/commands/mod.rs +++ b/tool/src/commands/mod.rs @@ -426,7 +426,7 @@ pub fn split(input: &mut dyn io::Read, prefix: &str) // This encodes our position in the tree. let mut pos = vec![0]; - while let PacketParserResult::Some(pp) = ppr { + while let Ok(pp) = ppr { if let Some(ref map) = pp.map() { let filename = format!( "{}{}--{}{:?}", prefix, @@ -445,7 +445,7 @@ pub fn split(input: &mut dyn io::Read, prefix: &str) let old_depth = Some(pp.recursion_depth()); ppr = pp.recurse()?.1; - let new_depth = ppr.as_ref().map(|pp| pp.recursion_depth()); + let new_depth = ppr.as_ref().ok().map(|pp| pp.recursion_depth()); // Update pos. match old_depth.cmp(&new_depth) { @@ -468,7 +468,7 @@ pub fn join(inputs: Option<clap::Values>, output: &mut dyn io::Write) /// OUTPUT. fn copy(mut ppr: PacketParserResult, output: &mut dyn io::Write) -> Result<()> { - while let PacketParserResult::Some(pp) = ppr { + while let Ok(pp) = ppr { // We (ab)use the mapping feature to create byte-accurate // copies. for field in pp.map().expect("must be mapped").iter() { diff --git a/tool/src/commands/sign.rs b/tool/src/commands/sign.rs index 9a8e6819..3996a3ba 100644 --- a/tool/src/commands/sign.rs +++ b/tool/src/commands/sign.rs @@ -11,7 +11,6 @@ use crate::openpgp::{Packet, Result}; use crate::openpgp::packet::Signature; use crate::openpgp::parse::{ Parse, - PacketParserResult, }; use crate::openpgp::serialize::Serialize; use crate::openpgp::serialize::stream::{ @@ -53,7 +52,7 @@ fn sign_data(policy: &dyn Policy, let mut ppr = openpgp::parse::PacketParser::from_file(output_path.unwrap())?; - while let PacketParserResult::Some(pp) = ppr { + while let Ok(pp) = ppr { let (packet, ppr_tmp) = pp.recurse()?; ppr = ppr_tmp; @@ -198,7 +197,7 @@ fn sign_message_(policy: &dyn Policy, State::AfterFirstSigGroup }; - while let PacketParserResult::Some(mut pp) = ppr { + while let Ok(mut pp) = ppr { if let Err(err) = pp.possible_message() { return Err(err.context("Malformed OpenPGP message").into()); } @@ -330,7 +329,7 @@ fn sign_message_(policy: &dyn Policy, } } - if let PacketParserResult::EOF(eof) = ppr { + if let Err(eof) = ppr { if let Err(err) = eof.is_message() { return Err(err.context("Malformed OpenPGP message").into()); } |