mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-04-28 19:20:00 -04:00
crypto: Add an optional backup_version param to inbound_group_session_counts
This commit is contained in:
@@ -8,6 +8,12 @@ Changed:
|
||||
|
||||
Breaking changes:
|
||||
|
||||
- Add a `backup_version` argument to `CryptoStore`'s
|
||||
`inbound_group_sessions_for_backup`,
|
||||
`mark_inbound_group_sessions_as_backed_up` and
|
||||
`inbound_group_session_counts` methods.
|
||||
([#3253](https://github.com/matrix-org/matrix-rust-sdk/pull/3253))
|
||||
|
||||
- Rename the `OlmMachine::invalidate_group_session` method to
|
||||
`OlmMachine::discard_room_key`
|
||||
|
||||
@@ -17,10 +23,6 @@ Breaking changes:
|
||||
- Add new `dehydrated` property to `olm::account::PickledAccount`.
|
||||
([#3164](https://github.com/matrix-org/matrix-rust-sdk/pull/3164))
|
||||
|
||||
- Add a `backup_version` argument to `CryptoStore`'s
|
||||
`inbound_group_sessions_for_backup` and
|
||||
`mark_inbound_group_sessions_as_backed_up` methods.
|
||||
|
||||
Additions:
|
||||
|
||||
- Expose new method `OlmMachine::device_creation_time`.
|
||||
|
||||
@@ -397,7 +397,8 @@ impl BackupMachine {
|
||||
|
||||
/// Get the number of backed up room keys and the total number of room keys.
|
||||
pub async fn room_key_counts(&self) -> Result<RoomKeyCounts, CryptoStoreError> {
|
||||
self.store.inbound_group_session_counts().await
|
||||
let backup_version = self.backup_key.read().await.as_ref().and_then(|k| k.backup_version());
|
||||
self.store.inbound_group_session_counts(backup_version.as_deref()).await
|
||||
}
|
||||
|
||||
/// Disable and reset our backup state.
|
||||
@@ -663,7 +664,11 @@ mod tests {
|
||||
|
||||
async fn backup_flow(machine: OlmMachine) -> Result<(), OlmError> {
|
||||
let backup_machine = machine.backup_machine();
|
||||
let counts = backup_machine.store.inbound_group_session_counts().await?;
|
||||
let backup_version =
|
||||
backup_machine.backup_key.read().await.as_ref().and_then(|k| k.backup_version());
|
||||
let backup_version = backup_version.as_deref();
|
||||
|
||||
let counts = backup_machine.store.inbound_group_session_counts(backup_version).await?;
|
||||
|
||||
assert_eq!(counts.total, 0, "Initially no keys exist");
|
||||
assert_eq!(counts.backed_up, 0, "Initially no backed up keys exist");
|
||||
@@ -671,7 +676,7 @@ mod tests {
|
||||
machine.create_outbound_group_session_with_defaults_test_helper(room_id()).await?;
|
||||
machine.create_outbound_group_session_with_defaults_test_helper(room_id2()).await?;
|
||||
|
||||
let counts = backup_machine.store.inbound_group_session_counts().await?;
|
||||
let counts = backup_machine.store.inbound_group_session_counts(backup_version).await?;
|
||||
assert_eq!(counts.total, 2, "Two room keys need to exist in the store");
|
||||
assert_eq!(counts.backed_up, 0, "No room keys have been backed up yet");
|
||||
|
||||
@@ -691,7 +696,7 @@ mod tests {
|
||||
|
||||
backup_machine.mark_request_as_sent(&request_id).await?;
|
||||
|
||||
let counts = backup_machine.store.inbound_group_session_counts().await?;
|
||||
let counts = backup_machine.store.inbound_group_session_counts(backup_version).await?;
|
||||
assert_eq!(counts.total, 2);
|
||||
assert_eq!(counts.backed_up, 2, "All room keys have been backed up");
|
||||
|
||||
@@ -702,7 +707,7 @@ mod tests {
|
||||
|
||||
backup_machine.disable_backup().await?;
|
||||
|
||||
let counts = backup_machine.store.inbound_group_session_counts().await?;
|
||||
let counts = backup_machine.store.inbound_group_session_counts(backup_version).await?;
|
||||
assert_eq!(counts.total, 2);
|
||||
assert_eq!(
|
||||
counts.backed_up, 0,
|
||||
|
||||
@@ -323,8 +323,8 @@ macro_rules! cryptostore_integration_tests {
|
||||
.unwrap();
|
||||
assert_eq!(session, loaded_session);
|
||||
assert_eq!(store.get_inbound_group_sessions().await.unwrap().len(), 1);
|
||||
assert_eq!(store.inbound_group_session_counts().await.unwrap().total, 1);
|
||||
assert_eq!(store.inbound_group_session_counts().await.unwrap().backed_up, 0);
|
||||
assert_eq!(store.inbound_group_session_counts(None).await.unwrap().total, 1);
|
||||
assert_eq!(store.inbound_group_session_counts(None).await.unwrap().backed_up, 0);
|
||||
|
||||
let to_back_up = store.inbound_group_sessions_for_backup("bkpver", 1).await.unwrap();
|
||||
assert_eq!(to_back_up, vec![session])
|
||||
@@ -377,7 +377,7 @@ macro_rules! cryptostore_integration_tests {
|
||||
async fn reset_inbound_group_session_for_backup() {
|
||||
let (account, store) =
|
||||
get_loaded_store("reset_inbound_group_session_for_backup").await;
|
||||
assert_eq!(store.inbound_group_session_counts().await.unwrap().total, 0);
|
||||
assert_eq!(store.inbound_group_session_counts(None).await.unwrap().total, 0);
|
||||
|
||||
let room_id = &room_id!("!test:localhost");
|
||||
let (_, session) = account.create_group_session_pair_with_defaults(room_id).await;
|
||||
@@ -393,8 +393,8 @@ macro_rules! cryptostore_integration_tests {
|
||||
.await
|
||||
.expect("Failed to mark_inbound_group_sessions_as_backed_up.");
|
||||
|
||||
assert_eq!(store.inbound_group_session_counts().await.unwrap().total, 1);
|
||||
assert_eq!(store.inbound_group_session_counts().await.unwrap().backed_up, 1);
|
||||
assert_eq!(store.inbound_group_session_counts(Some("bkpver1")).await.unwrap().total, 1);
|
||||
assert_eq!(store.inbound_group_session_counts(Some("bkpver1")).await.unwrap().backed_up, 1);
|
||||
|
||||
// Sanity: before resetting, we have nothing to back up
|
||||
let to_back_up = store.inbound_group_sessions_for_backup("bkpver1", 1).await.unwrap();
|
||||
@@ -442,7 +442,7 @@ macro_rules! cryptostore_integration_tests {
|
||||
loaded_session.export().await;
|
||||
|
||||
assert_eq!(store.get_inbound_group_sessions().await.unwrap().len(), 1);
|
||||
assert_eq!(store.inbound_group_session_counts().await.unwrap().total, 1);
|
||||
assert_eq!(store.inbound_group_session_counts(Some("bkpver1")).await.unwrap().total, 1);
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
|
||||
@@ -270,7 +270,10 @@ impl CryptoStore for MemoryStore {
|
||||
Ok(self.inbound_group_sessions.get_all())
|
||||
}
|
||||
|
||||
async fn inbound_group_session_counts(&self) -> Result<RoomKeyCounts> {
|
||||
async fn inbound_group_session_counts(
|
||||
&self,
|
||||
_backup_version: Option<&str>,
|
||||
) -> Result<RoomKeyCounts> {
|
||||
let backed_up =
|
||||
self.get_inbound_group_sessions().await?.into_iter().filter(|s| s.backed_up()).count();
|
||||
|
||||
@@ -760,8 +763,11 @@ mod integration_tests {
|
||||
self.0.get_inbound_group_sessions().await
|
||||
}
|
||||
|
||||
async fn inbound_group_session_counts(&self) -> Result<RoomKeyCounts, Self::Error> {
|
||||
self.0.inbound_group_session_counts().await
|
||||
async fn inbound_group_session_counts(
|
||||
&self,
|
||||
backup_version: Option<&str>,
|
||||
) -> Result<RoomKeyCounts, Self::Error> {
|
||||
self.0.inbound_group_session_counts(backup_version).await
|
||||
}
|
||||
|
||||
async fn inbound_group_sessions_for_backup(
|
||||
|
||||
@@ -105,7 +105,10 @@ pub trait CryptoStore: AsyncTraitDeps {
|
||||
|
||||
/// Get the number inbound group sessions we have and how many of them are
|
||||
/// backed up.
|
||||
async fn inbound_group_session_counts(&self) -> Result<RoomKeyCounts, Self::Error>;
|
||||
async fn inbound_group_session_counts(
|
||||
&self,
|
||||
backup_version: Option<&str>,
|
||||
) -> Result<RoomKeyCounts, Self::Error>;
|
||||
|
||||
/// Return a batch of ['InboundGroupSession'] ("room keys") that have not
|
||||
/// yet been backed up in the supplied backup version.
|
||||
@@ -349,8 +352,11 @@ impl<T: CryptoStore> CryptoStore for EraseCryptoStoreError<T> {
|
||||
self.0.get_inbound_group_sessions().await.map_err(Into::into)
|
||||
}
|
||||
|
||||
async fn inbound_group_session_counts(&self) -> Result<RoomKeyCounts> {
|
||||
self.0.inbound_group_session_counts().await.map_err(Into::into)
|
||||
async fn inbound_group_session_counts(
|
||||
&self,
|
||||
backup_version: Option<&str>,
|
||||
) -> Result<RoomKeyCounts> {
|
||||
self.0.inbound_group_session_counts(backup_version).await.map_err(Into::into)
|
||||
}
|
||||
async fn inbound_group_sessions_for_backup(
|
||||
&self,
|
||||
|
||||
@@ -873,7 +873,7 @@ impl_crypto_store! {
|
||||
).await
|
||||
}
|
||||
|
||||
async fn inbound_group_session_counts(&self) -> Result<RoomKeyCounts> {
|
||||
async fn inbound_group_session_counts(&self, _backup_version: Option<&str>) -> Result<RoomKeyCounts> {
|
||||
let tx = self
|
||||
.inner
|
||||
.transaction_on_one_with_mode(
|
||||
|
||||
@@ -477,7 +477,10 @@ trait SqliteObjectCryptoStoreExt: SqliteObjectExt {
|
||||
.await?)
|
||||
}
|
||||
|
||||
async fn get_inbound_group_session_counts(&self) -> Result<RoomKeyCounts> {
|
||||
async fn get_inbound_group_session_counts(
|
||||
&self,
|
||||
_backup_version: Option<&str>,
|
||||
) -> Result<RoomKeyCounts> {
|
||||
let total = self
|
||||
.query_row("SELECT count(*) FROM inbound_group_session", (), |row| row.get(0))
|
||||
.await?;
|
||||
@@ -940,8 +943,11 @@ impl CryptoStore for SqliteCryptoStore {
|
||||
.collect()
|
||||
}
|
||||
|
||||
async fn inbound_group_session_counts(&self) -> Result<RoomKeyCounts> {
|
||||
Ok(self.acquire().await?.get_inbound_group_session_counts().await?)
|
||||
async fn inbound_group_session_counts(
|
||||
&self,
|
||||
backup_version: Option<&str>,
|
||||
) -> Result<RoomKeyCounts> {
|
||||
Ok(self.acquire().await?.get_inbound_group_session_counts(backup_version).await?)
|
||||
}
|
||||
|
||||
async fn inbound_group_sessions_for_backup(
|
||||
|
||||
Reference in New Issue
Block a user