Skip to content

Commit

Permalink
Make Cert::valid_dns_names() public
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Sep 21, 2023
1 parent f93369a commit 12fe2bb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ impl<'a> Cert<'a> {
)
}

pub(crate) fn valid_dns_names(&self) -> impl Iterator<Item = &str> {
/// Returns a list of valid DNS names provided in the subject alternative names extension
///
/// This function must not be used to implement custom DNS name verification.
/// Checking that a certificate is valid for a given subject name should always be done with
/// [EndEntityCert::verify_is_valid_for_subject_name].
///
/// [EndEntityCert::verify_is_valid_for_subject_name]: crate::EndEntityCert::verify_is_valid_for_subject_name
pub fn valid_dns_names(&self) -> impl Iterator<Item = &str> {
NameIterator::new(Some(self.subject), self.subject_alt_name).filter_map(|result| {
let presented_id = match result.ok()? {
GeneralName::DnsName(presented) => presented,
Expand Down
11 changes: 1 addition & 10 deletions src/end_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,6 @@ impl<'a> EndEntityCert<'a> {
untrusted::Input::from(signature),
)
}

/// Returns a list of valid DNS names provided in the subject alternative names extension
///
/// This function must not be used to implement custom DNS name verification.
/// Checking that a certificate is valid for a given subject name should always be done with
/// [EndEntityCert::verify_is_valid_for_subject_name].
pub fn dns_names(&'a self) -> impl Iterator<Item = &'a str> {
self.inner.valid_dns_names()
}
}

impl<'a> Deref for EndEntityCert<'a> {
Expand Down Expand Up @@ -215,7 +206,7 @@ mod tests {
let cert =
EndEntityCert::try_from(der).expect("should parse end entity certificate correctly");

let mut names = cert.dns_names();
let mut names = cert.valid_dns_names();
assert_eq!(names.next(), Some(name));
assert_eq!(names.next(), None);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,5 @@ fn expect_cert_dns_names<'name>(
let cert = webpki::EndEntityCert::try_from(&der)
.expect("should parse end entity certificate correctly");

assert!(cert.dns_names().eq(expected_names))
assert!(cert.valid_dns_names().eq(expected_names))
}

0 comments on commit 12fe2bb

Please sign in to comment.