diff options
author | Neal H. Walfield <neal@pep.foundation> | 2019-05-11 14:48:09 +0200 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2019-05-11 14:48:09 +0200 |
commit | 5a2688066b934f73ff4e69640f2bc47211a84451 (patch) | |
tree | bc7c83efc28b9df3cfb8b0b1bf0198be623ffcaa /tool | |
parent | ccaccf692688451e984e75b2d020a7077dc15546 (diff) |
openpgp: Make {is,possible}_{message,keyring,tpk} return a Result
- PacketParserEOF::is_message, PacketParserEOF::is_keyring,
PacketParserEOF::is_tpk, PacketParserResult::possible_message,
PacketParserResult::possible_keyring, and
PacketParserResult::possible_tpk returned a boolean.
- Change them to return a Result<()> instead, which is more Rusty,
and, in particular, allows the caller to determine why the message
didn't parse.
Diffstat (limited to 'tool')
-rw-r--r-- | tool/src/commands/inspect.rs | 10 | ||||
-rw-r--r-- | tool/src/commands/sign.rs | 12 |
2 files changed, 11 insertions, 11 deletions
diff --git a/tool/src/commands/inspect.rs b/tool/src/commands/inspect.rs index 0ba21dd9..84e66520 100644 --- a/tool/src/commands/inspect.rs +++ b/tool/src/commands/inspect.rs @@ -31,7 +31,9 @@ pub fn inspect(m: &clap::ArgMatches, output: &mut io::Write) while let PacketParserResult::Some(mut pp) = ppr { match pp.packet { Packet::PublicKey(_) | Packet::SecretKey(_) => { - if ! pp.possible_tpk() && pp.possible_keyring() { + if pp.possible_tpk().is_err() + && pp.possible_keyring().is_ok() + { if ! type_called { writeln!(output, "OpenPGP Keyring.")?; writeln!(output)?; @@ -53,7 +55,7 @@ pub fn inspect(m: &clap::ArgMatches, output: &mut io::Write) _ => (), } - let possible_keyring = pp.possible_keyring(); + let possible_keyring = pp.possible_keyring().is_ok(); let (packet, ppr_) = pp.recurse()?; ppr = ppr_; @@ -70,7 +72,7 @@ pub fn inspect(m: &clap::ArgMatches, output: &mut io::Write) } if let PacketParserResult::EOF(eof) = ppr { - if eof.is_message() { + if eof.is_message().is_ok() { writeln!(output, "{}OpenPGP Message.", match (encrypted, ! sigs.is_empty()) { (false, false) => "", @@ -92,7 +94,7 @@ pub fn inspect(m: &clap::ArgMatches, output: &mut io::Write) if literal_prefix.len() == 40 { "..." } else { "" })?; } - } else if eof.is_tpk() || eof.is_keyring() { + } else if eof.is_tpk().is_ok() || eof.is_keyring().is_ok() { let pp = openpgp::PacketPile::from(packets); let tpk = openpgp::TPK::from_packet_pile(pp)?; inspect_tpk(output, &tpk, print_keygrips, print_certifications)?; diff --git a/tool/src/commands/sign.rs b/tool/src/commands/sign.rs index bcead074..f527f3a7 100644 --- a/tool/src/commands/sign.rs +++ b/tool/src/commands/sign.rs @@ -8,7 +8,7 @@ extern crate sequoia_openpgp as openpgp; use openpgp::armor; use openpgp::constants::DataFormat; use openpgp::crypto; -use openpgp::{Packet, Error, Result}; +use openpgp::{Packet, Result}; use openpgp::packet::Signature; use openpgp::parse::{ Parse, @@ -179,9 +179,8 @@ fn sign_message(input: &mut io::Read, output_path: Option<&str>, }; while let PacketParserResult::Some(mut pp) = ppr { - if ! pp.possible_message() { - return Err(Error::MalformedMessage( - "Malformed OpenPGP message".into()).into()); + if let Err(err) = pp.possible_message() { + return Err(err.context("Malformed OpenPGP message").into()); } match pp.packet { @@ -301,9 +300,8 @@ fn sign_message(input: &mut io::Read, output_path: Option<&str>, } if let PacketParserResult::EOF(eof) = ppr { - if ! eof.is_message() { - return Err(Error::MalformedMessage( - "Malformed OpenPGP message".into()).into()); + if let Err(err) = eof.is_message() { + return Err(err.context("Malformed OpenPGP message").into()); } } else { unreachable!() |