Skip to content

Commit 9754177

Browse files
committed
subject_name: tidy up list_cert_dns_names
Avoid combinator chaining, use explicit `match`.
1 parent 5f4ec11 commit 9754177

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/subject_name/verify.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1313
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1414

15-
use super::dns_name::{self, DnsNameRef, GeneralDnsNameRef, WildcardDnsNameRef};
15+
use super::dns_name::{self, DnsNameRef, WildcardDnsNameRef};
1616
use super::ip_address::{self, IpAddrRef};
1717
use super::name::SubjectNameRef;
1818
use crate::der::{self, FromDer};
@@ -317,25 +317,19 @@ pub(crate) fn list_cert_dns_names<'names>(
317317
) -> impl Iterator<Item = &'names str> {
318318
let cert = &cert.inner();
319319
NameIterator::new(Some(cert.subject), cert.subject_alt_name).filter_map(|result| {
320-
let name = result.ok()?;
321-
322-
let presented_id = match name {
320+
let presented_id = match result.ok()? {
323321
GeneralName::DnsName(presented) => presented,
324322
_ => return None,
325323
};
326324

327-
let dns_name = DnsNameRef::try_from_ascii(presented_id.as_slice_less_safe())
328-
.map(GeneralDnsNameRef::DnsName)
329-
.or_else(|_| {
330-
WildcardDnsNameRef::try_from_ascii(presented_id.as_slice_less_safe())
331-
.map(GeneralDnsNameRef::Wildcard)
332-
});
333-
334-
// if the name could be converted to a DNS name, add it; otherwise,
325+
// if the name could be converted to a DNS name, return it; otherwise,
335326
// keep going.
336-
match dns_name {
337-
Ok(name) => Some(name.into()),
338-
_ => None,
327+
match DnsNameRef::try_from_ascii(presented_id.as_slice_less_safe()) {
328+
Ok(dns_name) => Some(dns_name.into()),
329+
Err(_) => match WildcardDnsNameRef::try_from_ascii(presented_id.as_slice_less_safe()) {
330+
Ok(wildcard_dns_name) => Some(wildcard_dns_name.into()),
331+
Err(_) => None,
332+
},
339333
}
340334
})
341335
}

0 commit comments

Comments
 (0)