basileus 0.4.0

All-in-one library for user management, authorization, sessions and permission management
Documentation
use thiserror::Error;

#[derive(Debug, Error)]
pub enum CreateUserError {
    #[error(transparent)]
    SQL(#[from] sqlx::error::Error),
    #[error("user '{0}' already exists")]
    UserAlreadyExist(String),
    #[error("invalid username '{0}'")]
    InvalidName(String),
}

#[derive(Debug, Error)]
pub enum UpdatePassError {
    #[error(transparent)]
    Argon2(#[from] argon2::Error),
    #[error(transparent)]
    SQL(#[from] sqlx::error::Error),
    #[error("user '{0}' does not exist")]
    UserNotExist(String),
}

#[derive(Debug, Error)]
pub enum VerifyPassError {
    #[error(transparent)]
    Argon2(#[from] argon2::Error),
    #[error(transparent)]
    SQL(#[from] sqlx::error::Error),
    #[error("user '{0}' does not exist")]
    UserNotExist(String),
    #[error("user '{0}' has not yet defined password authorization")]
    PassUndefined(String),
}

#[derive(Debug, Error)]
pub enum DeleteUserError {
    #[error(transparent)]
    SQL(#[from] sqlx::error::Error),
    #[error("user '{0}' does not exist")]
    UserNotExist(String),
}

#[derive(Debug, Error)]
pub enum DeletePassError {
    #[error(transparent)]
    SQL(#[from] sqlx::error::Error),
    #[error("user '{0}' does not exist")]
    UserNotExist(String),
    #[error("user '{0}' has not yet defined password authorization")]
    PassUndefined(String),
}

#[derive(Debug, Error)]
pub enum GetPermError {
    #[error(transparent)]
    SQL(#[from] sqlx::error::Error),
    #[error("user '{0}' does not exist")]
    UserNotExist(String),
}

#[derive(Debug, Error)]
pub enum GivePermError {
    #[error(transparent)]
    SQL(#[from] sqlx::error::Error),
    #[error("user '{0}' does not exist")]
    UserNotExist(String),
    #[error(transparent)]
    GetDirectPerm(#[from] GetPermError),
    #[error(transparent)]
    SetPerm(#[from] SetPermError),
}

#[derive(Debug, Error)]
pub enum SetPermError {
    #[error(transparent)]
    SQL(#[from] sqlx::error::Error),
    #[error("user '{0}' does not exist")]
    UserNotExist(String),
}

#[derive(Debug, Error)]
pub enum RevokePermError {
    #[error(transparent)]
    SQL(#[from] sqlx::error::Error),
    #[error("user '{0}' does not exist")]
    UserNotExist(String),
    #[error(transparent)]
    GetPerm(#[from] GetPermError),
    #[error(transparent)]
    SetPerm(#[from] SetPermError),
}

#[derive(Debug, Error)]
pub enum CheckPermError {
    #[error(transparent)]
    SQL(#[from] sqlx::error::Error),
    #[error("user '{0}' does not exist")]
    UserNotExist(String),
    #[error(transparent)]
    GetDirectPerm(#[from] GetPermError),
    #[error(transparent)]
    SetPerm(#[from] SetPermError),
}

#[derive(Debug, Error)]
pub enum PkceAuthError {
    #[error(transparent)]
    VerifyPass(#[from] VerifyPassError),
    #[error("unauthorized")]
    Unauthorized,
    #[error("support only S256 code challenge method")]
    UnsupportedMethod,
    #[error("insecure `plain` transformation method is disallowed")]
    InsecurePlain,
}

#[derive(Debug, Error)]
pub enum PkceTokenError {
    #[error("invalid authorization code")]
    InvalidCode,
    #[error("expired authorization code")]
    ExpiredCode,
    #[error("invalid code verifier")]
    InvalidVerifier,
}