Skip to content

Commit

Permalink
subject_name: tidy up list_cert_dns_names
Browse files Browse the repository at this point in the history
Avoid combinator chaining, use explicit `match`.
  • Loading branch information
cpu committed Sep 18, 2023
1 parent 5f4ec11 commit 9754177
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/subject_name/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

use super::dns_name::{self, DnsNameRef, GeneralDnsNameRef, WildcardDnsNameRef};
use super::dns_name::{self, DnsNameRef, WildcardDnsNameRef};
use super::ip_address::{self, IpAddrRef};
use super::name::SubjectNameRef;
use crate::der::{self, FromDer};
Expand Down Expand Up @@ -317,25 +317,19 @@ pub(crate) fn list_cert_dns_names<'names>(
) -> impl Iterator<Item = &'names str> {
let cert = &cert.inner();
NameIterator::new(Some(cert.subject), cert.subject_alt_name).filter_map(|result| {
let name = result.ok()?;

let presented_id = match name {
let presented_id = match result.ok()? {
GeneralName::DnsName(presented) => presented,
_ => return None,
};

let dns_name = DnsNameRef::try_from_ascii(presented_id.as_slice_less_safe())
.map(GeneralDnsNameRef::DnsName)
.or_else(|_| {
WildcardDnsNameRef::try_from_ascii(presented_id.as_slice_less_safe())
.map(GeneralDnsNameRef::Wildcard)
});

// if the name could be converted to a DNS name, add it; otherwise,
// if the name could be converted to a DNS name, return it; otherwise,
// keep going.
match dns_name {
Ok(name) => Some(name.into()),
_ => None,
match DnsNameRef::try_from_ascii(presented_id.as_slice_less_safe()) {
Ok(dns_name) => Some(dns_name.into()),
Err(_) => match WildcardDnsNameRef::try_from_ascii(presented_id.as_slice_less_safe()) {
Ok(wildcard_dns_name) => Some(wildcard_dns_name.into()),
Err(_) => None,
},
}
})
}
Expand Down

0 comments on commit 9754177

Please sign in to comment.