Skip to content

Commit f0bdc05

Browse files
committed
refactor(crypto): Use IntoCryptoStore for OlmMachine::with_store
1 parent 6473bf2 commit f0bdc05

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

src/machine.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,41 +70,25 @@ impl OlmMachine {
7070

7171
future_to_promise(async move {
7272
let store = match (store_name, store_passphrase) {
73-
// We need this `#[cfg]` because `IndexeddbCryptoStore`
74-
// implements `CryptoStore` only on `target_arch =
75-
// "wasm32"`. Without that, we could have a compilation
76-
// error when checking the entire workspace. In
77-
// practise, it doesn't impact this crate because it's
78-
// always compiled for `wasm32`.
79-
#[cfg(target_arch = "wasm32")]
8073
(Some(store_name), Some(mut store_passphrase)) => {
81-
use std::sync::Arc;
82-
8374
use zeroize::Zeroize;
8475

8576
let store = Some(
8677
matrix_sdk_indexeddb::IndexeddbCryptoStore::open_with_passphrase(
8778
&store_name,
8879
&store_passphrase,
8980
)
90-
.await
91-
.map(Arc::new)?,
81+
.await?,
9282
);
9383

9484
store_passphrase.zeroize();
9585

9686
store
9787
}
9888

99-
#[cfg(target_arch = "wasm32")]
100-
(Some(store_name), None) => {
101-
use std::sync::Arc;
102-
Some(
103-
matrix_sdk_indexeddb::IndexeddbCryptoStore::open_with_name(&store_name)
104-
.await
105-
.map(Arc::new)?,
106-
)
107-
}
89+
(Some(store_name), None) => Some(
90+
matrix_sdk_indexeddb::IndexeddbCryptoStore::open_with_name(&store_name).await?,
91+
),
10892

10993
(None, Some(_)) => {
11094
return Err(anyhow::Error::msg(
@@ -113,11 +97,18 @@ impl OlmMachine {
11397
))
11498
}
11599

116-
_ => None,
100+
(None, None) => None,
117101
};
118102

119103
Ok(OlmMachine {
120104
inner: match store {
105+
// We need this `#[cfg]` because `IndexeddbCryptoStore`
106+
// implements `CryptoStore` only on `target_arch =
107+
// "wasm32"`. Without that, we could have a compilation
108+
// error when checking the entire workspace. In practice,
109+
// it doesn't impact this crate because it's always
110+
// compiled for `wasm32`.
111+
#[cfg(target_arch = "wasm32")]
121112
Some(store) => {
122113
matrix_sdk_crypto::OlmMachine::with_store(
123114
user_id.as_ref(),
@@ -126,7 +117,7 @@ impl OlmMachine {
126117
)
127118
.await?
128119
}
129-
None => {
120+
_ => {
130121
matrix_sdk_crypto::OlmMachine::new(user_id.as_ref(), device_id.as_ref())
131122
.await
132123
}

0 commit comments

Comments
 (0)