Skip to content

x509-cert: fix UserNotice::notice_ref type, add DisplayText::BmpString - #2569

Draft
MarkAtwood wants to merge 1 commit into
RustCrypto:masterfrom
MarkAtwood:x509-cert/user-notice-display-text
Draft

MarkAtwood wants to merge 1 commit into
RustCrypto:masterfrom
MarkAtwood:x509-cert/user-notice-display-text

Conversation

@MarkAtwood

@MarkAtwood MarkAtwood commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

UserNotice::notice_ref is declared Option<GeneralizedTime>.
RFC 5280 §4.2.1.4
gives it as NoticeReference:

UserNotice ::= SEQUENCE {
    noticeRef        NoticeReference OPTIONAL,
    explicitText     DisplayText OPTIONAL }

NoticeReference ::= SEQUENCE {
    organization     DisplayText,
    noticeNumbers    SEQUENCE OF INTEGER }

NoticeReference is defined in the same module and unused. A
UserNotice carrying a noticeRef does not decode.

DisplayText implements two of four alternatives:

DisplayText ::= CHOICE {
    ia5String        IA5String      (SIZE (1..200)),
    visibleString    VisibleString  (SIZE (1..200)),
    bmpString        BMPString      (SIZE (1..200)),
    utf8String       UTF8String     (SIZE (1..200)) }

This changes notice_ref to Option<NoticeReference> and adds
DisplayText::BmpString, held by der::asn1::BmpString.

Three tests, from_der and to_der in each: a UserNotice with a
noticeRef, one with a bmpString explicitText, and one for the two
alternatives already implemented.

visibleString

Not added; tracked in #2570.

RFC 6818

RFC 6818 §3 replaced
§4.2.1.4's tenth paragraph:

encoding RFC 5280 RFC 6818 §3
utf8String SHOULD SHOULD
ia5String MAY MUST NOT
visibleString MUST NOT acceptable, less preferred
bmpString MUST NOT acceptable, less preferred

The two alternatives currently implemented are the preferred one and the
prohibited one.

Breaking

DisplayText and UserNotice are not #[non_exhaustive]. A new variant
and a changed field type are both visible to downstream exhaustive
matches and struct literals. Draft in case these belong on a 0.4 line, or
want #[non_exhaustive] in the same change.

Checks

cargo test -p x509-cert, --no-default-features, cargo fmt,
cargo clippy: clean. --all-features has five failures in the builder
tests, which shell out to a zlint binary absent here; identical on
clean master. cargo hack feature-powerset not run.

…ring`

`UserNotice::notice_ref` was declared `Option<GeneralizedTime>`. RFC 5280
Section 4.2.1.4 gives it as `NoticeReference`:

    UserNotice ::= SEQUENCE {
        noticeRef        NoticeReference OPTIONAL,
        explicitText     DisplayText OPTIONAL }

    NoticeReference ::= SEQUENCE {
        organization     DisplayText,
        noticeNumbers    SEQUENCE OF INTEGER }

`NoticeReference` is already defined correctly in this module and was
never used, so a `UserNotice` carrying a `noticeRef` could not be
decoded.

`DisplayText` implemented two of the CHOICE's four alternatives. This
adds `bmpString`, which `der::asn1::BmpString` can hold. `visibleString`
is still missing: `der` has `Tag::VisibleString` but no `asn1` type for
the value, and adding one is a public API decision for that crate.

Neither type had any test, which is how both survived. Three are added:
a `UserNotice` with a `noticeRef`, one with a `bmpString` explicitText,
and one covering the two alternatives that already worked, each
round-tripping through `from_der` and `to_der`.

Both changes are breaking: `DisplayText` and `UserNotice` are not
`#[non_exhaustive]`, so adding a variant and changing a field type are
each visible to downstream exhaustive matches and struct literals.

This branch has not been deployed

No deployments
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.

1 participant