Skip to content

Commit

Permalink
crypto: rename Account::generate_one_time_keys to `Account::generat…
Browse files Browse the repository at this point in the history
…e_one_time_keys_if_needed`
  • Loading branch information
bnjbvr committed Jan 11, 2024
1 parent 1911d2c commit f5f5ea7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions crates/matrix-sdk-crypto/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2244,7 +2244,7 @@ pub(crate) mod tests {
let account = tr.account().await.unwrap();
account.generate_fallback_key_helper();
account.update_uploaded_key_count(0);
account.generate_one_time_keys();
account.generate_one_time_keys_if_needed();
let request = machine
.keys_for_upload(account)
.await
Expand Down Expand Up @@ -2370,7 +2370,7 @@ pub(crate) mod tests {
.store()
.with_transaction(|mut tr| async {
let account = tr.account().await.unwrap();
assert!(account.generate_one_time_keys().is_some());
assert!(account.generate_one_time_keys_if_needed().is_some());
Ok((tr, ()))
})
.await
Expand All @@ -2384,7 +2384,7 @@ pub(crate) mod tests {
.store()
.with_transaction(|mut tr| async {
let account = tr.account().await.unwrap();
assert!(account.generate_one_time_keys().is_some());
assert!(account.generate_one_time_keys_if_needed().is_some());
Ok((tr, ()))
})
.await
Expand All @@ -2398,7 +2398,7 @@ pub(crate) mod tests {
.store()
.with_transaction(|mut tr| async {
let account = tr.account().await.unwrap();
assert!(account.generate_one_time_keys().is_none());
assert!(account.generate_one_time_keys_if_needed().is_none());

Ok((tr, ()))
})
Expand Down Expand Up @@ -2466,7 +2466,7 @@ pub(crate) mod tests {
fn test_one_time_key_signing() {
let mut account = Account::with_device_id(user_id(), alice_device_id());
account.update_uploaded_key_count(49);
account.generate_one_time_keys();
account.generate_one_time_keys_if_needed();

let mut one_time_keys = account.signed_one_time_keys();
let ed25519_key = account.identity_keys().ed25519;
Expand Down
8 changes: 4 additions & 4 deletions crates/matrix-sdk-crypto/src/olm/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ impl Account {
}

self.update_uploaded_key_count(count);
self.generate_one_time_keys();
self.generate_one_time_keys_if_needed();
}

if let Some(unused) = unused_fallback_keys {
Expand All @@ -513,7 +513,7 @@ impl Account {
/// Generally `Some` means that keys should be uploaded, while `None` means
/// that keys should not be uploaded.
#[instrument(skip_all)]
pub fn generate_one_time_keys(&mut self) -> Option<u64> {
pub fn generate_one_time_keys_if_needed(&mut self) -> Option<u64> {
// Only generate one-time keys if there aren't any, otherwise the caller
// might have failed to upload them the last time this method was
// called.
Expand Down Expand Up @@ -1430,13 +1430,13 @@ mod tests {

account.mark_keys_as_published();
account.update_uploaded_key_count(50);
account.generate_one_time_keys();
account.generate_one_time_keys_if_needed();

let (_, third_one_time_keys, _) = account.keys_for_upload();
assert!(third_one_time_keys.is_empty());

account.update_uploaded_key_count(0);
account.generate_one_time_keys();
account.generate_one_time_keys_if_needed();

let (_, fourth_one_time_keys, _) = account.keys_for_upload();
assert!(!fourth_one_time_keys.is_empty());
Expand Down

0 comments on commit f5f5ea7

Please sign in to comment.