diff --git a/sqlx-core/Cargo.toml b/sqlx-core/Cargo.toml index f4db49fa7a..bb58e5674f 100644 --- a/sqlx-core/Cargo.toml +++ b/sqlx-core/Cargo.toml @@ -34,14 +34,15 @@ decimal = [ "rust_decimal", "num-bigint" ] json = [ "serde", "serde_json" ] # runtimes -runtime-actix-native-tls = [ "sqlx-rt/runtime-actix-native-tls", "_rt-actix" ] -runtime-async-std-native-tls = [ "sqlx-rt/runtime-async-std-native-tls", "_rt-async-std" ] -runtime-tokio-native-tls = [ "sqlx-rt/runtime-tokio-native-tls", "_rt-tokio" ] +runtime-actix-native-tls = [ "sqlx-rt/runtime-actix-native-tls", "_tls-native-tls", "_rt-actix" ] +runtime-async-std-native-tls = [ "sqlx-rt/runtime-async-std-native-tls", "_tls-native-tls", "_rt-async-std" ] +runtime-tokio-native-tls = [ "sqlx-rt/runtime-tokio-native-tls", "_tls-native-tls", "_rt-tokio" ] # for conditional compilation _rt-actix = [] _rt-async-std = [] _rt-tokio = [] +_tls-native-tls = [] # support offline/decoupled building (enables serialization of `Describe`) offline = [ "serde", "either/serde" ] diff --git a/sqlx-core/src/error.rs b/sqlx-core/src/error.rs index ff9b05edd2..0cab5a2f85 100644 --- a/sqlx-core/src/error.rs +++ b/sqlx-core/src/error.rs @@ -129,12 +129,6 @@ impl Error { pub(crate) fn config(err: impl StdError + Send + Sync + 'static) -> Self { Error::Configuration(err.into()) } - - #[allow(dead_code)] - #[inline] - pub(crate) fn tls(err: impl StdError + Send + Sync + 'static) -> Self { - Error::Tls(err.into()) - } } pub(crate) fn mismatched_types>(ty: &DB::TypeInfo) -> BoxDynError { @@ -240,6 +234,14 @@ impl From for Error { } } +#[cfg(feature = "_tls-native-tls")] +impl From for Error { + #[inline] + fn from(error: sqlx_rt::native_tls::Error) -> Self { + Error::Tls(Box::new(error)) + } +} + // Format an error message as a `Protocol` error macro_rules! err_protocol { ($expr:expr) => { diff --git a/sqlx-core/src/net/tls.rs b/sqlx-core/src/net/tls.rs index 674babfa49..69041b4699 100644 --- a/sqlx-core/src/net/tls.rs +++ b/sqlx-core/src/net/tls.rs @@ -48,17 +48,17 @@ where if !accept_invalid_certs { if let Some(ca) = root_cert_path { let data = fs::read(ca).await?; - let cert = Certificate::from_pem(&data).map_err(Error::tls)?; + let cert = Certificate::from_pem(&data)?; builder.add_root_certificate(cert); } } #[cfg(not(feature = "_rt-async-std"))] - let connector = builder.build().map_err(Error::tls)?; + let connector = sqlx_rt::TlsConnector::from(builder.build()?); #[cfg(feature = "_rt-async-std")] - let connector = builder; + let connector = sqlx_rt::TlsConnector::from(builder); let stream = match replace(self, MaybeTlsStream::Upgrading) { MaybeTlsStream::Raw(stream) => stream, @@ -75,12 +75,7 @@ where } }; - *self = MaybeTlsStream::Tls( - sqlx_rt::TlsConnector::from(connector) - .connect(host, stream) - .await - .map_err(|err| Error::Tls(err.into()))?, - ); + *self = MaybeTlsStream::Tls(connector.connect(host, stream).await?); Ok(()) }