Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add const-friendly CertificateDer::from_slice #51

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

cpu
Copy link
Member

@cpu cpu commented Aug 5, 2024

In webpki-roots we want to be able to codegen constant CertificateDer entries to support the use-case where trusted CA roots in full self-signed certificate form (as opposed to the minimal webpki TrustAnchor representation) are required, for example when working with a platform verifier that consumes x509 trust anchors (See rustls/webpki-roots#75).

While there is a const friendly way to create pki_types::Der with Der::from_slice() there's presently no const friendly way to create a CertificateDer in a similar manner. This branch adds const CertificateDer::from_slice() for this purpose. We skip requiring the Der::from_slice() and accept a &[u8] directly since the CertificateDer name already emphasizes the expected format and there's limited value in making callers jump through the extra Der::from_slice() hoop.

There are other types that wrap Der<'_> (e.g. the PrivateKeyDer variants, CertificateRevocationListDer, etc) but for now I've omitted adding similar from_slice() const constructors for these types until there's a concrete need in-hand.

@cpu cpu self-assigned this Aug 5, 2024
@djc
Copy link
Member

djc commented Aug 5, 2024

The main question in my mind is whether this should take Der or just take &[u8] directly. I don't remember why I/we made Der a public type, but I don't feel there is much to be gained from making the extra intermediate step in this case?

@cpu
Copy link
Member Author

cpu commented Aug 5, 2024

The main question in my mind is whether this should take Der or just take &[u8] directly. I don't remember why I/we made Der a public type, but I don't feel there is much to be gained from making the extra intermediate step in this case?

That's a fair point. Given "Der" is in the outer type name already I would be in favour of changing it to take a slice directly. I'll adjust.

@cpu cpu changed the title add const-friendly CertificateDer::from_der add const-friendly CertificateDer::from_slice Aug 6, 2024
@cpu
Copy link
Member Author

cpu commented Aug 6, 2024

I would be in favour of changing it to take a slice directly. I'll adjust.

Done

src/lib.rs Outdated Show resolved Hide resolved
cpu added 2 commits August 6, 2024 09:28
This commit adds the ability to construct a `const CertificateDer` by
way of the `const`-friendly `CertificateDer::from_slice()` fn that
accepts a slice of `&[u8]` DER.
@cpu
Copy link
Member Author

cpu commented Aug 6, 2024

I updated rustls/webpki-roots#75 to use the new from_slice() fn and everything is working as expected. Going to merge/release.

@cpu cpu added this pull request to the merge queue Aug 6, 2024
Merged via the queue into rustls:main with commit 9382315 Aug 6, 2024
13 checks passed
@cpu cpu deleted the cpu-const-cert-der branch August 6, 2024 14:35
@cpu
Copy link
Member Author

cpu commented Aug 6, 2024

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.

3 participants