//! Thin async D-Bus wrapper around `io.dangerousthings.AuthForge1`. Each method //! is one `Proxy::call` round-trip. Connection + proxy hold owned state so the //! Daemon handle can be passed around freely. use anyhow::{Context, Result}; use authforge_common::policy::Policy; use authforge_common::types::{Credential, PendingFlag, PolicyApplyResult, RecoveryCodeSummary}; const BUS_NAME: &str = "io.dangerousthings.AuthForge"; const OBJECT_PATH: &str = "/io/dangerousthings/AuthForge"; const IFACE: &str = "io.dangerousthings.AuthForge1"; pub(crate) struct Daemon { proxy: zbus::Proxy<'static>, } impl Daemon { pub async fn connect() -> Result { let conn = zbus::Connection::system() .await .context("connecting to system D-Bus")?; let proxy = zbus::Proxy::new_owned(conn, BUS_NAME, OBJECT_PATH, IFACE) .await .context("constructing AuthForge proxy")?; Ok(Self { proxy }) } pub async fn list_credentials(&self, user: &str) -> Result> { Ok(self.proxy.call("ListCredentials", &(user,)).await?) } pub async fn enroll_own(&self, user: &str, nickname: &str) -> Result { Ok(self.proxy.call("EnrollOwn", &(user, nickname)).await?) } pub async fn remove_own(&self, user: &str, cred_id: &str) -> Result<()> { Ok(self.proxy.call("RemoveOwn", &(user, cred_id)).await?) } pub async fn get_policy(&self) -> Result { Ok(self.proxy.call("GetPolicy", &()).await?) } pub async fn set_policy(&self, p: &Policy, force: bool) -> Result { Ok(self.proxy.call("SetPolicy", &(p, force)).await?) } pub async fn set_pending_flag(&self, user: &str, flag: &PendingFlag) -> Result<()> { Ok(self.proxy.call("SetPendingFlag", &(user, flag)).await?) } pub async fn clear_pending_flag(&self, user: &str) -> Result<()> { Ok(self.proxy.call("ClearPendingFlag", &(user,)).await?) } pub async fn generate_recovery_code(&self, user: &str) -> Result { Ok(self.proxy.call("GenerateRecoveryCode", &(user,)).await?) } pub async fn list_recovery_codes(&self) -> Result> { Ok(self.proxy.call("ListRecoveryCodes", &()).await?) } pub async fn revoke_recovery_code(&self, user: &str) -> Result { Ok(self.proxy.call("RevokeRecoveryCode", &(user,)).await?) } }