Skip to content

Commit 3b40dd9

Browse files
server: Make use of ashpd::WindowIdentifierType
1 parent 438be39 commit 3b40dd9

4 files changed

Lines changed: 30 additions & 18 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ rust-version.workspace = true
1010
version.workspace = true
1111

1212
[dependencies]
13+
ashpd = {workspace = true, features = ["backend", "tracing"]}
1314
base64 = "0.22"
1415
clap.workspace = true
1516
enumflags2 = "0.7"

server/src/gnome/prompter.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use oo7::{dbus::ServiceError, Key};
3+
use oo7::{ashpd::WindowIdentifierType, dbus::ServiceError, Key};
44
use serde::{Deserialize, Serialize};
55
use tokio::sync::OnceCell;
66
use zbus::zvariant::{self, as_value, Optional, OwnedObjectPath, Type};
@@ -36,15 +36,15 @@ struct Properties {
3636
#[serde(with = "as_value::optional", skip_serializing_if = "Option::is_none")]
3737
choice_chosen: Option<bool>,
3838
#[serde(with = "as_value::optional", skip_serializing_if = "Option::is_none")]
39-
caller_window: Option<String>,
39+
caller_window: Option<WindowIdentifierType>,
4040
#[serde(with = "as_value::optional", skip_serializing_if = "Option::is_none")]
4141
continue_label: Option<String>,
4242
#[serde(with = "as_value::optional", skip_serializing_if = "Option::is_none")]
4343
cancel_label: Option<String>,
4444
}
4545

4646
impl Properties {
47-
fn for_lock(keyring: &str, window_id: Option<&str>) -> Self {
47+
fn for_lock(keyring: &str, window_id: Option<WindowIdentifierType>) -> Self {
4848
Self {
4949
title: None,
5050
message: Some("Lock Keyring".to_owned()),
@@ -54,13 +54,17 @@ impl Properties {
5454
password_strength: None,
5555
choice_label: None,
5656
choice_chosen: None,
57-
caller_window: window_id.map(ToOwned::to_owned),
57+
caller_window: window_id,
5858
continue_label: Some("Lock".to_owned()),
5959
cancel_label: Some("Cancel".to_owned()),
6060
}
6161
}
6262

63-
fn for_unlock(keyring: &str, warning: Option<&str>, window_id: Option<&str>) -> Self {
63+
fn for_unlock(
64+
keyring: &str,
65+
warning: Option<&str>,
66+
window_id: Option<WindowIdentifierType>,
67+
) -> Self {
6468
Self {
6569
title: Some("Unlock Keyring".to_owned()),
6670
message: Some("Authentication required".to_owned()),
@@ -73,7 +77,7 @@ impl Properties {
7377
password_strength: None,
7478
choice_label: None,
7579
choice_chosen: None,
76-
caller_window: window_id.map(ToOwned::to_owned),
80+
caller_window: window_id,
7781
continue_label: Some("Unlock".to_owned()),
7882
cancel_label: Some("Cancel".to_owned()),
7983
}
@@ -138,7 +142,7 @@ pub trait Prompter {
138142

139143
#[derive(Debug, Clone)]
140144
pub struct PrompterCallback {
141-
window_id: Option<String>,
145+
window_id: Option<WindowIdentifierType>,
142146
private_key: Arc<Key>,
143147
public_key: Arc<Key>,
144148
aes_key: Arc<OnceCell<Key>>,
@@ -202,15 +206,15 @@ impl PrompterCallback {
202206

203207
impl PrompterCallback {
204208
pub async fn new(
205-
window_id: Option<&str>,
209+
window_id: Option<WindowIdentifierType>,
206210
service: Service,
207211
prompt_path: OwnedObjectPath,
208212
) -> Result<Self, oo7::crypto::Error> {
209213
let index = service.prompt_index().await;
210214
let private_key = Arc::new(Key::generate_private_key()?);
211215
let public_key = Arc::new(crate::gnome::crypto::generate_public_key(&private_key)?);
212216
Ok(Self {
213-
window_id: window_id.map(ToOwned::to_owned),
217+
window_id,
214218
public_key,
215219
private_key,
216220
aes_key: Default::default(),
@@ -236,7 +240,7 @@ impl PrompterCallback {
236240

237241
let (properties, prompt_type) = match prompt.role() {
238242
PromptRole::Lock => (
239-
Properties::for_lock(&label, self.window_id.as_deref()),
243+
Properties::for_lock(&label, self.window_id.clone()),
240244
PromptType::Confirm,
241245
),
242246
PromptRole::Unlock => {
@@ -250,7 +254,7 @@ impl PrompterCallback {
250254
self.aes_key.set(aes_key).unwrap();
251255

252256
(
253-
Properties::for_unlock(&label, None, self.window_id.as_deref()),
257+
Properties::for_unlock(&label, None, self.window_id.clone()),
254258
PromptType::Password,
255259
)
256260
}
@@ -304,7 +308,7 @@ impl PrompterCallback {
304308
let properties = Properties::for_unlock(
305309
&label,
306310
Some("The unlock password was incorrect"),
307-
self.window_id.as_deref(),
311+
self.window_id.clone(),
308312
);
309313
let server_exchange = self
310314
.exchange

server/src/prompt.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// org.freedesktop.Secret.Prompt
22

3-
use std::sync::Arc;
3+
use std::{str::FromStr, sync::Arc};
44

55
use oo7::dbus::ServiceError;
66
use tokio::sync::OnceCell;
@@ -56,11 +56,17 @@ impl Prompt {
5656
));
5757
};
5858

59-
let callback = PrompterCallback::new(*window_id, self.service.clone(), self.path.clone())
60-
.await
61-
.map_err(|err| {
62-
custom_service_error(&format!("Failed to create PrompterCallback {err}."))
63-
})?;
59+
let callback = PrompterCallback::new(
60+
(*window_id)
61+
.map(|w| ashpd::WindowIdentifierType::from_str(w).ok())
62+
.flatten(),
63+
self.service.clone(),
64+
self.path.clone(),
65+
)
66+
.await
67+
.map_err(|err| {
68+
custom_service_error(&format!("Failed to create PrompterCallback {err}."))
69+
})?;
6470

6571
let path = callback.path().clone();
6672

0 commit comments

Comments
 (0)