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

Clean up name api #182

Closed
wants to merge 21 commits into from
Closed

Clean up name api #182

wants to merge 21 commits into from

Conversation

djc
Copy link
Member

@djc djc commented Sep 20, 2023

Small refactoring for the name API from reviewing #178. Hope this doesn't make a rebase too painful.

We switched to using `doc_auto_cfg` to automatically indicate in
Rustdocs when an item requires a particular feature. This comment about
the `dns_name::DnsName` re-export requiring alloc isn't necessary
anymore.
We switched to `doc_auto_cfg` and don't need to manually annotate
`cfg(feature ...)` annotations for docsrs purposes anymore.
This is what most consumers of the API are interested in, and avoids
needing to export the `GeneralDnsNameRef` and `WildcardDnsNameRef`
types.
We can express this test with the `expect_cert_dns_names` helper.
Prior to this commit the rustdoc comment on `EndEntityCert.dns_names`
mentioned using `verify_is_valid_for_dns_name` and
`verify_is_valid_for_at_least_one_dns_name`, but these functions don't
exist anymore.

This commit updates the comment to point to
`EndEntityCert::verify_is_valid_for_subject_name`, and does so with
a proper Rustdoc link so that future updates will be caught by `cargo
doc` if we forget to fix this reference to match.
The purpose of the `dns_names` helper on an `EndEntityCert` is to
provide users the opportunity to get information on the dNSName SAN
values in a certificate for **non-validation** purposes. Checking that
a certificate is valid for a particular name should always be done with
`verify_is_valid_for_at_least_one_dns_name`.

With that use-case in mind, we can make the `dns_names` helper easier
for consumers to use by filtering out invalid general names, returning
an `Iterator<Item = &'a str>` unconditionally, instead of
a `Result`. This better matches the updated name validation semantics
where we ignore `MalformedDnsIdentifier` errors to continue to try to
find a valid name to validate against.
With the update to the `dns_names` function in the previous commit we
can now make `EndEntity.dns_names` work without requiring `alloc`.
Avoid combinator chaining, use explicit `match`.
@djc djc requested review from cpu and ctz September 20, 2023 08:51
@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

Merging #182 (219a115) into main (8d6a733) will increase coverage by 0.11%.
Report is 11 commits behind head on main.
The diff coverage is 89.28%.

❗ Current head 219a115 differs from pull request most recent head 27a1234. Consider uploading reports for the commit 27a1234 to get more accurate results

@@            Coverage Diff             @@
##             main     #182      +/-   ##
==========================================
+ Coverage   96.31%   96.43%   +0.11%     
==========================================
  Files          17       17              
  Lines        4510     4512       +2     
==========================================
+ Hits         4344     4351       +7     
+ Misses        166      161       -5     
Files Changed Coverage Δ
src/subject_name/dns_name.rs 87.98% <88.46%> (+1.11%) ⬆️
src/end_entity.rs 100.00% <100.00%> (ø)
src/subject_name/verify.rs 92.09% <100.00%> (ø)

... and 6 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

The From impl feels a little unidiomatic because the DnsNameRef is not
consumed. An AsRef impl would unnecessarily constrain the lifetime of
the output value to `&self`, whereas it can live as long as `'a`.
The From impl feels a little unidiomatic because the WildcardDnsNameRef is
not consumed. An AsRef impl would unnecessarily constrain the lifetime of
the output value to `&self`, whereas it can live as long as `'a`.
The From impl feels a little unidiomatic because the GeneralDnsNameRef is
not consumed. An AsRef impl would unnecessarily constrain the lifetime of
the output value to `&self`, whereas it can live as long as `'a`.
@djc djc closed this Sep 20, 2023
@cpu cpu deleted the clean-up-name-api branch September 20, 2023 14:01
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.

2 participants