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