Skip to content

Commit

Permalink
Use the GlobalAccountDataEventType instead of a string for the event …
Browse files Browse the repository at this point in the history
…type
  • Loading branch information
poljar authored and bnjbvr committed Oct 23, 2023
1 parent fda24d3 commit 7440ce0
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions crates/matrix-sdk-crypto/src/secret_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use ruma::{
},
secret::SecretEncryptedData,
},
EventContent, GlobalAccountDataEventType,
},
serde::Base64,
UInt,
Expand Down Expand Up @@ -561,8 +562,8 @@ impl SecretStorageKey {
/// The type is equal to the concatenation of the string
/// `"m.secret_storage.key."` and the key ID from the
/// [`SecretStorageKey::key_id()`] method.
pub fn event_type(&self) -> String {
format!("m.secret_storage.key.{}", self.key_id())
pub fn event_type(&self) -> GlobalAccountDataEventType {
self.event_content().event_type()
}
}

Expand Down Expand Up @@ -610,9 +611,11 @@ mod test {
let content = to_raw_value(key.event_content())
.expect("We should be able to serialize the secret storage key event content");

let content = SecretStorageKeyEventContent::from_parts(&key.event_type(), &content).expect(
"We should be able to parse our, just serialized, secret storage key event content",
);
let content =
SecretStorageKeyEventContent::from_parts(&key.event_type().to_string(), &content)
.expect(
"We should be able to parse our, just serialized, secret storage key event content",
);

let key = SecretStorageKey::from_account_data(passphrase, content)
.expect("We should be able to restore our secret storage key");
Expand All @@ -639,9 +642,11 @@ mod test {
let content = to_raw_value(key.event_content())
.expect("We should be able to serialize the secret storage key event content");

let content = SecretStorageKeyEventContent::from_parts(&key.event_type(), &content).expect(
"We should be able to parse our, just serialized, secret storage key event content",
);
let content =
SecretStorageKeyEventContent::from_parts(&key.event_type().to_string(), &content)
.expect(
"We should be able to parse our, just serialized, secret storage key event content",
);

let base58_key = key.to_base58();

Expand Down Expand Up @@ -711,9 +716,11 @@ mod test {
let content = to_raw_value(key.event_content())
.expect("We should be able to serialize the secret storage key event content");

let content = SecretStorageKeyEventContent::from_parts(&key.event_type(), &content).expect(
"We should be able to parse our, just serialized, secret storage key event content",
);
let content =
SecretStorageKeyEventContent::from_parts(&key.event_type().to_string(), &content)
.expect(
"We should be able to parse our, just serialized, secret storage key event content",
);

assert_matches!(
SecretStorageKey::from_account_data("It's a secret to nobody", content.to_owned()),
Expand Down

0 comments on commit 7440ce0

Please sign in to comment.