Skip to content

Commit

Permalink
migration: Fallback to plain secret service if encrypted fails
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Aug 10, 2023
1 parent a9a49c3 commit 5a954f1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/migration.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
use std::collections::HashMap;

use crate::{dbus::Service, portal::Keyring, Result};
use crate::{
dbus::{self, Algorithm, Service},
portal::Keyring,
Result,
};

/// Helper to migrate your secrets from the host Secret Service
/// to the sandboxed file backend.
///
/// If the migration is successful, the items are removed from the host
/// Secret Service.
pub async fn migrate(attributes: Vec<HashMap<&str, &str>>, replace: bool) -> Result<()> {
let service = Service::new(crate::dbus::Algorithm::Encrypted).await?;
let service = match Service::new(Algorithm::Encrypted).await {
Ok(service) => Ok(service),
Err(dbus::Error::Zbus(zbus::Error::MethodError(_, _, _))) => {
dbus::Service::new(Algorithm::Plain).await
}
Err(e) => Err(e),
}?;
let file_backend = match Keyring::load_default().await {
Ok(portal) => Ok(portal),
Err(crate::portal::Error::PortalNotAvailable) => {
Expand Down

0 comments on commit 5a954f1

Please sign in to comment.