Skip to content

Commit ec508d0

Browse files
committed
change PrimaryPasswordAuthenticator callbacks to be async
This is a breaking change, but not yet used by anyone.
1 parent c99e053 commit ec508d0

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# v142.0 (In progress)
22
[Full Changelog](In progress)
33

4+
### Logins
5+
- expose constructors for `ManagedEncryptorDecryptor` and `NSSKeyManager`
6+
- change PrimaryPasswordAuthenticator callbacks to be async (a breaking change, but not yet used by anyone)
7+
48
# v141.0 (_2025-06-23_)
59

610
## ✨ What's New ✨
@@ -13,7 +17,6 @@
1317
- add checkpoint API: `set_checkpoint(checkpoint)` and `get_checkpoint()` for desktop's rolling migration
1418
- add `delete_many(ids)` for batch deletion within a single transaction
1519
- Add `count()`, `count_by_origin()` and `count_by_form_action_origin()` methods
16-
- expose constructors for `ManagedEncryptorDecryptor` and `NSSKeyManager`
1720

1821
### Sync Manager
1922
- Added sync settings metrics for mobile. [#6786](https://github.com/mozilla/application-services/pull/6786)

components/logins/src/encryption.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ pub trait PrimaryPasswordAuthenticator: Send + Sync {
184184
/// Get a primary password for authentication, otherwise return the
185185
/// AuthenticationCancelled error to cancel the authentication process.
186186
async fn get_primary_password(&self) -> ApiResult<String>;
187-
fn on_authentication_success(&self);
188-
fn on_authentication_failure(&self);
187+
async fn on_authentication_success(&self);
188+
async fn on_authentication_failure(&self);
189189
}
190190

191191
/// Use the `NSSKeyManager` to use NSS for key management.
@@ -215,11 +215,11 @@ pub trait PrimaryPasswordAuthenticator: Send + Sync {
215215
/// Ok("secret".to_string())
216216
/// }
217217
///
218-
/// fn on_authentication_success(&self) {
218+
/// async fn on_authentication_success(&self) {
219219
/// println!("success");
220220
/// }
221221
///
222-
/// fn on_authentication_failure(&self) {
222+
/// async fn on_authentication_failure(&self) {
223223
/// println!("this did not work, please try again:");
224224
/// }
225225
/// }
@@ -284,19 +284,25 @@ impl KeyManager for NSSKeyManager {
284284
let mut result = api_authenticate_with_primary_password(&primary_password)?;
285285

286286
if result {
287-
self.primary_password_authenticator
288-
.on_authentication_success();
287+
block_on(
288+
self.primary_password_authenticator
289+
.on_authentication_success(),
290+
);
289291
} else {
290292
while !result {
291-
self.primary_password_authenticator
292-
.on_authentication_failure();
293+
block_on(
294+
self.primary_password_authenticator
295+
.on_authentication_failure(),
296+
);
293297

294298
let primary_password =
295299
block_on(self.primary_password_authenticator.get_primary_password())?;
296300
result = api_authenticate_with_primary_password(&primary_password)?;
297301
}
298-
self.primary_password_authenticator
299-
.on_authentication_success();
302+
block_on(
303+
self.primary_password_authenticator
304+
.on_authentication_success(),
305+
);
300306
}
301307
}
302308

@@ -458,8 +464,8 @@ mod keydb_test {
458464
async fn get_primary_password(&self) -> ApiResult<String> {
459465
Ok(self.password.clone())
460466
}
461-
fn on_authentication_success(&self) {}
462-
fn on_authentication_failure(&self) {}
467+
async fn on_authentication_success(&self) {}
468+
async fn on_authentication_failure(&self) {}
463469
}
464470

465471
fn profile_path() -> PathBuf {

examples/sync-pass/src/sync-pass.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ impl PrimaryPasswordAuthenticator for MyPrimaryPasswordAuthenticator {
306306
Ok(password)
307307
}
308308

309-
fn on_authentication_success(&self) {
309+
async fn on_authentication_success(&self) {
310310
println!("success");
311311
}
312312

313-
fn on_authentication_failure(&self) {
313+
async fn on_authentication_failure(&self) {
314314
println!("this did not work, please try again:");
315315
}
316316
}

0 commit comments

Comments
 (0)