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 committed Oct 3, 2023
1 parent 7ac601d commit a2c6954
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 @@ -32,6 +32,7 @@ use ruma::{
key::{PassPhrase, SecretEncryptionAlgorithm, SecretStorageKeyEventContent},
secret::SecretEncryptedData,
},
EventContent, GlobalAccountDataEventType,
},
serde::Base64,
UInt,
Expand Down Expand Up @@ -548,8 +549,8 @@ impl SecretStorageKey {
///
/// Will be a concatenation of `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 @@ -597,9 +598,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 @@ -626,9 +629,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 @@ -698,9 +703,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 a2c6954

Please sign in to comment.