Skip to content

Commit

Permalink
Add some comments
Browse files Browse the repository at this point in the history
A couple of improvements and a couple of oddities I noted along the way.
  • Loading branch information
richvdh committed Nov 27, 2023
1 parent a4cdd59 commit 0f16ad6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> into a Javascript-side `Array<number>`.
// 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)?)
}
}
Expand Down Expand Up @@ -133,7 +137,12 @@ impl IndexeddbSerializer {
value: JsValue,
) -> Result<T, CryptoStoreError> {
if let Some(cipher) = &self.store_cipher {
// `value` is a JS-side array containing the byte values. Turn it into a
// rust-side Vec<u8>.
// XXX: Isn't there a way to do this that *doesn't* involve going via a JSON
// string?
let value: Vec<u8> = value.into_serde()?;

cipher.decrypt_value(&value).map_err(CryptoStoreError::backend)
} else {
Ok(value.into_serde()?)
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-indexeddb/src/crypto_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsValue> {
let obj = GossipRequestIndexedDbObject {
// hash the info as a key so that it can be used in index lookups.
Expand All @@ -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<GossipRequest> {
let idb_object: GossipRequestIndexedDbObject =
serde_wasm_bindgen::from_value(stored_request)?;
Expand Down

0 comments on commit 0f16ad6

Please sign in to comment.