diff options
author | Neal H. Walfield <neal@pep.foundation> | 2017-12-24 23:04:06 +0100 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2017-12-24 23:04:06 +0100 |
commit | 0528165a8c5aa96a85b52ef9ab2a8c855476e090 (patch) | |
tree | 2ad6a67ec492ed946b08df4af77eebb1db159b1b | |
parent | 217e7595584418e68c8c634533b72a59a76ee02d (diff) |
Revert "tools: Use a PacketParser to parse packets. Improve dumps output."
This reverts commit 217e7595584418e68c8c634533b72a59a76ee02d.
This commit was actually a part of
e0354af157e31421c2c65310b9f49d3f87d66814 and
217e7595584418e68c8c634533b72a59a76ee02d reverted it. Whoops.
-rw-r--r-- | tool/src/main.rs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/tool/src/main.rs b/tool/src/main.rs index 1d8a6b5f..c1a5f262 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -88,9 +88,28 @@ fn real_main() -> Result<(), io::Error> { } else { input }; - let m = openpgp::Message::from_reader(input); - for p in m.iter() { - writeln!(output, "{:?}", p).unwrap(); + + // Indent packets according to their recursion level. + let indent = " "; + + let mut ppo + = openpgp::parse::PacketParserBuilder::from_reader(input)? + .finalize()?; + while ppo.is_some() { + let mut pp = ppo.unwrap(); + + if let openpgp::Packet::Literal(_) = pp.packet { + // XXX: We should actually stream this. In fact, + // we probably only want to print out the first + // line or so and then print the total number of + // bytes. + pp.buffer_unread_content()?; + } + writeln!(output, "{}{:?}", + &indent[0..pp.recursion_depth as usize], pp.packet)?; + + let (_, _, ppo_tmp, _) = pp.recurse()?; + ppo = ppo_tmp; } }, _ => { |