From 0f16ad64823551933aea0e96029c2ccc4d5bef1e Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 27 Nov 2023 12:53:38 +0000 Subject: [PATCH] Add some comments A couple of improvements and a couple of oddities I noted along the way. --- .../src/crypto_store/indexeddb_serializer.rs | 9 +++++++++ crates/matrix-sdk-indexeddb/src/crypto_store/mod.rs | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/matrix-sdk-indexeddb/src/crypto_store/indexeddb_serializer.rs b/crates/matrix-sdk-indexeddb/src/crypto_store/indexeddb_serializer.rs index 3c4efad4c33..9d21d622921 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store/indexeddb_serializer.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store/indexeddb_serializer.rs @@ -104,8 +104,12 @@ impl IndexeddbSerializer { if let Some(cipher) = &self.store_cipher { let value = cipher.encrypt_value(value).map_err(CryptoStoreError::backend)?; + // Turn the Vec into a Javascript-side `Array`. + // XXX Isn't there a way to do this that *doesn't* involve going via a JSON + // string? Ok(JsValue::from_serde(&value)?) } else { + // Turn the rust-side struct into a JS-side `Object`. Ok(JsValue::from_serde(&value)?) } } @@ -133,7 +137,12 @@ impl IndexeddbSerializer { value: JsValue, ) -> Result { if let Some(cipher) = &self.store_cipher { + // `value` is a JS-side array containing the byte values. Turn it into a + // rust-side Vec. + // XXX: Isn't there a way to do this that *doesn't* involve going via a JSON + // string? let value: Vec = value.into_serde()?; + cipher.decrypt_value(&value).map_err(CryptoStoreError::backend) } else { Ok(value.into_serde()?) diff --git a/crates/matrix-sdk-indexeddb/src/crypto_store/mod.rs b/crates/matrix-sdk-indexeddb/src/crypto_store/mod.rs index 52127bd6007..935846bd7e7 100644 --- a/crates/matrix-sdk-indexeddb/src/crypto_store/mod.rs +++ b/crates/matrix-sdk-indexeddb/src/crypto_store/mod.rs @@ -252,7 +252,7 @@ impl IndexeddbCryptoStore { } /// Transform a [`GossipRequest`] into a `JsValue` holding a - /// [`GossipRequestIndexedDbObject`], ready for storing + /// [`GossipRequestIndexedDbObject`], ready for storing. fn serialize_gossip_request(&self, gossip_request: &GossipRequest) -> Result { let obj = GossipRequestIndexedDbObject { // hash the info as a key so that it can be used in index lookups. @@ -270,7 +270,7 @@ impl IndexeddbCryptoStore { } /// Transform a JsValue holding a [`GossipRequestIndexedDbObject`] back into - /// a [`GossipRequest`] + /// a [`GossipRequest`]. fn deserialize_gossip_request(&self, stored_request: JsValue) -> Result { let idb_object: GossipRequestIndexedDbObject = serde_wasm_bindgen::from_value(stored_request)?;