scylla_cql/frame/response/
authenticate.rs

1//! CQL protocol-level representation of an `AUTHENTICATE` response.
2
3use crate::frame::frame_errors::{
4    CqlAuthChallengeParseError, CqlAuthSuccessParseError, CqlAuthenticateParseError,
5};
6use crate::frame::types;
7
8/// Represents AUTHENTICATE CQL response.
9#[derive(Debug)]
10pub struct Authenticate {
11    /// The name of the authenticator requested by the server to use.
12    pub authenticator_name: String,
13}
14
15impl Authenticate {
16    /// Deserializes an `AUTHENTICATE` message from the provided buffer.
17    pub fn deserialize(buf: &mut &[u8]) -> Result<Self, CqlAuthenticateParseError> {
18        let authenticator_name = types::read_string(buf)
19            .map_err(CqlAuthenticateParseError::AuthNameParseError)?
20            .to_string();
21
22        Ok(Authenticate { authenticator_name })
23    }
24}
25
26/// Represents AUTH_SUCCESS CQL response.
27#[derive(Debug)]
28pub struct AuthSuccess {
29    /// Optional success message provided by the server.
30    pub success_message: Option<Vec<u8>>,
31}
32
33impl AuthSuccess {
34    /// Deserializes an `AUTH_SUCCESS` message from the provided buffer.
35    pub fn deserialize(buf: &mut &[u8]) -> Result<Self, CqlAuthSuccessParseError> {
36        let success_message = types::read_bytes_opt(buf)
37            .map_err(CqlAuthSuccessParseError::SuccessMessageParseError)?
38            .map(ToOwned::to_owned);
39
40        Ok(AuthSuccess { success_message })
41    }
42}
43
44/// Represents AUTH_CHALLENGE CQL response.
45///
46/// This message is sent by the server to challenge the client to provide
47/// authentication credentials. The client must respond with an `AUTH_RESPONSE`
48/// message containing the credentials.
49#[derive(Debug)]
50pub struct AuthChallenge {
51    /// The challenge sent by the server, whose semantics depend on the
52    /// authenticator being used.
53    pub authenticate_message: Option<Vec<u8>>,
54}
55
56impl AuthChallenge {
57    /// Deserializes an `AUTH_CHALLENGE` message from the provided buffer.
58    pub fn deserialize(buf: &mut &[u8]) -> Result<Self, CqlAuthChallengeParseError> {
59        let authenticate_message = types::read_bytes_opt(buf)
60            .map_err(CqlAuthChallengeParseError::AuthMessageParseError)?
61            .map(|b| b.to_owned());
62
63        Ok(AuthChallenge {
64            authenticate_message,
65        })
66    }
67}