sos-platform-authenticator 0.17.0

Platform authenticator and keyring suppport for the Save Our Secrets SDK.
Documentation
use http::StatusCode;
use thiserror::Error;

/// Errors generated by the platform authenticator library.
#[derive(Debug, Error)]
pub enum Error {
    /// Error generated when a keyring entry could not be found.
    #[error("keyring entry not found")]
    NoKeyringEntry,

    /// Error generated when it is not possible to authenticate
    /// using the platform authenticator and keyring; authentication
    /// may still succeed with a password supplied by the user.
    #[error("unauthorized")]
    Unauthorized,

    /// Error generated when an attempt to authenticate failed.
    #[error("forbidden")]
    Forbidden,

    /// Error generated converting to UTF-8.
    #[cfg(all(not(target_os = "android"), not(target_os = "macos")))]
    #[error(transparent)]
    Keyring(#[from] keyring::Error),

    /// Error generated converting to UTF-8.
    #[error(transparent)]
    Utf8(#[from] std::str::Utf8Error),

    /// Error generated by the security framework.
    #[cfg(target_os = "macos")]
    #[error(transparent)]
    SecurityFramework(#[from] security_framework::base::Error),
}

impl From<&Error> for StatusCode {
    fn from(value: &Error) -> Self {
        match value {
            Error::NoKeyringEntry => StatusCode::NOT_FOUND,
            Error::Unauthorized => StatusCode::UNAUTHORIZED,
            Error::Forbidden => StatusCode::FORBIDDEN,
            _ => StatusCode::INTERNAL_SERVER_ERROR,
        }
    }
}