Skip to content

Commit

Permalink
f_errors: CqlAuthChallengeParseError
Browse files Browse the repository at this point in the history
  • Loading branch information
muzarski committed Aug 22, 2024
1 parent f1c92cc commit 6fcbe9a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions scylla-cql/src/frame/frame_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub enum FrameError {

#[derive(Error, Debug)]
pub enum ParseError {
#[error(transparent)]
CqlAuthChallengeParseError(#[from] CqlAuthChallengeParseError),
#[error(transparent)]
CqlAuthSuccessParseError(#[from] CqlAuthSuccessParseError),
#[error(transparent)]
Expand Down Expand Up @@ -63,6 +65,14 @@ pub enum ParseError {
CqlTypeError(#[from] CqlTypeError),
}

/// An error type returned when deserialization of AUTH_CHALLENGE response fails.
#[non_exhaustive]
#[derive(Error, Debug)]
pub enum CqlAuthChallengeParseError {
#[error("Malformed authenticate message: {0}")]
AuthMessageParseError(LowLevelDeserializationError),
}

/// An error type returned when deserialization of AUTH_SUCCESS response fails.
#[non_exhaustive]
#[derive(Error, Debug)]
Expand Down
10 changes: 7 additions & 3 deletions scylla-cql/src/frame/response/authenticate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::frame::frame_errors::{CqlAuthSuccessParseError, CqlAuthenticateParseError, ParseError};
use crate::frame::frame_errors::{
CqlAuthChallengeParseError, CqlAuthSuccessParseError, CqlAuthenticateParseError,
};
use crate::frame::types;

// Implements Authenticate message.
Expand Down Expand Up @@ -38,8 +40,10 @@ pub struct AuthChallenge {
}

impl AuthChallenge {
pub fn deserialize(buf: &mut &[u8]) -> Result<Self, ParseError> {
let authenticate_message = types::read_bytes_opt(buf)?.map(|b| b.to_owned());
pub fn deserialize(buf: &mut &[u8]) -> Result<Self, CqlAuthChallengeParseError> {
let authenticate_message = types::read_bytes_opt(buf)
.map_err(CqlAuthChallengeParseError::AuthMessageParseError)?
.map(|b| b.to_owned());

Ok(AuthChallenge {
authenticate_message,
Expand Down

0 comments on commit 6fcbe9a

Please sign in to comment.