| 1 | use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::iorust-analyzer cargo sqlx-mysql 0.8.3 io/::MySqlBufMutExtrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/MySqlBufMutExt#; |
| 2 | use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::iorust-analyzer cargo sqlx-mysql 0.8.3 io/::{BufMutExtrust-analyzer cargo sqlx-core 0.8.3 io/buf_mut/BufMutExt#, ProtocolEncoderust-analyzer cargo sqlx-core 0.8.3 io/encode/ProtocolEncode#}; |
| 3 | use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::protocolrust-analyzer cargo sqlx-mysql 0.8.3 protocol/::authrust-analyzer cargo sqlx-mysql 0.8.3 protocol/auth/::AuthPluginrust-analyzer cargo sqlx-mysql 0.8.3 protocol/auth/AuthPlugin#; |
| 4 | use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::protocolrust-analyzer cargo sqlx-mysql 0.8.3 protocol/::connectrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/::ssl_requestrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/ssl_request/::SslRequestrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/ssl_request/SslRequest#; |
| 5 | use craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::protocolrust-analyzer cargo sqlx-mysql 0.8.3 protocol/::Capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/Capabilities#; |
| 6 | |
| 7 | // https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse |
| 8 | // https://mariadb.com/kb/en/connection/#client-handshake-response |
| 9 | |
| 10 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 11 | pub struct HandshakeResponserust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#<'a> { |
| 12 | pub databaserust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#database.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>, |
| 13 | |
| 14 | /// Max size of a command packet that the client wants to send to the server |
| 15 | pub max_packet_sizerust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#max_packet_size.: u32, |
| 16 | |
| 17 | /// Default collation for the connection |
| 18 | pub collationrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#collation.: u8, |
| 19 | |
| 20 | /// Name of the SQL account which client wants to log in |
| 21 | pub usernamerust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#username.: &'a str, |
| 22 | |
| 23 | /// Authentication method used by the client |
| 24 | pub auth_pluginrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#auth_plugin.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<AuthPluginrust-analyzer cargo sqlx-mysql 0.8.3 protocol/auth/AuthPlugin#>, |
| 25 | |
| 26 | /// Opaque authentication response |
| 27 | pub auth_responserust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#auth_response.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a [u8]>, |
| 28 | } |
| 29 | |
| 30 | impl ProtocolEncoderust-analyzer cargo sqlx-core 0.8.3 io/encode/ProtocolEncode#<'_, Capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/Capabilities#> for HandshakeResponserust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#<'_> { |
| 31 | fn encode_withrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/impl#[`HandshakeResponse<'_>`][`ProtocolEncode<'_, Capabilities>`]encode_with().( |
| 32 | &self, |
| 33 | buf: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 34 | mut context: Capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/Capabilities#, |
| 35 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), craterust-analyzer cargo sqlx-mysql 0.8.3 crate/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> { |
| 36 | if self.auth_pluginrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#auth_plugin..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 37 | // ensure PLUGIN_AUTH is set *only* if we have a defined plugin |
| 38 | context.removerust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]remove().(Capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/Capabilities#::PLUGIN_AUTHrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]PLUGIN_AUTH.); |
| 39 | } |
| 40 | |
| 41 | // NOTE: Half of this packet is identical to the SSL Request packet |
| 42 | SslRequestrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/ssl_request/SslRequest# { |
| 43 | max_packet_sizerust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/ssl_request/SslRequest#max_packet_size.: self.max_packet_sizerust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#max_packet_size., |
| 44 | collationrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/ssl_request/SslRequest#collation.: self.collationrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#collation., |
| 45 | } |
| 46 | .encode_withrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/ssl_request/impl#[SslRequest][`ProtocolEncode<'_, Capabilities>`]encode_with().(buf, context)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 47 | |
| 48 | buf.put_str_nulrust-analyzer cargo sqlx-core 0.8.3 io/buf_mut/impl#[`Vec<u8>`][BufMutExt]put_str_nul().(self.usernamerust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#username.); |
| 49 | |
| 50 | if context.containsrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]contains().(Capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/Capabilities#::PLUGIN_AUTH_LENENC_DATArust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]PLUGIN_AUTH_LENENC_DATA.) { |
| 51 | buf.put_bytes_lenencrust-analyzer cargo sqlx-mysql 0.8.3 io/buf_mut/impl#[`Vec<u8>`][MySqlBufMutExt]put_bytes_lenenc().(self.auth_responserust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#auth_response..unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().()); |
| 52 | } else if context.containsrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]contains().(Capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/Capabilities#::SECURE_CONNECTIONrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]SECURE_CONNECTION.) { |
| 53 | let response = self.auth_responserust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#auth_response..unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().(); |
| 54 | |
| 55 | let response_len = u8::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u8][`TryFrom<usize>`]try_from().(response.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) |
| 56 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!("auth_response.len() too long: {}", response.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 57 | |
| 58 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(response_len); |
| 59 | buf.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(response); |
| 60 | } else { |
| 61 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(0); |
| 62 | } |
| 63 | |
| 64 | if context.containsrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]contains().(Capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/Capabilities#::CONNECT_WITH_DBrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]CONNECT_WITH_DB.) { |
| 65 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(database) = &self.databaserust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#database. { |
| 66 | buf.put_str_nulrust-analyzer cargo sqlx-core 0.8.3 io/buf_mut/impl#[`Vec<u8>`][BufMutExt]put_str_nul().(database); |
| 67 | } else { |
| 68 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(0); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if context.containsrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]contains().(Capabilitiesrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/Capabilities#::PLUGIN_AUTHrust-analyzer cargo sqlx-mysql 0.8.3 protocol/capabilities/impl#[Capabilities]PLUGIN_AUTH.) { |
| 73 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(plugin) = &self.auth_pluginrust-analyzer cargo sqlx-mysql 0.8.3 protocol/connect/handshake_response/HandshakeResponse#auth_plugin. { |
| 74 | buf.put_str_nulrust-analyzer cargo sqlx-core 0.8.3 io/buf_mut/impl#[`Vec<u8>`][BufMutExt]put_str_nul().(plugin.namerust-analyzer cargo sqlx-mysql 0.8.3 protocol/auth/impl#[AuthPlugin]name().()); |
| 75 | } else { |
| 76 | buf.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(0); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 81 | } |
| 82 | } |