| 1 | use crate::io::ProtocolEncode; |
| 2 | use crate::protocol::Capabilities; |
| 3 | |
| 4 | // https://dev.mysql.com/doc/dev/mysql-server/8.0.12/page_protocol_connection_phase_packets_protocol_handshake_response.html |
| 5 | // https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::SSLRequest |
| 6 | |
| 7 | #[derive(Debug)] |
| 8 | pub struct SslRequest { |
| 9 | pub max_packet_size: u32, |
| 10 | pub collation: u8, |
| 11 | } |
| 12 | |
| 13 | impl ProtocolEncode<'_, Capabilities> for SslRequest { |
| 14 | fn encode_with(&self, buf: &mut Vec<u8>, context: Capabilities) -> Result<(), crate::Error> { |
| 15 | // truncation is intended |
| 16 | #[allow(clippy::cast_possible_truncation)] |
| 17 | buf.extend(&(context.bits() as u32).to_le_bytes()); |
| 18 | buf.extend(&self.max_packet_size.to_le_bytes()); |
| 19 | buf.push(self.collation); |
| 20 | |
| 21 | // reserved: string<19> |
| 22 | buf.extend(&[0_u8; 19]); |
| 23 | |
| 24 | if context.contains(Capabilities::MYSQL) { |
| 25 | // reserved: string<4> |
| 26 | buf.extend(&[0_u8; 4]); |
| 27 | } else { |
| 28 | // extended client capabilities (MariaDB-specified): int<4> |
| 29 | buf.extend(&((context.bits() >> 32) as u32).to_le_bytes()); |
| 30 | } |
| 31 | |
| 32 | Ok(()) |
| 33 | } |
| 34 | } |