tilo-secrets 0.5.1

App-scoped secret storage on Linux, macOS, Windows and the web: the Secret Service, the Keychain, Credential Manager, and WebCrypto-wrapped IndexedDB.
Documentation
//! What this crate provides on each target, as data an app can query.

pub use tilo_platform_caps::{Availability, availability, available};

pub type Unsupported = tilo_platform_caps::Unsupported<Feature>;

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Feature {
    Store,
    /// Secrets held by the operating system's keychain rather than wrapped
    /// by the browser ([`Protection::OsKeychain`](crate::Protection::OsKeychain)).
    OsKeychain,
    Blocking,
}

pub(crate) const WEB_KEYCHAIN: &str =
    "Browsers have no keychain; Tilo encrypts secrets with a key the browser keeps.";
pub(crate) const WEB_BLOCKING: &str = "The browser's storage answers asynchronously.";

impl tilo_platform_caps::Feature for Feature {
    /// The feature's availability on Linux (and Windows), macOS and the web, in that
    /// order. A Linux session without a Secret Service provides less, and the macOS
    /// Keychain may ask the user to allow access.
    fn targets(self) -> [Availability; 3] {
        use Availability::{Available, Unsupported};
        match self {
            Self::Store => [Available, Available, Available],
            Self::OsKeychain => [Available, Available, Unsupported(WEB_KEYCHAIN)],
            Self::Blocking => [Available, Available, Unsupported(WEB_BLOCKING)],
        }
    }
}