Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Conversation

cpu
Copy link
Member

@cpu cpu commented Feb 27, 2024

RFC 7468 §2 says:

parsers SHOULD ignore whitespace

Previously we only stripped the trailing whitespace from the base64 content lines within the PEM section boundaries. This branch updates our processing to additionally trim leading contiguous whitespace. This felt more sensible than outright ignoring whitespace (e.g. from the middle of content) and will be sufficient to resolve #40

We base our implementation on the stdlib's unstable [u8]::trim_ascii fn, which we can't (yet) use directly due to our MSRV/stable rust requirements. A TODO is left for future cleanup. Notably this broadens our definition of what whitespace is slightly (e.g. including \t).

Along the way I noticed CI for main is failing on nightly clippy due to redundant import findings. I've applied the same fix strategy we used for Rustls (rustls/rustls#1813) and Webpki (rustls/webpki#234) to resolve this.

Like we just did in Rustls and webpki, _always_ opt-in to no_std, and
then import the std prelude in tests where necessary.

This resolves some nightly clippy warnings about redundant imports that
will arise otherwise
@cpu cpu self-assigned this Feb 27, 2024
RFC 7468 §2[0] says:
> parsers SHOULD ignore whitespace

Previously we only stripped the trailing whitespace from the base64
content lines within the PEM section boundaries. This branch updates our
processing to additionally trim leading contiguous whitespace. This felt
more sensible than outright ignoring whitespace (e.g. from the middle of
content) and will be sufficient to resolve the real world PEM files
we've seen with leading whitespace.

We base our implementation on the stdlib's unstable `[u8]::trim_ascii`
fn, which we can't (yet) use directly due to our MSRV/stable rust
requirements. A TODO is left for future cleanup.

[0]: https://www.rfc-editor.org/rfc/rfc7468#section-2
@cpu cpu force-pushed the cpu-whitespace-prefix-ok branch from db38d3a to a0f5ad0 Compare February 29, 2024 19:43
@cpu cpu requested a review from ctz February 29, 2024 19:52
Copy link
Member

@ctz ctz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good stuff!

@cpu cpu merged commit 95152b4 into rustls:main Mar 1, 2024
@cpu cpu deleted the cpu-whitespace-prefix-ok branch March 1, 2024 14:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Certificates with indentation fail to parse
3 participants