diff --git a/Cargo.toml b/Cargo.toml index cda43fe..dad8a07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ members = [ [package] name = "cdbc" -version = "0.1.12" +version = "0.1.13" edition = "2021" authors = ["zhuxiujia@qq.com"] description = "Rust Coroutine Database Driver Connectivity" @@ -18,7 +18,8 @@ license = "Apache-2.0" [features] default = [] -_tls-native-tls = [] + +#native-tls # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -32,6 +33,6 @@ log = { version = "0.4.8", default-features = false } crossbeam-queue = "0.3.1" either = {version = "1.5.3",features = ["serde"]} bstr = { version = "0.2.14", default-features = false, features = ["std"] } -native-tls = {version ="0.2"} +native-tls = {version ="0.2",optional = true} ahash = "0.7.2" serde_json = { version = "1.0.51", features = ["raw_value"]} diff --git a/cdbc-mysql/Cargo.toml b/cdbc-mysql/Cargo.toml index fac2ee2..52ac1cc 100644 --- a/cdbc-mysql/Cargo.toml +++ b/cdbc-mysql/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cdbc-mysql" -version = "0.1.12" +version = "0.1.13" edition = "2021" authors = ["zhuxiujia@qq.com"] description = "Rust Coroutine Database Driver Connectivity" @@ -8,7 +8,7 @@ repository = "https://github.com/co-rs/cdbc" license = "Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["offline","time"] +default = ["cdbc","offline", "time"] offline = ["serde", "either/serde"] _tls-native-tls = [] @@ -25,29 +25,30 @@ bigdecimal = ["bigdecimal_", "num-bigint"] decimal = ["rust_decimal", "num-bigint"] json = ["serde", "serde_json"] +native-tls = ["cdbc/native-tls"] + [dependencies] -cdbc = { version = "0.1.12", path = "../"} +cdbc = { version = "0.1.13", path = "../", optional = true } cogo = "0.1" hashlink = "0.7.0" thiserror = "1.0.30" bytes = '1.0.0' memchr = "2.3.4" -serde={version = "1.0.130" ,optional = true} +serde = { version = "1.0.130", optional = true } log = { version = "0.4.8", default-features = false } either = "1.5.3" bstr = { version = "0.2.14", default-features = false, features = ["std"] } -native-tls = {version ="0.2"} -generic-array = {version ="^0.14.4",features = ["serde"]} -rand = {version = "0.8.4",features = ["std","serde"]} -rsa = {version = "0.5.0",features = ["std","serde","serde_crate"]} -sha-1 = {version = "0.9.0", default-features = false} -sha2 = {version = "0.9.0", default-features = false} -base64 = {version="0.13.0",features = ["std"]} -digest = {version = "0.9.0"} +generic-array = { version = "^0.14.4", features = ["serde"] } +rand = { version = "0.8.4", features = ["std", "serde"] } +rsa = { version = "0.5.0", features = ["std", "serde", "serde_crate"] } +sha-1 = { version = "0.9.0", default-features = false } +sha2 = { version = "0.9.0", default-features = false } +base64 = { version = "0.13.0", features = ["std"] } +digest = { version = "0.9.0" } smallvec = "1.7.0" -byteorder = { version = "1.3.4", features = ["std"] } +byteorder = { version = "1.3.4", features = ["std"] } ahash = "0.7.2" percent-encoding = "2.1.0" url = { version = "2.1.1" } diff --git a/cdbc-mysql/src/connection/tls.rs b/cdbc-mysql/src/connection/tls.rs index ada1eeb..e95a436 100644 --- a/cdbc-mysql/src/connection/tls.rs +++ b/cdbc-mysql/src/connection/tls.rs @@ -47,6 +47,10 @@ fn upgrade(stream: &mut MySqlStream, options: &MySqlConnectOptions) -> Result Result{ pub inner:native_tls::TlsStream } +#[cfg(feature = "native-tls")] impl Deref for TlsStream{ type Target = native_tls::TlsStream; @@ -67,6 +68,7 @@ impl Deref for TlsStream{ &self.inner } } +#[cfg(feature = "native-tls")] impl DerefMut for TlsStream{ fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner @@ -80,6 +82,7 @@ where S: std::io::Read + std::io::Write, { Raw(S), + #[cfg(feature = "native-tls")] Tls(TlsStream), Upgrading, } @@ -89,6 +92,7 @@ impl MaybeTlsStream where S: std::io::Read + std::io::Write + std::fmt::Debug + Send +Sync + 'static, { + #[cfg(feature = "native-tls")] pub fn upgrade( &mut self, host: &str, @@ -135,11 +139,17 @@ where impl IsTLS for MaybeTlsStream where S:Write+Read{ #[inline] fn is_tls(&self) -> bool { - matches!(self, Self::Tls(_)) + if !cfg!(feature = "native-tls") { + return false; + }else{ + #[cfg(feature = "native-tls")] + return matches!(self, Self::Tls(_)); + } + return false; } } -// #[cfg(feature = "_tls-native-tls")] +#[cfg(feature = "native-tls")] fn configure_tls_connector( accept_invalid_certs: bool, accept_invalid_hostnames: bool, @@ -185,6 +195,7 @@ where fn read(&mut self, buf: &mut [u8]) -> std::io::Result { match &mut *self { MaybeTlsStream::Raw(s) => s.read(buf), + #[cfg(feature = "native-tls")] MaybeTlsStream::Tls(s) => s.read(buf), MaybeTlsStream::Upgrading => Err(io::ErrorKind::ConnectionAborted.into()), } @@ -198,8 +209,8 @@ where fn write(&mut self, buf: &[u8]) -> std::io::Result { match self { MaybeTlsStream::Raw(s) => s.write( buf), + #[cfg(feature = "native-tls")] MaybeTlsStream::Tls(s) => s.write( buf), - MaybeTlsStream::Upgrading => Err(io::ErrorKind::ConnectionAborted.into()), } } @@ -207,6 +218,7 @@ where fn flush(&mut self) -> std::io::Result<()> { match self { MaybeTlsStream::Raw(s) => s.flush(), + #[cfg(feature = "native-tls")] MaybeTlsStream::Tls(s) => s.flush(), MaybeTlsStream::Upgrading => Err(io::ErrorKind::ConnectionAborted.into()), @@ -224,7 +236,7 @@ where fn deref(&self) -> &Self::Target { match self { MaybeTlsStream::Raw(s) => s, - + #[cfg(feature = "native-tls")] MaybeTlsStream::Tls(s) => s.get_ref(), MaybeTlsStream::Upgrading => { @@ -241,7 +253,7 @@ where fn deref_mut(&mut self) -> &mut Self::Target { match self { MaybeTlsStream::Raw(s) => s, - + #[cfg(feature = "native-tls")] MaybeTlsStream::Tls(s) => s.get_mut(), MaybeTlsStream::Upgrading => {