Skip to content

dump: walk multiple armored messages in --list-packets (#2036) - #2429

Merged
ronaldtse merged 1 commit into
mainfrom
list-packets-parity
Aug 30, 2026
Merged

dump: walk multiple armored messages in --list-packets (#2036)#2429
ronaldtse merged 1 commit into
mainfrom
list-packets-parity

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

Fixes #2036. The packet dumper now walks all armored messages in inputs that contain more than one, instead of stopping after the first.

Root cause

DumpContextDst::dump() and DumpContextJson::dump() used init_armored_src() which reads exactly one armor block and reports EOF at the -----END ...----- line. Inputs like data/test_stream_key_merge/key-both.asc (public keys in the first block, secret keys in the second) silently dropped everything after the first block.

The fix is the same pattern already used by process_pgp_signatures() and the key loader: rnp::ArmoredSource constructed with AllowBinary | AllowMultiple, then loop on armor.eof() && armor.multiple()armor.restart().

Behaviour change

Before:

:armored input
:off 0: packet header 0x99... (tag 6, len 397)    ← public key only
...                                                 ← secret-key block silently dropped

After:

:armored input
:off 0: packet header 0x99... (tag 6, len 397)     ← public key
...
:off 0: packet header 0x95... (tag 5, len 1414)    ← secret key now dumped
:off 1417: packet header 0xb4... (tag 13, len 15)  ← secret-block UID
...

Output now matches gpg --list-packets on the same fixture (modulo intentional formatting differences).

Test plan

  • test_ffi_dump_multiple_armored_messages (new) — covers both the text and JSON dumpers; asserts Secret key packet / Secret subkey packet appear in the output and "tag":5 / "tag":7 appear in the JSON
  • test_ffi_key_dump, test_ffi_key_dump_edge_cases, test_ffi_signatures_dump — no regression
  • Manually compared ./rnp --list-packets src/tests/data/test_stream_key_merge/key-both.asc to the gpg dump attached to issue rnp --list-packets dumps fewer packets than gpg --list-packets from the same source #2036 — same number of packets, same types
  • CI green

Out of scope

Issue #2036 also mentions a broader audit (vendor subpackets, partial-length packets, PQC messages). This PR is scoped to the specific bug the maintainer identified in the issue thread (multiple armored messages). The broader audit belongs in follow-up PRs and intersects with #13 (Photo ID) for one of the gap categories.

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.93939% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.46%. Comparing base (87657a6) to head (9427b81).

Files with missing lines Patch % Lines
src/librepgp/stream-dump.cpp 93.93% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2429      +/-   ##
==========================================
+ Coverage   85.44%   85.46%   +0.01%     
==========================================
  Files         125      125              
  Lines       22946    22962      +16     
==========================================
+ Hits        19607    19625      +18     
+ Misses       3339     3337       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ronaldtse
ronaldtse requested review from antonsviridenko and ni4 July 31, 2026 16:20
@ronaldtse
ronaldtse force-pushed the list-packets-parity branch from 3f7e6a0 to 5ad5eb1 Compare August 10, 2026 02:09
@ronaldtse
ronaldtse force-pushed the list-packets-parity branch 4 times, most recently from a869763 to 7c6b40a Compare August 23, 2026 11:34
@ronaldtse
ronaldtse changed the base branch from main to replace-json-c-with-nlohmann August 23, 2026 11:34
@ronaldtse

Copy link
Copy Markdown
Contributor Author

Retargeted onto #2439 (json-c → nlohmann): the multi-armor dump walk is now implemented with nlohmann on top of the migration, instead of json-c APIs that this stack removes. The diff here is now a single commit on top of #2439. Merge order: #2439 → this PR (and #2448, which is also stacked on it).

The nlohmann version is also simpler — merging each armored block's packets into one array no longer needs refcount juggling.

@ni4 ni4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@ronaldtse
ronaldtse force-pushed the replace-json-c-with-nlohmann branch from 13f2dfa to 871fe76 Compare August 29, 2026 01:42
@ronaldtse
ronaldtse force-pushed the list-packets-parity branch from 7c6b40a to 9f1b8c8 Compare August 29, 2026 01:43
@ronaldtse
ronaldtse changed the base branch from replace-json-c-with-nlohmann to main August 30, 2026 16:15
@ronaldtse
ronaldtse force-pushed the list-packets-parity branch from f060656 to 9f1b8c8 Compare August 30, 2026 16:17
Reimplemented on top of the nlohmann/json migration: a single input
file with several armored OpenPGP messages now dumps all of them, for
both the text and the JSON dumper, instead of silently dropping
everything after the first -----END--- marker. Merging each block's
packets into one array no longer needs json-c refcount juggling.
@ronaldtse
ronaldtse force-pushed the list-packets-parity branch from 9f1b8c8 to 9427b81 Compare August 30, 2026 16:18
@ronaldtse
ronaldtse merged commit ce33cc6 into main Aug 30, 2026
176 of 179 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rnp --list-packets dumps fewer packets than gpg --list-packets from the same source

2 participants