der: order FlagSet by its BIT STRING encoding - #2451
Open
yuxi-liu-wired wants to merge 1 commit into
Open
yuxi-liu-wired wants to merge 1 commit into
yuxi-liu-wired wants to merge 1 commit into
Conversation
`ValueOrd for FlagSet<T>` compared `bits()` as an integer. The DER
encoding (a NamedBitList BIT STRING) puts flag 0 in the most significant
bit of the first octet and drops trailing zero bits, so the integer order
and the encoding order disagree, e.g. for a 9-flag set:
{A} bits 0x001 -> 03 02 07 80
{B} bits 0x002 -> 03 02 06 40 (sorts first in DER)
X.690 11.6 orders `SET OF` components by their encodings, so `SetOfVec`
of a type containing a `FlagSet` (e.g. x509-cert's `DistributionPoint`
with `reasons: Option<ReasonFlags>`) can encode out of DER order.
Compare the encoded values instead (on a stack buffer).
This branch has not been deployed
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.
ValueOrd for FlagSet<T>comparesbits()as an integer. The DER encoding, a NamedBitList BIT STRING, puts flag 0 in the most significant bit of the first octet and drops trailing zero bits, so the two orders disagree. For a 9-flag set:Over all 512×512 pairs of a 9-flag set, 84,822 pairs order differently.
X.690 11.6 orders
SET OFcomponents by their encodings. ASetOfVecof a type that contains aFlagSetcan therefore encode out of DER order. An example is x509-cert'sDistributionPoint, which derivesValueOrdand hasreasons: Option<ReasonFlags>.The fix compares the encoded values, using a 17-byte stack buffer: one unused-bits octet plus up to 16 data octets for
u128flags.Test:
bit_string::tests::flagset_valueord_is_encoding_orderchecks the{A}/{B}example and every pair of a 9-flag set against the order of their encodings. It fails on master.This PR is independent of the other
derordering PRs (tag octet order,UtcTime,Option::der_cmp,ContextSpecificrecursion) and merges cleanly with each.This PR was produced by AI agents (Claude) while auditing every
DerOrd/ValueOrdimpl inderafter differential fuzzing ofder/x509-certfound the tag-order issue.