Provide into_ssl() for ConnectConfiguration

Port from openssl-rs.
This commit is contained in:
Yuchen Wu 2023-08-14 18:42:12 -07:00 committed by Anthony Ramine
parent 4749c525e4
commit 52307b145b
1 changed files with 16 additions and 8 deletions

View File

@ -8,6 +8,7 @@ use crate::ssl::{
SslOptions, SslRef, SslStream, SslVerifyMode, SslOptions, SslRef, SslStream, SslVerifyMode,
}; };
use crate::version; use crate::version;
use std::net::IpAddr;
const FFDHE_2048: &str = " const FFDHE_2048: &str = "
-----BEGIN DH PARAMETERS----- -----BEGIN DH PARAMETERS-----
@ -189,14 +190,11 @@ impl ConnectConfiguration {
self.verify_hostname = verify_hostname; self.verify_hostname = verify_hostname;
} }
/// Initiates a client-side TLS session on a stream. /// Returns an `Ssl` configured to connect to the provided domain.
/// ///
/// The domain is used for SNI and hostname verification if enabled. /// The domain is used for SNI (if it is not an IP address) and hostname verification if enabled.
pub fn connect<S>(mut self, domain: &str, stream: S) -> Result<SslStream<S>, HandshakeError<S>> pub fn into_ssl(mut self, domain: &str) -> Result<Ssl, ErrorStack> {
where if self.sni && domain.parse::<IpAddr>().is_err() {
S: Read + Write,
{
if self.sni {
self.ssl.set_hostname(domain)?; self.ssl.set_hostname(domain)?;
} }
@ -210,7 +208,17 @@ impl ConnectConfiguration {
setup_verify_hostname(&mut self.ssl, domain)?; setup_verify_hostname(&mut self.ssl, domain)?;
} }
self.ssl.connect(stream) Ok(self.ssl)
}
/// Initiates a client-side TLS session on a stream.
///
/// The domain is used for SNI (if it is not an IP address) and hostname verification if enabled.
pub fn connect<S>(self, domain: &str, stream: S) -> Result<SslStream<S>, HandshakeError<S>>
where
S: Read + Write,
{
self.into_ssl(domain)?.connect(stream)
} }
} }