Skip to content

Commit 9dfb3f2

Browse files
committed
Rm unwraps
1 parent 3e6140e commit 9dfb3f2

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ impl ProxyClient {
686686
) -> Result<(HttpSender, HttpConnection), ProxyError> {
687687
let outbound_stream = tokio::net::TcpStream::connect(target).await?;
688688

689-
let domain = server_name_from_host(target).unwrap();
689+
let domain = server_name_from_host(target)?;
690690
let tls_stream = nesting_tls_connector
691691
.connect(domain, outbound_stream)
692692
.await?;
@@ -785,6 +785,12 @@ pub enum ProxyError {
785785
IntConversion(#[from] TryFromIntError),
786786
#[error("Bad host name: {0}")]
787787
BadDnsName(#[from] tokio_rustls::rustls::pki_types::InvalidDnsNameError),
788+
#[error("Invalid certificate encoding")]
789+
InvalidCertificateEncoding,
790+
#[error("Missing common name in certificate subject")]
791+
MissingCertificateName,
792+
#[error("Certificate common name is not valid UTF-8")]
793+
InvalidCertificateName,
788794
#[error("HTTP: {0}")]
789795
Hyper(#[from] hyper::Error),
790796
#[error("Attested TLS: {0}")]
@@ -809,17 +815,15 @@ impl From<mpsc::error::SendError<RequestWithResponseSender>> for ProxyError {
809815
fn hostname_from_cert(cert: &CertificateDer<'static>) -> Result<String, ProxyError> {
810816
let cert = x509_parser::parse_x509_certificate(cert.as_ref())
811817
.map(|(_, parsed)| parsed)
812-
.unwrap();
818+
.map_err(|_| ProxyError::InvalidCertificateEncoding)?;
813819

814820
Ok(cert
815821
.subject()
816822
.iter_common_name()
817823
.next()
818-
.unwrap()
819-
// .ok_or_else(|| Self::bad_encoding("Missing common name"))?
824+
.ok_or(ProxyError::MissingCertificateName)?
820825
.as_str()
821-
// .map_err(|err| Self::bad_encoding(format!("Invalid common name: {err}")))
822-
.unwrap()
826+
.map_err(|_| ProxyError::InvalidCertificateName)?
823827
.to_string())
824828
}
825829

0 commit comments

Comments
 (0)