From a2c6954c171d7e3549dc65065e3b8d1e78409eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 27 Sep 2023 10:20:43 +0200 Subject: [PATCH] Use the GlobalAccountDataEventType instead of a string for the event type --- .../matrix-sdk-crypto/src/secret_storage.rs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/crates/matrix-sdk-crypto/src/secret_storage.rs b/crates/matrix-sdk-crypto/src/secret_storage.rs index 58430630df..25ec3e8a5c 100644 --- a/crates/matrix-sdk-crypto/src/secret_storage.rs +++ b/crates/matrix-sdk-crypto/src/secret_storage.rs @@ -32,6 +32,7 @@ use ruma::{ key::{PassPhrase, SecretEncryptionAlgorithm, SecretStorageKeyEventContent}, secret::SecretEncryptedData, }, + EventContent, GlobalAccountDataEventType, }, serde::Base64, UInt, @@ -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() } } @@ -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"); @@ -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(); @@ -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()),