| 288 | } |
| 289 | |
| 290 | fn parse_authentication( |
| 291 | &self, |
| 292 | length: usize, |
| 293 | reader: &mut BufferReader<'_>, |
| 294 | ) -> Result<BackendMessage> { |
| 295 | let code = reader.int32()?; |
| 296 | let message = match code { |
| 297 | 0 => AuthenticationMessage::Ok(AuthenticationOk { length }), |
| 298 | 3 => AuthenticationMessage::Cleartext(AuthenticationCleartextPassword { length }), |
| 299 | 5 => { |
| 300 | let salt = reader.bytes(4)?; |
| 301 | AuthenticationMessage::Md5(AuthenticationMD5Password { length, salt }) |
| 302 | } |
| 303 | 10 => { |
| 304 | let mut mechanisms = Vec::new(); |
| 305 | loop { |
| 306 | let mechanism = reader.cstring()?; |
| 307 | if mechanism.is_empty() { |
| 308 | break; |
| 309 | } |
| 310 | mechanisms.push(mechanism); |
| 311 | } |
| 312 | AuthenticationMessage::Sasl(AuthenticationSasl { length, mechanisms }) |
| 313 | } |
| 314 | 11 => { |
| 315 | let data = reader.string(length.saturating_sub(8))?; |
| 316 | AuthenticationMessage::SaslContinue(AuthenticationSaslContinue { length, data }) |
| 317 | } |
| 318 | 12 => { |
| 319 | let data = reader.string(length.saturating_sub(8))?; |
| 320 | AuthenticationMessage::SaslFinal(AuthenticationSaslFinal { length, data }) |
| 321 | } |
| 322 | other => { |
| 323 | return Err(anyhow!( |
| 324 | "Unknown authentication message type {other} (length={length})" |
| 325 | )); |
| 326 | } |
| 327 | }; |
| 328 | Ok(BackendMessage::Authentication(message)) |
| 329 | } |
| 330 | |
| 331 | fn parse_error_message( |
| 332 | &self, |