Skip to content

Commit b967bbc

Browse files
author
Alexei Pastuchov
committed
restrict MySQL SSL connection mode for non Windows only
Windows binding of mysqlclient-sys doesn't provide values for the option MYSQL_OPT_SSL_MODE See: sgrif/mysqlclient-sys#27
1 parent 58882b3 commit b967bbc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

diesel/src/mysql/connection/raw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl RawConnection {
4747
let port = connection_options.port();
4848
let unix_socket = connection_options.unix_socket();
4949

50-
if connection_options.ssl_mode().is_some() {
50+
if !cfg!(windows) && connection_options.ssl_mode().is_some() {
5151
let ssl_mode = connection_options
5252
.ssl_mode()
5353
.expect("Failure on unwrapping ssl_mode");

diesel/src/mysql/connection/url.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::collections::HashMap;
77
use std::ffi::{CStr, CString};
88

99
use crate::result::{ConnectionError, ConnectionResult};
10+
11+
#[cfg(not(windows))]
1012
use mysqlclient_sys::mysql_ssl_mode;
1113

1214
pub struct ConnectionOptions {
@@ -16,6 +18,7 @@ pub struct ConnectionOptions {
1618
database: Option<CString>,
1719
port: Option<u16>,
1820
unix_socket: Option<CString>,
21+
#[cfg(not(windows))]
1922
ssl_mode: Option<mysql_ssl_mode>,
2023
}
2124

@@ -44,6 +47,7 @@ impl ConnectionOptions {
4447
_ => None,
4548
};
4649

50+
#[cfg(not(windows))]
4751
let ssl_mode = match query_pairs.get("ssl_mode") {
4852
Some(v) => {
4953
let ssl_mode = match v.to_lowercase().as_str() {
@@ -86,6 +90,7 @@ impl ConnectionOptions {
8690
database: database,
8791
port: url.port(),
8892
unix_socket: unix_socket,
93+
#[cfg(not(windows))]
8994
ssl_mode: ssl_mode,
9095
})
9196
}
@@ -114,6 +119,7 @@ impl ConnectionOptions {
114119
self.unix_socket.as_ref().map(|x| &**x)
115120
}
116121

122+
#[cfg(not(windows))]
117123
pub fn ssl_mode(&self) -> Option<mysql_ssl_mode> {
118124
self.ssl_mode
119125
}
@@ -253,6 +259,7 @@ fn unix_socket_tests() {
253259
);
254260
}
255261

262+
#[cfg(not(windows))]
256263
#[test]
257264
fn ssl_mode() {
258265
let ssl_mode = |url| ConnectionOptions::parse(url).unwrap().ssl_mode();

0 commit comments

Comments
 (0)