Repository: ruma/ruma
Pull request #181 (2020-08-06 02:13:01)

Update endpoints to use key identifier and algorithm types


Patch:
diff --git a/ruma-client-api/CHANGELOG.md b/ruma-client-api/CHANGELOG.md
index 1a1d2777..2f7bfcaf 100644
--- a/ruma-client-api/CHANGELOG.md
+++ b/ruma-client-api/CHANGELOG.md
@@ -8,6 +8,16 @@ Bug fixes:
 
 Breaking changes:
 
+* Borrow strings in outgoing requests and responses.
+  * Explicit types may have to be updated from `endpoint::Request` to `endpoint::Request<'_>` on
+    clients and `endpoint::IncomingRequest` on servers, the other way around for responses.
+  * When sending a request or response, you shouldn't have to clone things as much as before. Tip:
+    Use clippy to detect now-unnecessary `.into()` conversions.
+* Make most types non-exhaustive
+  * This means you no longer can construct many of them using struct literals.
+  * Instead, constructors are provided.
+  * Tip: To set optional fields that aren't set in the constructor, you may find the `assign` crate
+    useful.
 * Make `avatar_url` in `r0::profile::set_avatar_url::Request` an `Option`
 * Update type of `canonical_alias` in `r0::directory::PublicRoomsChunk` from
   `Option<String>` to `Option<RoomAliasId>`
@@ -40,6 +50,10 @@ Breaking changes:
 * Update strum dependency to 0.19
 * Rename `r0::message::{create_message_event => send_message_event}`
 * Rename `r0::state::{create_state_event_* => send_state_event_*}`
+* Replace `r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm}` with
+  `ruma_identifiers::{DeviceKeyId, DeviceKeyAlgorithm}`, respectively
+* Use `ruma_identifiers::{ServerName, ServerKeyId}` in `signatures` fields of
+  `r0::room::membership::ThirdPartySigned`.
 
 Improvements:
 
diff --git a/ruma-client-api/src/r0/backup.rs b/ruma-client-api/src/r0/backup.rs
index 600f8660..7d84a2a7 100644
--- a/ruma-client-api/src/r0/backup.rs
+++ b/ruma-client-api/src/r0/backup.rs
@@ -8,12 +8,10 @@ pub mod get_latest_backup;
 pub mod update_backup;
 
 use js_int::UInt;
-use ruma_identifiers::UserId;
+use ruma_identifiers::{DeviceKeyId, UserId};
 use serde::{Deserialize, Serialize};
 use std::collections::BTreeMap;
 
-use crate::r0::keys::AlgorithmAndDeviceId;
-
 // TODO: remove
 /// A wrapper around a mapping of session IDs to key data.
 #[cfg(feature = "unstable-synapse-quirks")]
@@ -33,7 +31,7 @@ pub enum BackupAlgorithm {
         /// The curve25519 public key used to encrypt the backups, encoded in unpadded base64.
         public_key: String,
         /// Signatures of the auth_data as Signed JSON.
-        signatures: BTreeMap<UserId, BTreeMap<AlgorithmAndDeviceId, String>>,
+        signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
     },
 }
 
diff --git a/ruma-client-api/src/r0/keys.rs b/ruma-client-api/src/r0/keys.rs
index 3f82ab9e..b1bb765c 100644
--- a/ruma-client-api/src/r0/keys.rs
+++ b/ruma-client-api/src/r0/keys.rs
@@ -1,17 +1,10 @@
 //! Endpoints for key management
 
-use std::{
-    collections::BTreeMap,
-    convert::TryFrom,
-    fmt::{self, Debug, Display, Formatter},
-};
+use std::{collections::BTreeMap, fmt::Debug};
 
 use ruma_events::Algorithm;
-use ruma_identifiers::{DeviceId, UserId};
-use serde::{
-    de::{self, Unexpected},
-    Deserialize, Deserializer, Serialize, Serializer,
-};
+use ruma_identifiers::{DeviceId, DeviceKeyId, UserId};
+use serde::{Deserialize, Serialize};
 
 pub mod claim_keys;
 pub mod get_key_changes;
@@ -23,98 +16,6 @@ pub mod upload_signatures;
 #[cfg(feature = "unstable-pre-spec")]
 pub mod upload_signing_keys;
 
-/// The basic key algorithms in the specification
-#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
-pub enum KeyAlgorithm {
-    /// The Ed25519 signature algorithm.
-    #[serde(rename = "ed25519")]
-    Ed25519,
-
-    /// The Curve25519 ECDH algorithm.
-    #[serde(rename = "curve25519")]
-    Curve25519,
-
-    /// The Curve25519 ECDH algorithm, but the key also contains signatures
-    #[serde(rename = "signed_curve25519")]
-    SignedCurve25519,
-}
-
-impl Display for KeyAlgorithm {
-    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
-        let algorithm_str = match *self {
-            KeyAlgorithm::Ed25519 => "ed25519",
-            KeyAlgorithm::Curve25519 => "curve25519",
-            KeyAlgorithm::SignedCurve25519 => "signed_curve25519",
-        };
-        write!(f, "{}", algorithm_str)?;
-        Ok(())
-    }
-}
-
-impl TryFrom<&'_ str> for KeyAlgorithm {
-    type Error = &'static str;
-    fn try_from(s: &str) -> Result<Self, Self::Error> {
-        match s {
-            "ed25519" => Ok(KeyAlgorithm::Ed25519),
-            "curve25519" => Ok(KeyAlgorithm::Curve25519),
-            "signed_curve25519" => Ok(KeyAlgorithm::SignedCurve25519),
-            _ => Err("Unknown algorithm"),
-        }
-    }
-}
-
-/// A key algorithm and a device id, combined with a ':'
-#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
-pub struct AlgorithmAndDeviceId(pub KeyAlgorithm, pub Box<DeviceId>);
-
-impl Display for AlgorithmAndDeviceId {
-    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
-        write!(f, "{}:{}", self.0, self.1)
-    }
-}
-
-impl Serialize for AlgorithmAndDeviceId {
-    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
-    where
-        S: Serializer,
-    {
-        serializer.serialize_str(&self.to_string())
-    }
-}
-
-impl<'de> Deserialize<'de> for AlgorithmAndDeviceId {
-    #[allow(clippy::comparison_chain)]
-    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
-    where
-        D: Deserializer<'de>,
-    {
-        let value = String::deserialize(deserializer)?;
-        let parts = value.split(':').collect::<Vec<_>>();
-
-        const EXPECTED: &str = "a string composed of an algorithm and a device id separated by ':'";
-
-        if parts.len() < 2 {
-            return Err(de::Error::invalid_type(
-                Unexpected::Other("string without a ':' separator"),
-                &EXPECTED,
-            ));
-        } else if parts.len() > 2 {
-            return Err(de::Error::invalid_type(
-                Unexpected::Other("string with more than one ':' separator"),
-                &EXPECTED,
-            ));
-        }
-
-        let algorithm_result = KeyAlgorithm::try_from(parts[0]);
-        match algorithm_result {
-            Ok(algorithm) => Ok(AlgorithmAndDeviceId(algorithm, parts[1].into())),
-            Err(_) => {
-                Err(de::Error::invalid_value(Unexpected::Str(parts[0]), &"valid key algorithm"))
-            }
-        }
-    }
-}
-
 /// Identity keys for a device.
 #[derive(Debug, Clone, Serialize, Deserialize)]
 pub struct DeviceKeys {
@@ -128,10 +29,10 @@ pub struct DeviceKeys {
     pub algorithms: Vec<Algorithm>,
 
     /// Public identity keys.
-    pub keys: BTreeMap<AlgorithmAndDeviceId, String>,
+    pub keys: BTreeMap<DeviceKeyId, String>,
 
     /// Signatures for the device key object.
-    pub signatures: BTreeMap<UserId, BTreeMap<AlgorithmAndDeviceId, String>>,
+    pub signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
 
     /// Additional data added to the device key information by intermediate servers, and
     /// not covered by the signatures.
@@ -153,7 +54,7 @@ pub struct SignedKey {
     pub key: String,
 
     /// Signatures for the key object.
-    pub signatures: BTreeMap<UserId, BTreeMap<AlgorithmAndDeviceId, String>>,
+    pub signatures: BTreeMap<UserId, BTreeMap<DeviceKeyId, String>>,
 }
 
 /// A one-time public key for "pre-key" messages.
diff --git a/ruma-client-api/src/r0/keys/claim_keys.rs b/ruma-client-api/src/r0/keys/claim_keys.rs
index 4cd08281..0b5f2bd9 100644
--- a/ruma-client-api/src/r0/keys/claim_keys.rs
+++ b/ruma-client-api/src/r0/keys/claim_keys.rs
@@ -1,14 +1,14 @@
-//! [POST /_matrix/client/r0/keys/claim](https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-keys-claim)
+//! [POST /_matrix/client/r0/keys/claim](https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-keys-claim)
 
 use std::collections::BTreeMap;
 
 use std::time::Duration;
 
 use ruma_api::ruma_api;
-use ruma_identifiers::{DeviceId, UserId};
+use ruma_identifiers::{DeviceId, DeviceKeyAlgorithm, DeviceKeyId, UserId};
 use serde_json::Value as JsonValue;
 
-use super::{AlgorithmAndDeviceId, KeyAlgorithm, OneTimeKey};
+use super::OneTimeKey;
 
 ruma_api! {
     metadata: {
@@ -31,7 +31,7 @@ ruma_api! {
         pub timeout: Option<Duration>,
 
         /// The keys to be claimed.
-        pub one_time_keys: BTreeMap<UserId, BTreeMap<Box<DeviceId>, KeyAlgorithm>>,
+        pub one_time_keys: BTreeMap<UserId, BTreeMap<Box<DeviceId>, DeviceKeyAlgorithm>>,
     }
 
     response: {
@@ -47,4 +47,4 @@ ruma_api! {
 }
 
 /// The one-time keys for a given device.
-pub type OneTimeKeys = BTreeMap<Box<DeviceId>, BTreeMap<AlgorithmAndDeviceId, OneTimeKey>>;
+pub type OneTimeKeys = BTreeMap<Box<DeviceId>, BTreeMap<DeviceKeyId, OneTimeKey>>;
diff --git a/ruma-client-api/src/r0/keys/upload_keys.rs b/ruma-client-api/src/r0/keys/upload_keys.rs
index 0d649bde..43684808 100644
--- a/ruma-client-api/src/r0/keys/upload_keys.rs
+++ b/ruma-client-api/src/r0/keys/upload_keys.rs
@@ -4,8 +4,9 @@ use std::collections::BTreeMap;
 
 use js_int::UInt;
 use ruma_api::ruma_api;
+use ruma_identifiers::{DeviceKeyAlgorithm, DeviceKeyId};
 
-use super::{AlgorithmAndDeviceId, DeviceKeys, KeyAlgorithm, OneTimeKey};
+use super::{DeviceKeys, OneTimeKey};
 
 ruma_api! {
     metadata: {
@@ -24,13 +25,13 @@ ruma_api! {
 
         /// One-time public keys for "pre-key" messages.
         #[serde(skip_serializing_if = "Option::is_none")]
-        pub one_time_keys: Option<BTreeMap<AlgorithmAndDeviceId, OneTimeKey>>,
+        pub one_time_keys: Option<BTreeMap<DeviceKeyId, OneTimeKey>>,
     }
 
     response: {
         /// For each key algorithm, the number of unclaimed one-time keys of that
         /// type currently held on the server for this device.
-        pub one_time_key_counts: BTreeMap<KeyAlgorithm, UInt>
+        pub one_time_key_counts: BTreeMap<DeviceKeyAlgorithm, UInt>
     }
 
     error: crate::Error
diff --git a/ruma-client-api/src/r0/membership.rs b/ruma-client-api/src/r0/membership.rs
index 047276f0..85dc443d 100644
--- a/ruma-client-api/src/r0/membership.rs
+++ b/ruma-client-api/src/r0/membership.rs
@@ -17,6 +17,7 @@ use std::collections::BTreeMap;
 use serde::{Deserialize, Serialize};
 
 use crate::r0::thirdparty::Medium;
+use ruma_identifiers::{ServerKeyId, ServerName};
 
 /// A signature of an `m.third_party_invite` token to prove that this user owns a third party
 /// identity which has been invited to the room.
@@ -32,7 +33,7 @@ pub struct ThirdPartySigned {
     pub token: String,
 
     /// A signatures object containing a signature of the entire signed object.
-    pub signatures: BTreeMap<String, BTreeMap<String, String>>,
+    pub signatures: BTreeMap<Box<ServerName>, BTreeMap<ServerKeyId, String>>,
 }
 
 /// Represents third party IDs to invite to the room.
diff --git a/ruma-client-api/src/r0/sync/sync_events.rs b/ruma-client-api/src/r0/sync/sync_events.rs
index e0a28dfa..8450fd28 100644
--- a/ruma-client-api/src/r0/sync/sync_events.rs
+++ b/ruma-client-api/src/r0/sync/sync_events.rs
@@ -9,10 +9,10 @@ use ruma_events::{
     presence::PresenceEvent, AnyBasicEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent,
     AnySyncRoomEvent, AnySyncStateEvent, AnyToDeviceEvent,
 };
-use ruma_identifiers::{RoomId, UserId};
+use ruma_identifiers::{DeviceKeyAlgorithm, RoomId, UserId};
 use serde::{Deserialize, Serialize};
 
-use crate::r0::{filter::FilterDefinition, keys::KeyAlgorithm};
+use crate::r0::filter::FilterDefinition;
 
 ruma_api! {
     metadata: {
@@ -87,7 +87,7 @@ ruma_api! {
         /// For each key algorithm, the number of unclaimed one-time keys
         /// currently held on the server for a device.
         #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
-        pub device_one_time_keys_count: BTreeMap<KeyAlgorithm, UInt>,
+        pub device_one_time_keys_count: BTreeMap<DeviceKeyAlgorithm, UInt>,
     }
 
     error: crate::Error
diff --git a/ruma-events/CHANGELOG.md b/ruma-events/CHANGELOG.md
index ccfb0ba3..8cc83a22 100644
--- a/ruma-events/CHANGELOG.md
+++ b/ruma-events/CHANGELOG.md
@@ -3,6 +3,9 @@
 Breaking changes:
 
 * Update strum dependency to 0.19
+* Use `ruma_identifiers::{ServerName, ServerKeyId}` in `signatures` fields of
+  `pdu::RoomV1Pdu, RoomV1PduStub, RoomV3Pdu, RoomV3PduStub}` and
+  `room::member::SignedContent`.
 
 # 0.22.0
 
diff --git a/ruma-events/src/pdu.rs b/ruma-events/src/pdu.rs
index 9bc411ff..af05b085 100644
--- a/ruma-events/src/pdu.rs
+++ b/ruma-events/src/pdu.rs
@@ -12,7 +12,7 @@ use std::{collections::BTreeMap, time::SystemTime};
 
 use js_int::UInt;
 use ruma_events::EventType;
-use ruma_identifiers::{EventId, RoomId, ServerName, UserId};
+use ruma_identifiers::{EventId, RoomId, ServerKeyId, ServerName, UserId};
 use serde::{Deserialize, Serialize};
 use serde_json::Value as JsonValue;
 
@@ -84,7 +84,7 @@ pub struct RoomV1Pdu {
     pub hashes: EventHash,
 
     /// Signatures for the PDU.
-    pub signatures: BTreeMap<Box<ServerName>, BTreeMap<String, String>>,
+    pub signatures: BTreeMap<Box<ServerName>, BTreeMap<ServerKeyId, String>>,
 }
 
 /// A 'persistent data unit' (event) for room versions 3 and beyond.
@@ -140,7 +140,7 @@ pub struct RoomV3Pdu {
     pub hashes: EventHash,
 
     /// Signatures for the PDU.
-    pub signatures: BTreeMap<Box<ServerName>, BTreeMap<String, String>>,
+    pub signatures: BTreeMap<Box<ServerName>, BTreeMap<ServerKeyId, String>>,
 }
 
 /// PDU type without event and room IDs.
@@ -216,7 +216,7 @@ pub struct RoomV1PduStub {
     pub hashes: EventHash,
 
     /// Signatures for the PDU.
-    pub signatures: BTreeMap<Box<ServerName>, BTreeMap<String, String>>,
+    pub signatures: BTreeMap<Box<ServerName>, BTreeMap<ServerKeyId, String>>,
 }
 
 impl RoomV1PduStub {
@@ -292,7 +292,7 @@ pub struct RoomV3PduStub {
     pub hashes: EventHash,
 
     /// Signatures for the PDU.
-    pub signatures: BTreeMap<Box<ServerName>, BTreeMap<String, String>>,
+    pub signatures: BTreeMap<Box<ServerName>, BTreeMap<ServerKeyId, String>>,
 }
 
 impl RoomV3PduStub {
diff --git a/ruma-events/src/room/member.rs b/ruma-events/src/room/member.rs
index f4b3b576..ce9d7bbb 100644
--- a/ruma-events/src/room/member.rs
+++ b/ruma-events/src/room/member.rs
@@ -3,7 +3,7 @@
 use std::collections::BTreeMap;
 
 use ruma_events_macros::StateEventContent;
-use ruma_identifiers::UserId;
+use ruma_identifiers::{ServerKeyId, ServerName, UserId};
 use serde::{Deserialize, Serialize};
 use strum::{Display, EnumString};
 
@@ -108,7 +108,7 @@ pub struct SignedContent {
 
     /// A single signature from the verifying server, in the format specified by the Signing Events
     /// section of the server-server API.
-    pub signatures: BTreeMap<String, BTreeMap<String, String>>,
+    pub signatures: BTreeMap<Box<ServerName>, BTreeMap<ServerKeyId, String>>,
 
     /// The token property of the containing third_party_invite object.
     pub token: String,
@@ -248,11 +248,12 @@ mod tests {
 
     use maplit::btreemap;
     use matches::assert_matches;
+    use ruma_common::Raw;
+    use ruma_identifiers::{server_key_id, server_name};
     use serde_json::{from_value as from_json_value, json};
 
     use super::{MemberEventContent, MembershipState, SignedContent, ThirdPartyInvite};
     use crate::StateEvent;
-    use ruma_common::Raw;
 
     #[test]
     fn serde_with_no_prev_content() {
@@ -406,8 +407,8 @@ mod tests {
                 && third_party_displayname == "alice"
                 && mxid == "@alice:example.org"
                 && signatures == btreemap! {
-                    "magic.forest".to_owned() => btreemap! {
-                        "ed25519:3".to_owned() => "foobar".to_owned()
+                    server_name!("magic.forest") => btreemap! {
+                        server_key_id!("ed25519:3") => "foobar".to_owned()
                     }
                 }
                 && token == "abc123"
@@ -492,8 +493,8 @@ mod tests {
                 && third_party_displayname == "alice"
                 && mxid == "@alice:example.org"
                 && signatures == btreemap! {
-                    "magic.forest".to_owned() => btreemap! {
-                        "ed25519:3".to_owned() => "foobar".to_owned()
+                    server_name!("magic.forest") => btreemap! {
+                        server_key_id!("ed25519:3") => "foobar".to_owned()
                     }
                 }
                 && token == "abc123"
diff --git a/ruma-identifiers-validation/Cargo.toml b/ruma-identifiers-validation/Cargo.toml
index 6f62bb5b..d1109d8e 100644
--- a/ruma-identifiers-validation/Cargo.toml
+++ b/ruma-identifiers-validation/Cargo.toml
@@ -12,5 +12,9 @@ license = "MIT"
 version = "0.1.0"
 edition = "2018"
 
+[features]
+default = ["serde"]
+
 [dependencies]
+serde = { version = "1.0.114", optional = true, features = ["derive"] }
 strum = { version = "0.19.2", features = ["derive"] }


Test patch:
diff --git a/ruma-events/tests/pdu.rs b/ruma-events/tests/pdu.rs
index d4e7f25c..26d23f54 100644
--- a/ruma-events/tests/pdu.rs
+++ b/ruma-events/tests/pdu.rs
@@ -1,6 +1,5 @@
 use std::{
     collections::BTreeMap,
-    convert::TryInto,
     time::{Duration, SystemTime},
 };
 
@@ -9,16 +8,18 @@ use ruma_events::{
     pdu::{EventHash, Pdu, PduStub, RoomV1Pdu, RoomV1PduStub, RoomV3Pdu, RoomV3PduStub},
     EventType,
 };
-use ruma_identifiers::{event_id, room_id, user_id};
+use ruma_identifiers::{event_id, room_id, server_key_id, server_name, user_id};
 use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
 
 #[test]
 fn serialize_stub_as_v1() {
     let mut signatures = BTreeMap::new();
     let mut inner_signature = BTreeMap::new();
-    inner_signature
-        .insert("ed25519:key_version".into(), "86BytesOfSignatureOfTheRedactedEvent".into());
-    signatures.insert("example.com".try_into().unwrap(), inner_signature);
+    inner_signature.insert(
+        server_key_id!("ed25519:key_version"),
+        "86BytesOfSignatureOfTheRedactedEvent".into(),
+    );
+    signatures.insert(server_name!("example.com"), inner_signature);
 
     let mut unsigned = BTreeMap::new();
     unsigned.insert("somekey".into(), json!({"a": 456}));
@@ -77,9 +78,11 @@ fn serialize_stub_as_v1() {
 fn serialize_stub_as_v3() {
     let mut signatures = BTreeMap::new();
     let mut inner_signature = BTreeMap::new();
-    inner_signature
-        .insert("ed25519:key_version".into(), "86BytesOfSignatureOfTheRedactedEvent".into());
-    signatures.insert("example.com".try_into().unwrap(), inner_signature);
+    inner_signature.insert(
+        server_key_id!("ed25519:key_version"),
+        "86BytesOfSignatureOfTheRedactedEvent".into(),
+    );
+    signatures.insert(server_name!("example.com"), inner_signature);
 
     let mut unsigned = BTreeMap::new();
     unsigned.insert("somekey".into(), json!({"a": 456}));
@@ -158,7 +161,7 @@ fn deserialize_stub_as_v1() {
         "sender": "@someone:matrix.org",
         "signatures": {
             "example.com": {
-                "ed25519:key_version:": "86BytesOfSignatureOfTheRedactedEvent"
+                "ed25519:key_version": "86BytesOfSignatureOfTheRedactedEvent"
             }
         },
         "state_key": "my_key",
@@ -205,7 +208,7 @@ fn deserialize_stub_as_v3() {
         "sender": "@someone:matrix.org",
         "signatures": {
             "example.com": {
-                "ed25519:key_version:": "86BytesOfSignatureOfTheRedactedEvent"
+                "ed25519:key_version": "86BytesOfSignatureOfTheRedactedEvent"
             }
         },
         "state_key": "my_key",
@@ -228,9 +231,11 @@ fn deserialize_stub_as_v3() {
 fn serialize_pdu_as_v1() {
     let mut signatures = BTreeMap::new();
     let mut inner_signature = BTreeMap::new();
-    inner_signature
-        .insert("ed25519:key_version".into(), "86BytesOfSignatureOfTheRedactedEvent".into());
-    signatures.insert("example.com".try_into().unwrap(), inner_signature);
+    inner_signature.insert(
+        server_key_id!("ed25519:key_version"),
+        "86BytesOfSignatureOfTheRedactedEvent".into(),
+    );
+    signatures.insert(server_name!("example.com"), inner_signature);
 
     let mut unsigned = BTreeMap::new();
     unsigned.insert("somekey".into(), json!({"a": 456}));
@@ -293,9 +298,11 @@ fn serialize_pdu_as_v1() {
 fn serialize_pdu_as_v3() {
     let mut signatures = BTreeMap::new();
     let mut inner_signature = BTreeMap::new();
-    inner_signature
-        .insert("ed25519:key_version".into(), "86BytesOfSignatureOfTheRedactedEvent".into());
-    signatures.insert("example.com".try_into().unwrap(), inner_signature);
+    inner_signature.insert(
+        server_key_id!("ed25519:key_version"),
+        "86BytesOfSignatureOfTheRedactedEvent".into(),
+    );
+    signatures.insert(server_name!("example.com"), inner_signature);
 
     let mut unsigned = BTreeMap::new();
     unsigned.insert("somekey".into(), json!({"a": 456}));
@@ -378,7 +385,7 @@ fn test_deserialize_pdu_as_v1() {
         "sender": "@someone:matrix.org",
         "signatures": {
             "example.com": {
-                "ed25519:key_version:": "86BytesOfSignatureOfTheRedactedEvent"
+                "ed25519:key_version": "86BytesOfSignatureOfTheRedactedEvent"
             }
         },
         "state_key": "my_key",
@@ -426,7 +433,7 @@ fn deserialize_pdu_as_v3() {
         "sender": "@someone:matrix.org",
         "signatures": {
             "example.com": {
-                "ed25519:key_version:": "86BytesOfSignatureOfTheRedactedEvent"
+                "ed25519:key_version": "86BytesOfSignatureOfTheRedactedEvent"
             }
         },
         "state_key": "my_key",
@@ -449,9 +456,11 @@ fn deserialize_pdu_as_v3() {
 fn convert_v1_stub_to_pdu() {
     let mut signatures = BTreeMap::new();
     let mut inner_signature = BTreeMap::new();
-    inner_signature
-        .insert("ed25519:key_version".into(), "86BytesOfSignatureOfTheRedactedEvent".into());
-    signatures.insert("example.com".try_into().unwrap(), inner_signature);
+    inner_signature.insert(
+        server_key_id!("ed25519:key_version"),
+        "86BytesOfSignatureOfTheRedactedEvent".into(),
+    );
+    signatures.insert(server_name!("example.com"), inner_signature);
 
     let mut unsigned = BTreeMap::new();
     unsigned.insert("somekey".into(), json!({"a": 456}));
@@ -523,10 +532,12 @@ fn convert_v1_stub_to_pdu() {
 fn convert_v3_stub_to_pdu() {
     let mut signatures = BTreeMap::new();
     let mut inner_signature = BTreeMap::new();
-    inner_signature
-        .insert("ed25519:key_version".into(), "86BytesOfSignatureOfTheRedactedEvent".into());
+    inner_signature.insert(
+        server_key_id!("ed25519:key_version"),
+        "86BytesOfSignatureOfTheRedactedEvent".into(),
+    );
 
-    signatures.insert("example.com".try_into().unwrap(), inner_signature);
+    signatures.insert(server_name!("example.com"), inner_signature);
 
     let mut unsigned = BTreeMap::new();
     unsigned.insert("somekey".into(), json!({"a": 456}));