Improve packet stream & error handling#1856
Merged
twiss merged 13 commits intoopenpgpjs:mainfrom Jun 12, 2025
Merged
Conversation
Instead of ignoring non-critical unknown packets entirely, write an UnparseablePacket object to the packet stream.
Instead of signalling that grammar checking should be delayed for not-yet-authenticated streams on the grammar validator, signal that the stream is not yet authenticated on the stream object.
a629f83 to
730ef27
Compare
larabr
reviewed
May 23, 2025
| */ | ||
| export async function readPackets(input, callback) { | ||
| const reader = streamGetReader(input); | ||
| export async function readPacket(reader, useStreamType, callback) { |
Collaborator
There was a problem hiding this comment.
Can we simplify this further and have it return { tag, packet } instead of taking a callback?
Member
Author
There was a problem hiding this comment.
No, because we need to call the callback earlier than returning when streaming. The callback happens when we've parsed the packet header; the function returns when the whole packet has been read.
Collaborator
There was a problem hiding this comment.
Ok; I think it should be possible to return the header and some stream/promises for the rest tho. I'd like to look into this for the next major 🙂
63ff85c to
6d375a2
Compare
Co-authored-by: larabr <larabr+github@protonmail.com>
5641132 to
8f30bb1
Compare
Instead of checking the list of packets for every new packet, check the new packet given the state we've recorded from the previous packets.
8f30bb1 to
d94d9d4
Compare
To make the grammar checker less of a breaking change in v6. This should be reverted in v7.
Some invalid sequences were not detected after refactor
baf3116 to
e584eb7
Compare
e584eb7 to
1aedcbe
Compare
larabr
approved these changes
Jun 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor & simplify the handling of the packet stream and errors in packet parsing & grammar validation.
This PR also makes the following observable changes:
allowUnauthenticatedStream: true) get delayed until the decrypted data stream is authenticated (i.e. the MDC has been validated)UnparseablePacketobjects on the packet stream instead of being ignored