Skip to content

Commit 35dd1c9

Browse files
client: Add a helper for getting sandboxed app secret
1 parent 3251d35 commit 35dd1c9

3 files changed

Lines changed: 13 additions & 16 deletions

File tree

client/src/keyring.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ impl Keyring {
3131
#[cfg(feature = "tracing")]
3232
tracing::debug!("Application is sandboxed, using the file backend");
3333

34-
let secret = Secret::from(
35-
ashpd::desktop::secret::retrieve()
36-
.await
37-
.map_err(crate::file::Error::from)?,
38-
);
34+
let secret = Secret::sandboxed().await?;
3935
match file::UnlockedKeyring::load(
4036
crate::file::api::Keyring::default_path()?,
4137
secret.clone(),
@@ -81,12 +77,7 @@ impl Keyring {
8177
tracing::debug!("Unlocking file backend keyring");
8278

8379
// Retrieve secret from portal
84-
let secret = Secret::from(
85-
ashpd::desktop::secret::retrieve()
86-
.await
87-
.map_err(crate::file::Error::from)?,
88-
);
89-
80+
let secret = Secret::sandboxed().await?;
9081
let unlocked = locked.unlock(secret).await.map_err(crate::Error::File)?;
9182
*kg = Some(file::Keyring::Unlocked(unlocked));
9283
} else {

client/src/migration.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ use crate::{AsAttributes, Result, dbus::Service, file::UnlockedKeyring};
77
/// Secret Service.
88
pub async fn migrate(attributes: Vec<impl AsAttributes>, replace: bool) -> Result<()> {
99
let service = Service::new().await?;
10-
let secret = crate::Secret::from(
11-
ashpd::desktop::secret::retrieve()
12-
.await
13-
.map_err(crate::file::Error::from)?,
14-
);
10+
let secret = crate::Secret::sandboxed().await?;
1511
let file_backend =
1612
match UnlockedKeyring::load(crate::file::api::Keyring::default_path()?, secret).await {
1713
Ok(file) => Ok(file),

client/src/secret.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ impl Secret {
7979
Ok(Self::blob(secret))
8080
}
8181

82+
/// Get the sandboxed app secret if the app is sandboxed using
83+
/// org.freedesktop.portal.Secret portal.
84+
pub async fn sandboxed() -> Result<Self, crate::file::Error> {
85+
Ok(Self::blob(
86+
ashpd::desktop::secret::retrieve()
87+
.await
88+
.map_err(crate::file::Error::from)?,
89+
))
90+
}
91+
8292
/// Create a text secret, stored with `text/plain` content type.
8393
pub fn text(value: impl AsRef<str>) -> Self {
8494
Self::Text(value.as_ref().to_owned())

0 commit comments

Comments
 (0)