diff --git a/sqlx-core/src/executor.rs b/sqlx-core/src/executor.rs index 037f30dd..f605caa6 100644 --- a/sqlx-core/src/executor.rs +++ b/sqlx-core/src/executor.rs @@ -48,8 +48,8 @@ pub trait Executor { } else { Ok(Some(val)) } - }, - None => Ok(None) + } + None => Ok(None), } }) } diff --git a/sqlx-core/src/mysql/connection.rs b/sqlx-core/src/mysql/connection.rs index 4949fbf0..4552ae1f 100644 --- a/sqlx-core/src/mysql/connection.rs +++ b/sqlx-core/src/mysql/connection.rs @@ -151,14 +151,6 @@ impl MySqlConnection { let handshake_packet = self_.receive().await?; let handshake = Handshake::decode(handshake_packet)?; - // TODO: Capabilities::SECURE_CONNECTION - // TODO: Capabilities::CONNECT_ATTRS - // TODO: Capabilities::PLUGIN_AUTH - // TODO: Capabilities::PLUGIN_AUTH_LENENC_CLIENT_DATA - // TODO: Capabilities::TRANSACTIONS - // TODO: Capabilities::CLIENT_DEPRECATE_EOF - // TODO: Capabilities::COMPRESS - // TODO: Capabilities::ZSTD_COMPRESSION_ALGORITHM let client_capabilities = Capabilities::PROTOCOL_41 | Capabilities::IGNORE_SPACE | Capabilities::FOUND_ROWS @@ -176,6 +168,8 @@ impl MySqlConnection { username: url.username().unwrap_or("root"), // TODO: Remove the panic! database: url.database().expect("required database"), + auth_plugin_name: handshake.auth_plugin_name.as_deref(), + auth_response: None, }); self_.stream.flush().await?; diff --git a/sqlx-core/src/mysql/executor.rs b/sqlx-core/src/mysql/executor.rs index ee2db6af..f4fb1a77 100644 --- a/sqlx-core/src/mysql/executor.rs +++ b/sqlx-core/src/mysql/executor.rs @@ -8,9 +8,8 @@ use crate::describe::{Column, Describe}; use crate::executor::Executor; use crate::mysql::error::MySqlError; use crate::mysql::protocol::{ - Capabilities, ColumnCount, ColumnDefinition, ComQuery, ComStmtExecute, - ComStmtPrepare, ComStmtPrepareOk, Cursor, Decode, EofPacket, ErrPacket, OkPacket, Row, - Type, + Capabilities, ColumnCount, ColumnDefinition, ComQuery, ComStmtExecute, ComStmtPrepare, + ComStmtPrepareOk, Cursor, Decode, EofPacket, ErrPacket, OkPacket, Row, Type, }; use crate::mysql::{MySql, MySqlArguments, MySqlConnection, MySqlRow}; diff --git a/sqlx-core/src/mysql/protocol/handshake.rs b/sqlx-core/src/mysql/protocol/handshake.rs index 910b737e..459e6fff 100644 --- a/sqlx-core/src/mysql/protocol/handshake.rs +++ b/sqlx-core/src/mysql/protocol/handshake.rs @@ -105,6 +105,55 @@ mod tests { use super::{Capabilities, Decode, Handshake, Status}; const HANDSHAKE_MARIA_DB_10_4_7: &[u8] = b"\n5.5.5-10.4.7-MariaDB-1:10.4.7+maria~bionic\x00\x0b\x00\x00\x00t6L\\j\"dS\x00\xfe\xf7\x08\x02\x00\xff\x81\x15\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00U14Oph9\" { pub client_collation: u8, pub username: &'a str, pub database: &'a str, + pub auth_plugin_name: Option<&'a str>, + pub auth_response: Option<&'a str>, } impl Encode for HandshakeResponse<'_> { @@ -41,17 +43,25 @@ impl Encode for HandshakeResponse<'_> { if capabilities.contains(Capabilities::PLUGIN_AUTH_LENENC_DATA) { // auth_response : string - buf.put_str_lenenc::(""); + buf.put_str_lenenc::(self.auth_response.unwrap_or_default()); } else { + let auth_response = self.auth_response.unwrap_or_default(); + // auth_response_length : int<1> - buf.put_u8(0); + buf.put_u8(auth_response.len() as u8); // auth_response : string<{auth_response_length}> + buf.put_str(auth_response); } if capabilities.contains(Capabilities::CONNECT_WITH_DB) { // database : string buf.put_str_nul(self.database); } + + if capabilities.contains(Capabilities::PLUGIN_AUTH) { + // client_plugin_name : string + buf.put_str_nul(self.auth_plugin_name.unwrap_or_default()); + } } }