Skip to main content

fraiseql_wire/auth/
mod.rs

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