secret_rs 0.5.1

a library to embed a secret value into a running binary
Documentation
use std::{fmt, path::PathBuf};

#[derive(Debug, Clone, PartialEq)]
pub enum SecretError {
    Decode(String, String),
    InvalidUtf8(String),
    FileRead(PathBuf, String),
    Json(String),
    JsonKey(String),
    JsonTraverse(String),
    Ini(String),
}

impl fmt::Display for SecretError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Decode(encoding, err) => {
                write!(f, "cannot decode as {encoding} with padding: {err}")
            }
            Self::InvalidUtf8(err) => {
                write!(f, "cannot read utf8 string from decoded content: {err}")
            }
            Self::FileRead(path, err) => write!(
                f,
                "cannot read file at '{path}': {err}",
                path = String::from_utf8_lossy(path.as_os_str().as_encoded_bytes())
            ),
            Self::Json(err) => write!(f, "cannot load file as 'json': {err}"),
            Self::JsonKey(key) => write!(f, "no key '{key}' found"),
            Self::JsonTraverse(err) => write!(f, "cannot traverse json structure: {err}"),
            Self::Ini(err) => write!(f, "cannot load file as 'ini': {err}"),
        }
    }
}

impl std::error::Error for SecretError {}

pub type Result<T, E = SecretError> = std::result::Result<T, E>;