pub(crate) mod passphrase;
#[cfg(feature = "secret-service")]
pub(crate) mod secret_service;
#[cfg(feature = "macos-keychain")]
pub(crate) mod macos_keychain;
#[cfg(feature = "fido2")]
pub(crate) mod fido2;
#[cfg(feature = "tpm")]
pub(crate) mod tpm;
#[cfg(feature = "systemd-creds")]
pub(crate) mod systemd_creds;
#[cfg(feature = "fprintd")]
pub(crate) mod fprintd;
#[cfg(feature = "ssh-agent-piggyback")]
pub(crate) mod ssh_agent;
use anyhow::Result;
#[cfg_attr(
all(feature = "unstable", nightly),
allow(multiple_supertrait_upcastable)
)]
pub(crate) trait UnlockBackend: Send + Sync {
fn retrieve_passphrase(&self) -> Result<String>;
fn set_passphrase(&self) -> Result<String> {
self.retrieve_passphrase()
}
#[allow(dead_code)]
fn name(&self) -> &'static str;
}
#[cfg(test)]
mod tests {
use super::UnlockBackend;
struct AlwaysOkBackend;
impl UnlockBackend for AlwaysOkBackend {
fn retrieve_passphrase(&self) -> anyhow::Result<String> {
Ok("the-passphrase".to_string())
}
fn name(&self) -> &'static str {
"always-ok"
}
}
#[test]
fn default_set_passphrase_delegates_to_retrieve() -> anyhow::Result<()> {
assert_eq!(AlwaysOkBackend.set_passphrase()?, "the-passphrase");
Ok(())
}
#[test]
fn backend_name_returns_correct_str() {
assert_eq!(AlwaysOkBackend.name(), "always-ok");
}
}