Skip to main content

fritz_core/secrets/
platform.rs

1//! The credential store of the operating system.
2//!
3//! Excluded from coverage (see `codecov.yml`): CI has no keychain, and tests
4//! must never touch the keychain of a developer.
5
6use std::sync::Arc;
7
8use keyring_core::CredentialStore;
9
10use super::{Error, Keychain};
11
12impl Keychain {
13    /// The keychain of the operating system.
14    pub fn platform() -> Result<Self, Error> {
15        store().map(Self::with_store).map_err(Error::Keychain)
16    }
17}
18
19#[cfg(target_os = "macos")]
20fn store() -> keyring_core::Result<Arc<CredentialStore>> {
21    Ok(apple_native_keyring_store::keychain::Store::new()?)
22}
23
24#[cfg(target_os = "windows")]
25fn store() -> keyring_core::Result<Arc<CredentialStore>> {
26    Ok(windows_native_keyring_store::Store::new()?)
27}
28
29#[cfg(not(any(target_os = "macos", target_os = "windows")))]
30fn store() -> keyring_core::Result<Arc<CredentialStore>> {
31    Ok(zbus_secret_service_keyring_store::Store::new()?)
32}