Repository navigation
der: order UTCTime in SET OF by its encoding - #2448
Merged
tarcieri merged 2 commits intoOct 5, 2026
Merged
Conversation
`UtcTime` used its chronological `Ord` as `ValueOrd` (`OrdIsValueOrd`).
X.690 11.6 orders `SET OF` components by their encodings, and a UTCTime
encodes the year as two digits (RFC 5280: 50..99 = 19xx, 00..49 = 20xx),
so the two orders disagree across 2000:
1999-12-31 23:59:59 -> "991231235959Z"
2000-01-01 00:00:00 -> "000101000000Z" (sorts first in DER)
`SetOfVec<UtcTime>` therefore encodes non-DER output for such sets, and
`SetOf`/`SetOfRef` reject the DER encoding.
Implement `ValueOrd` for `UtcTime` by comparing the encoded value. `Ord`
stays chronological.
dishmaker
reviewed
Oct 2, 2026
tarcieri
reviewed
Oct 5, 2026
Comment on lines
+180
to
+193
| // Every field is encoded as two decimal digits, so comparing the fields in order is | ||
| // comparing the encodings. | ||
| let fields = |t: &Self| { | ||
| let dt = &t.0; | ||
| ( | ||
| dt.year() % 100, | ||
| dt.month(), | ||
| dt.day(), | ||
| dt.hour(), | ||
| dt.minutes(), | ||
| dt.seconds(), | ||
| ) | ||
| }; | ||
| Ok(fields(self).cmp(&fields(other))) |
Member
There was a problem hiding this comment.
This seems like a little bit weird way of implementing this (i.e. using an anonymous function) versus just writing out the comparisons, but the fix seems correct so I'll go ahead and merge it
tarcieri
approved these changes
Oct 5, 2026
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.
UtcTimeuses its chronologicalOrdasValueOrd(impl OrdIsValueOrd for UtcTime). X.690 11.6 orders the components of a DERSET OFby their encodings. A UTCTime encodes the year as two digits: under RFC 5280,50..99is 19xx and00..49is 20xx. So the two orders disagree across 2000:SetOfVec<UtcTime>therefore encodes such a set out of DER order, andSetOf/SetOfRefreject the correctly ordered encoding.This PR implements
ValueOrdforUtcTimeby comparing the encodedYYMMDDHHMMSSZvalue.Ordstays chronological. No otherOrdIsValueOrdtype has this mismatch:GeneralizedTime's four-digit year sorts the same in both orders, and every pair ofObjectIdentifier,Int/Uint, string,BitStringandOctetStringvalues checked throughder_cmpagrees with octet order.Tests:
utc_time::tests::value_ord_is_encoding_order:value_cmp/der_cmpput 2000 before 1999, andOrdstill puts 1999 first.der/tests/set_of.rsutctime_order: aSetOfVec<UtcTime>holding both dates encodes 2000 first. It fails on master.This is independent of the
SET OFtag-order fix (der: order SET OF components by their encoded octets): the two touch different code and merge without conflict.This PR was produced by AI agents (Claude) during differential fuzzing of
der/x509-cert. It was found by checking everyOrdIsValueOrdtype'sder_cmpagainst the byte order of its encodings.