Skip to content

Commit 1706290

Browse files
server: Rename GNOME types to make things clearer
1 parent 9ff9b32 commit 1706290

4 files changed

Lines changed: 34 additions & 41 deletions

File tree

server/src/gnome/prompter.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub enum PromptType {
240240
default_path = "/org/gnome/keyring/Prompter",
241241
gen_blocking = false
242242
)]
243-
pub trait Prompter {
243+
pub trait GNOMEPrompter {
244244
fn begin_prompting(&self, callback: &ObjectPath<'_>) -> Result<(), ServiceError>;
245245

246246
fn perform_prompt(
@@ -255,7 +255,7 @@ pub trait Prompter {
255255
}
256256

257257
#[derive(Debug, Clone)]
258-
pub struct PrompterCallback {
258+
pub struct GNOMEPrompterCallback {
259259
window_id: Option<WindowIdentifierType>,
260260
private_key: Arc<Key>,
261261
public_key: Arc<Key>,
@@ -266,7 +266,7 @@ pub struct PrompterCallback {
266266
}
267267

268268
#[zbus::interface(name = "org.gnome.keyring.internal.Prompter.Callback")]
269-
impl PrompterCallback {
269+
impl GNOMEPrompterCallback {
270270
pub async fn prompt_ready(
271271
&self,
272272
reply: Optional<Reply>,
@@ -317,7 +317,7 @@ impl PrompterCallback {
317317
}
318318
}
319319

320-
impl PrompterCallback {
320+
impl GNOMEPrompterCallback {
321321
pub async fn new(
322322
window_id: Option<WindowIdentifierType>,
323323
service: Service,
@@ -362,7 +362,7 @@ impl PrompterCallback {
362362
),
363363
};
364364

365-
let prompter = PrompterProxy::new(connection).await?;
365+
let prompter = GNOMEPrompterProxy::new(connection).await?;
366366
let path = self.path.clone();
367367
let exchange = self.exchange.get().unwrap().clone();
368368
tokio::spawn(async move {
@@ -374,7 +374,7 @@ impl PrompterCallback {
374374
}
375375

376376
async fn prompter_done(&self, prompt: &Prompt, exchange: &str) -> Result<(), ServiceError> {
377-
let prompter = PrompterProxy::new(self.service.connection()).await?;
377+
let prompter = GNOMEPrompterProxy::new(self.service.connection()).await?;
378378
let aes_key = secret_exchange::handshake(&self.private_key, exchange).map_err(|err| {
379379
custom_service_error(&format!(
380380
"Failed to generate AES key for SecretExchange {err}."
@@ -436,7 +436,7 @@ impl PrompterCallback {
436436

437437
async fn prompter_dismissed(&self, prompt_path: OwnedObjectPath) -> Result<(), ServiceError> {
438438
let path = self.path.clone();
439-
let prompter = PrompterProxy::new(self.service.connection()).await?;
439+
let prompter = GNOMEPrompterProxy::new(self.service.connection()).await?;
440440

441441
tokio::spawn(async move { prompter.stop_prompting(&path).await });
442442
let signal_emitter = self.service.signal_emitter(prompt_path)?;

server/src/prompt/mod.rs

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use zbus::{
1111
};
1212

1313
#[cfg(any(feature = "gnome_native_crypto", feature = "gnome_openssl_crypto"))]
14-
use crate::gnome::prompter::{PrompterCallback, PrompterProxy};
14+
use crate::gnome::prompter::{GNOMEPrompterCallback, GNOMEPrompterProxy};
1515
#[cfg(any(feature = "plasma_native_crypto", feature = "plasma_openssl_crypto"))]
1616
use crate::plasma::prompter::{PlasmaPrompterCallback, in_plasma_environment};
1717
use crate::{error::custom_service_error, service::Service};
@@ -64,10 +64,10 @@ pub struct Prompt {
6464
collection: Option<crate::collection::Collection>,
6565
/// GNOME Specific
6666
#[cfg(any(feature = "gnome_native_crypto", feature = "gnome_openssl_crypto"))]
67-
callback: Arc<OnceCell<PrompterCallback>>,
67+
gnome_callback: Arc<OnceCell<GNOMEPrompterCallback>>,
6868
/// KDE Plasma Specific
6969
#[cfg(any(feature = "plasma_native_crypto", feature = "plasma_openssl_crypto"))]
70-
callback_plasma: Arc<OnceCell<PlasmaPrompterCallback>>,
70+
plasma_callback: Arc<OnceCell<PlasmaPrompterCallback>>,
7171
/// The action to execute when the prompt completes
7272
action: Arc<Mutex<Option<PromptAction>>>,
7373
}
@@ -94,11 +94,10 @@ impl std::fmt::Debug for Prompt {
9494
#[interface(name = "org.freedesktop.Secret.Prompt")]
9595
impl Prompt {
9696
pub async fn prompt(&self, window_id: Optional<&str>) -> Result<(), ServiceError> {
97+
let window_id = (*window_id).and_then(|w| ashpd::WindowIdentifierType::from_str(w).ok());
9798
#[cfg(any(feature = "plasma_native_crypto", feature = "plasma_openssl_crypto"))]
9899
if in_plasma_environment(self.service.connection()).await {
99-
use ashpd::WindowIdentifierType;
100-
101-
if self.callback_plasma.get().is_some() {
100+
if self.plasma_callback.get().is_some() {
102101
return Err(custom_service_error(
103102
"A prompt callback is ongoing already.",
104103
));
@@ -108,7 +107,7 @@ impl Prompt {
108107
PlasmaPrompterCallback::new(self.service.clone(), self.path.clone()).await;
109108
let path = OwnedObjectPath::from(callback.path().clone());
110109

111-
self.callback_plasma
110+
self.plasma_callback
112111
.set(callback.clone())
113112
.expect("A prompt callback is only set once");
114113
self.service
@@ -117,36 +116,29 @@ impl Prompt {
117116
.await?;
118117
tracing::debug!("Prompt `{}` created.", self.path);
119118

120-
return callback
121-
.start(
122-
&self.role,
123-
WindowIdentifierType::from_str(window_id.unwrap_or("")).ok(),
124-
&self.label,
125-
)
126-
.await;
119+
return callback.start(&self.role, window_id, &self.label).await;
127120
}
128121

129122
#[cfg(any(feature = "gnome_native_crypto", feature = "gnome_openssl_crypto"))]
130123
{
131-
if self.callback.get().is_some() {
124+
if self.gnome_callback.get().is_some() {
132125
return Err(custom_service_error(
133-
"A prompt callback is ongoing already.",
126+
"A GNOME prompt callback is ongoing already.",
134127
));
135128
};
136129

137-
let callback = PrompterCallback::new(
138-
(*window_id).and_then(|w| ashpd::WindowIdentifierType::from_str(w).ok()),
139-
self.service.clone(),
140-
self.path.clone(),
141-
)
142-
.await
143-
.map_err(|err| {
144-
custom_service_error(&format!("Failed to create PrompterCallback {err}."))
145-
})?;
130+
let callback =
131+
GNOMEPrompterCallback::new(window_id, self.service.clone(), self.path.clone())
132+
.await
133+
.map_err(|err| {
134+
custom_service_error(&format!(
135+
"Failed to create GNOMEPrompterCallback {err}."
136+
))
137+
})?;
146138

147139
let path = OwnedObjectPath::from(callback.path().clone());
148140

149-
self.callback
141+
self.gnome_callback
150142
.set(callback.clone())
151143
.expect("A prompt callback is only set once");
152144

@@ -156,7 +148,7 @@ impl Prompt {
156148
// Starts GNOME System Prompting.
157149
// Spawned separately to avoid blocking the early return of the current
158150
// execution.
159-
let prompter = PrompterProxy::new(self.service.connection()).await?;
151+
let prompter = GNOMEPrompterProxy::new(self.service.connection()).await?;
160152
tokio::spawn(async move { prompter.begin_prompting(&path).await });
161153

162154
return Ok(());
@@ -170,16 +162,16 @@ impl Prompt {
170162

171163
pub async fn dismiss(&self) -> Result<(), ServiceError> {
172164
#[cfg(any(feature = "plasma_native_crypto", feature = "plasma_openssl_crypto"))]
173-
if let Some(callback_plasma) = self.callback_plasma.get() {
165+
if let Some(callback) = self.plasma_callback.get() {
174166
let emitter = SignalEmitter::from_parts(
175167
self.service.connection().clone(),
176-
callback_plasma.path().clone(),
168+
callback.path().clone(),
177169
);
178170
PlasmaPrompterCallback::dismiss(&emitter).await?;
179171
}
180172

181173
#[cfg(any(feature = "gnome_native_crypto", feature = "gnome_openssl_crypto"))]
182-
if let Some(_callback) = self.callback.get() {
174+
if let Some(_callback) = self.gnome_callback.get() {
183175
// TODO: figure out if we should destroy the un-export the callback
184176
// here?
185177
}
@@ -217,9 +209,9 @@ impl Prompt {
217209
label,
218210
collection,
219211
#[cfg(any(feature = "gnome_native_crypto", feature = "gnome_openssl_crypto"))]
220-
callback: Default::default(),
212+
gnome_callback: Default::default(),
221213
#[cfg(any(feature = "plasma_native_crypto", feature = "plasma_openssl_crypto"))]
222-
callback_plasma: Default::default(),
214+
plasma_callback: Default::default(),
223215
action: Arc::new(Mutex::new(None)),
224216
}
225217
}

server/src/prompt/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async fn prompt_not_found_error() -> Result<(), Box<dyn std::error::Error>> {
7272
setup.server.remove_prompt(&prompt_path).await;
7373

7474
// Manually serve a callback to trigger the error path
75-
let callback = crate::gnome::prompter::PrompterCallback::new(
75+
let callback = crate::gnome::prompter::GNOMEPrompterCallback::new(
7676
None,
7777
setup.server.clone(),
7878
prompt_path.clone(),

server/src/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ impl MockPrompterService {
414414
callback,
415415
type_
416416
);
417-
// This is called by PrompterCallback.prompter_init() with the server's exchange
417+
// This is called by GNOMEPrompterCallback.prompter_init() with the server's
418+
// exchange
418419
let callback_path = callback.to_owned();
419420
let unlock_password = self.unlock_password.clone();
420421
let should_accept = self.should_accept.clone();

0 commit comments

Comments
 (0)