scylla_cql/frame/request/
auth_response.rs

1//! CQL protocol-level representation of a `AUTH_RESPONSE` request.
2
3use std::num::TryFromIntError;
4
5use thiserror::Error;
6
7use crate::frame::frame_errors::CqlRequestSerializationError;
8
9use crate::frame::request::{RequestOpcode, SerializableRequest};
10use crate::frame::types::write_bytes_opt;
11
12/// Represents AUTH_RESPONSE CQL request.
13///
14/// This request is sent by the client to respond to an authentication challenge.
15pub struct AuthResponse {
16    /// Raw response bytes.
17    pub response: Option<Vec<u8>>,
18}
19
20impl SerializableRequest for AuthResponse {
21    const OPCODE: RequestOpcode = RequestOpcode::AuthResponse;
22
23    fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), CqlRequestSerializationError> {
24        Ok(write_bytes_opt(self.response.as_ref(), buf)
25            .map_err(AuthResponseSerializationError::ResponseSerialization)?)
26    }
27}
28
29/// An error type returned when serialization of AUTH_RESPONSE request fails.
30#[non_exhaustive]
31#[derive(Error, Debug, Clone)]
32pub enum AuthResponseSerializationError {
33    /// Maximum response's body length exceeded.
34    #[error("AUTH_RESPONSE body bytes length too big: {0}")]
35    ResponseSerialization(TryFromIntError),
36}