diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-05-11 16:27:47 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-05-11 16:30:00 +0200 |
commit | 4fd637775c0d66206ddf2e6652fe8402469bb7ee (patch) | |
tree | b6a4e43f56219d1e24ebe660cd9a1168d20b2453 /tool | |
parent | 4eceddecaf175c81f7fe7372ddb1c5116ee1bea2 (diff) |
tool: Allow hex-dumping when decrypting data.
Diffstat (limited to 'tool')
-rw-r--r-- | tool/src/cli.rs | 6 | ||||
-rw-r--r-- | tool/src/commands.rs | 25 | ||||
-rw-r--r-- | tool/src/main.rs | 4 | ||||
-rw-r--r-- | tool/src/usage.rs | 2 |
4 files changed, 27 insertions, 10 deletions
diff --git a/tool/src/cli.rs b/tool/src/cli.rs index 468d2438..26a8ecb8 100644 --- a/tool/src/cli.rs +++ b/tool/src/cli.rs @@ -29,7 +29,11 @@ pub fn build() -> App<'static, 'static> { .help("Remove ASCII Armor from input")) .arg(Arg::with_name("dump") .long("dump") - .help("Print a packet dump to stderr"))) + .help("Print a packet dump to stderr")) + .arg(Arg::with_name("hex") + .long("hex") + .short("x") + .help("Print a hexdump (implies --dump)"))) .subcommand(SubCommand::with_name("enarmor") .about("Applies ASCII Armor to a file") .arg(Arg::with_name("input").value_name("FILE") diff --git a/tool/src/commands.rs b/tool/src/commands.rs index a4db1c85..53df3e2b 100644 --- a/tool/src/commands.rs +++ b/tool/src/commands.rs @@ -9,7 +9,8 @@ use openpgp::{Packet, Tag}; const INDENT: &'static str = " "; -pub fn decrypt(input: &mut io::Read, output: &mut io::Write, dump: bool) +pub fn decrypt(input: &mut io::Read, output: &mut io::Write, + dump: bool, map: bool) -> Result<(), failure::Error> { #[derive(PartialEq)] enum State { @@ -19,9 +20,24 @@ pub fn decrypt(input: &mut io::Read, output: &mut io::Write, dump: bool) Done, } let mut state = State::Start; - let mut ppo = openpgp::parse::PacketParser::from_reader(input)?; + let mut ppo + = openpgp::parse::PacketParserBuilder::from_reader(input)? + .map(map).finalize()?; while let Some(mut pp) = ppo { + if dump || map { + eprintln!("{}{:?}", + &INDENT[0..pp.recursion_depth as usize], pp.packet); + } + + if let Some(ref map) = pp.map { + let mut hd = HexDumper::new(); + for (field, bytes) in map.iter() { + hd.print(bytes, field); + } + println!(); + } + state = match state { // Look for an PKESK or SKESK packet. State::Start => @@ -72,11 +88,6 @@ pub fn decrypt(input: &mut io::Read, output: &mut io::Write, dump: bool) State::Done => State::Done, }; - if dump { - eprintln!("{}{:?}", - &INDENT[0..pp.recursion_depth as usize], pp.packet); - } - let (_, _, ppo_tmp, _) = pp.recurse()?; ppo = ppo_tmp; } diff --git a/tool/src/main.rs b/tool/src/main.rs index 5b14e469..50eab105 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -61,7 +61,6 @@ fn real_main() -> Result<(), failure::Error> { match matches.subcommand() { ("decrypt", Some(m)) => { - let dump = m.is_present("dump"); let mut input = open_or_stdin(m.value_of("input"))?; let mut output = create_or_stdout(m.value_of("output"))?; let mut input = if m.is_present("dearmor") { @@ -69,7 +68,8 @@ fn real_main() -> Result<(), failure::Error> { } else { input }; - commands::decrypt(&mut input, &mut output, dump)?; + commands::decrypt(&mut input, &mut output, + m.is_present("dump"), m.is_present("hex"))?; }, ("enarmor", Some(m)) => { let mut input = open_or_stdin(m.value_of("input"))?; diff --git a/tool/src/usage.rs b/tool/src/usage.rs index 81ae0f07..b0c76132 100644 --- a/tool/src/usage.rs +++ b/tool/src/usage.rs @@ -56,6 +56,7 @@ //! -A, --dearmor Remove ASCII Armor from input //! --dump Print a packet dump to stderr //! -h, --help Prints help information +//! -x, --hex Print a hexdump (implies --dump) //! -V, --version Prints version information //! //! OPTIONS: @@ -74,6 +75,7 @@ //! FLAGS: //! -A, --dearmor Remove ASCII Armor from input //! -h, --help Prints help information +//! -x, --hex Print a hexdump //! -V, --version Prints version information //! //! OPTIONS: |