Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 40ee1bb

Browse files
authored
Support rust in StorageManager (#12206)
1 parent 01f0c66 commit 40ee1bb

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/MatrixClientPeg.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ class MatrixClientPegClass implements IMatrixClientPeg {
336336
if (useRustCrypto) {
337337
await this.matrixClient.initRustCrypto();
338338

339+
StorageManager.setCryptoInitialised(true);
339340
// TODO: device dehydration and whathaveyou
340341
return;
341342
}

src/utils/StorageManager.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ limitations under the License.
1717
import { LocalStorageCryptoStore, IndexedDBStore, IndexedDBCryptoStore } from "matrix-js-sdk/src/matrix";
1818
import { logger } from "matrix-js-sdk/src/logger";
1919

20+
import SettingsStore from "../settings/SettingsStore";
21+
import { Features } from "../settings/Settings";
22+
2023
const localStorage = window.localStorage;
2124

2225
// just *accessing* indexedDB throws an exception in firefox with
@@ -28,7 +31,16 @@ try {
2831

2932
// The JS SDK will add a prefix of "matrix-js-sdk:" to the sync store name.
3033
const SYNC_STORE_NAME = "riot-web-sync";
31-
const CRYPTO_STORE_NAME = "matrix-js-sdk:crypto";
34+
const LEGACY_CRYPTO_STORE_NAME = "matrix-js-sdk:crypto";
35+
const RUST_CRYPTO_STORE_NAME = "matrix-js-sdk::matrix-sdk-crypto";
36+
37+
function cryptoStoreName(): string {
38+
if (SettingsStore.getValue(Features.RustCrypto)) {
39+
return RUST_CRYPTO_STORE_NAME;
40+
} else {
41+
return LEGACY_CRYPTO_STORE_NAME;
42+
}
43+
}
3244

3345
function log(msg: string): void {
3446
logger.log(`StorageManager: ${msg}`);
@@ -145,7 +157,7 @@ async function checkSyncStore(): Promise<StoreCheck> {
145157
async function checkCryptoStore(): Promise<StoreCheck> {
146158
let exists = false;
147159
try {
148-
exists = await IndexedDBCryptoStore.exists(indexedDB, CRYPTO_STORE_NAME);
160+
exists = await IndexedDBCryptoStore.exists(indexedDB, cryptoStoreName());
149161
log(`Crypto store using IndexedDB contains data? ${exists}`);
150162
return { exists, healthy: true };
151163
} catch (e) {

0 commit comments

Comments
 (0)