Skip to content

Handling of raw for large SubpacketLengths

Nora Widdecke requested to merge large_subpackets into master

The current implementation of Subpacket::Arbitrary for signature subpackets does not take the size of the subpacket into account. This means the 2-byte and 5-byte encoding schemes for subpacket lengths are likely not reached in our tests (maximum size for an Arbitrary byte vector by default is 100, the threshold for 2-byte encoding is 192).

This turns up a problem with handling subpackets with length > 8383, (where the optimal encoding is actually 5-byte long) and where also the raw value of the SubpacketLength is set. The roundtrip test fails for such subpackets :/ This also came up (unrelated to this PR) here: https://gitlab.com/sequoia-pgp/sequoia/-/jobs/608805550. The input subpacket has raw = Some(...), while the output has raw = None.

I believe this is connected to the the meaning of the raw field. It's doc-comment says

/// Stores the raw bytes in case of suboptimal encoding.

Do we want "in case of" to mean "if and only if"? Then SubpacketLenghts which require 5-byte encoding should never have raw = Some(...), which should probably be ensured when creating a SubpacketLength.

On the other hand, we could also change the implementation of Eq for SubpacketLengths to ignore the raw field if the actual encoding is the same anyway.

What do you think?

Merge request reports