use std::sync::Once;
pub use keyring_core::{Error, Result};
pub struct Entry {
pub inner: keyring_core::Entry,
}
impl Entry {
pub fn new(service: &str, username: &str) -> Result<Self> {
SET_CREDENTIAL_STORE.call_once(set_credential_store);
let inner = keyring_core::Entry::new(service, username)?;
Ok(Self { inner })
}
pub fn set_password(&self, password: &str) -> Result<()> {
self.inner.set_password(password)
}
pub fn set_secret(&self, secret: &[u8]) -> Result<()> {
self.inner.set_secret(secret)
}
pub fn get_password(&self) -> Result<String> {
self.inner.get_password()
}
pub fn get_secret(&self) -> Result<Vec<u8>> {
self.inner.get_secret()
}
pub fn delete_credential(&self) -> Result<()> {
self.inner.delete_credential()
}
}
static SET_CREDENTIAL_STORE: Once = Once::new();
fn set_credential_store() {
#[cfg(target_os = "macos")]
{
if let Ok(store) = apple_native_keyring_store::keychain::Store::new() {
keyring_core::set_default_store(store);
}
}
#[cfg(target_os = "windows")]
{
if let Ok(store) = windows_native_keyring_store::Store::new() {
keyring_core::set_default_store(store);
}
}
#[cfg(all(
unix,
not(any(target_os = "macos", target_os = "ios", target_os = "android"))
))]
{
if let Ok(store) = zbus_secret_service_keyring_store::Store::new() {
keyring_core::set_default_store(store);
}
}
}