diff --git a/src/end_entity.rs b/src/end_entity.rs index b94486ea..8a8c57df 100644 --- a/src/end_entity.rs +++ b/src/end_entity.rs @@ -140,8 +140,8 @@ impl<'a> EndEntityCert<'a> { } /// Verifies that the certificate is valid for the given DNS host name. - pub fn verify_for_name(&self, name: Name) -> Result<(), Error> { - match name { + pub fn verify_for_name<'n>(&self, name: impl Into>) -> Result<(), Error> { + match name.into() { Name::DnsName(dns_name) => name::verify_cert_dns_name(&self, dns_name), } } diff --git a/src/name/name.rs b/src/name/name.rs index e379f126..86e776cb 100644 --- a/src/name/name.rs +++ b/src/name/name.rs @@ -21,3 +21,10 @@ pub enum Name<'a> { /// A DNS name. DnsName(DnsNameRef<'a>), } + +impl<'a> From> for Name<'a> { + #[inline] + fn from(name: DnsNameRef<'a>) -> Self { + Self::DnsName(name) + } +} diff --git a/tests/integration.rs b/tests/integration.rs index 598641d3..c4cff895 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -13,7 +13,9 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. use core::convert::TryFrom; + extern crate webpki; +use webpki::Error; static ALL_SIGALGS: &[&webpki::SignatureAlgorithm] = &[ &webpki::ECDSA_P256_SHA256, @@ -51,6 +53,15 @@ pub fn netflix() { Ok(()), cert.verify_is_valid_tls_server_cert(ALL_SIGALGS, &anchors, &[inter], time) ); + + let name = webpki::DnsNameRef::try_from_ascii_str("netflix.com").unwrap(); + assert_eq!(Ok(()), cert.verify_for_name(name)); + + let wrong_name = webpki::DnsNameRef::try_from_ascii_str("netflix.co").unwrap(); + assert_eq!( + Err(Error::CertNotValidForName), + cert.verify_for_name(wrong_name) + ); } #[test]