From 52d96ceb60b117f0ab1c4b80be730f7b4bd5ca8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 18 Oct 2022 11:28:11 +0200 Subject: [PATCH] fix(bindings): Allow setting the store without a passphrase --- bindings/matrix-sdk-crypto-js/src/machine.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bindings/matrix-sdk-crypto-js/src/machine.rs b/bindings/matrix-sdk-crypto-js/src/machine.rs index b13d96686..0d3fb8e58 100644 --- a/bindings/matrix-sdk-crypto-js/src/machine.rs +++ b/bindings/matrix-sdk-crypto-js/src/machine.rs @@ -66,6 +66,7 @@ impl OlmMachine { #[cfg(target_arch = "wasm32")] (Some(store_name), Some(mut store_passphrase)) => { use std::sync::Arc; + use zeroize::Zeroize; let store = Some( @@ -82,9 +83,22 @@ impl OlmMachine { store } - (Some(_), None) => return Err(anyhow::Error::msg("The `store_name` has been set, and so, it expects a `store_passphrase`, which is not set; please provide one")), + #[cfg(target_arch = "wasm32")] + (Some(store_name), None) => { + use std::sync::Arc; + Some( + matrix_sdk_indexeddb::IndexeddbCryptoStore::open_with_name(&store_name) + .await + .map(Arc::new)?, + ) + } - (None, Some(_)) => return Err(anyhow::Error::msg("The `store_passphrase` has been set, but it has an effect only if `store_name` is set, which is not; please provide one")), + (None, Some(_)) => { + return Err(anyhow::Error::msg( + "The `store_passphrase` has been set, but it has an effect only if \ + `store_name` is set, which is not; please provide one", + )) + } _ => None, };