Skip to main content

fraiseql_wire/auth/
mod.rs

1//! Wire-protocol SCRAM-SHA-256 authentication errors.
2//!
3//! Supports SCRAM-SHA-256 (Postgres 10+) as the primary authentication method.
4//! The `AuthError` here is specific to the wire protocol handshake — NOT the
5//! same as `fraiseql_error::AuthError` (domain) or `fraiseql_auth::AuthError`
6//! (OIDC/JWT middleware).
7
8pub mod scram;
9
10pub use scram::{ScramClient, ScramError};
11
12use std::fmt;
13
14/// Authentication error types
15#[derive(Debug, Clone)]
16#[non_exhaustive]
17pub enum AuthError {
18    /// SCRAM-specific error
19    Scram(ScramError),
20    /// Server doesn't support required mechanism
21    MechanismNotSupported(String),
22    /// Invalid server message format
23    InvalidServerMessage(String),
24    /// UTF-8 encoding error
25    Utf8Error(String),
26}
27
28impl fmt::Display for AuthError {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        match self {
31            AuthError::Scram(e) => write!(f, "SCRAM authentication error: {}", e),
32            AuthError::MechanismNotSupported(mech) => {
33                write!(f, "server does not support mechanism: {}", mech)
34            }
35            AuthError::InvalidServerMessage(msg) => {
36                write!(f, "invalid server message format: {}", msg)
37            }
38            AuthError::Utf8Error(msg) => write!(f, "UTF-8 encoding error: {}", msg),
39        }
40    }
41}
42
43impl std::error::Error for AuthError {}
44
45impl From<ScramError> for AuthError {
46    fn from(e: ScramError) -> Self {
47        AuthError::Scram(e)
48    }
49}