From b793a790db4352a5d94e994e5f6d4325a9acf2da Mon Sep 17 00:00:00 2001 From: Isaiah Inuwa Date: Fri, 21 Aug 2020 15:56:51 -0500 Subject: [PATCH] Rename ServerKeyId to SigningKeyId --- ruma-client-api/src/r0/membership.rs | 4 +- ruma-events/src/pdu.rs | 10 ++--- ruma-events/src/room/member.rs | 4 +- ruma-federation-api/src/discovery.rs | 14 +++---- .../discovery/get_remote_server_keys/v2.rs | 6 +-- .../get_remote_server_keys_batch/v2.rs | 12 +++--- .../src/discovery/get_server_keys/v2.rs | 10 ++--- .../src/thirdparty/bind_callback/v1.rs | 6 +-- ruma-identifiers-macros/src/lib.rs | 18 ++++++-- .../src/crypto_algorithms.rs | 14 +++---- ruma-identifiers-validation/src/error.rs | 4 +- ruma-identifiers-validation/src/lib.rs | 2 +- .../{server_key_id.rs => signing_key_id.rs} | 10 ++--- ruma-identifiers/CHANGELOG.md | 3 +- ruma-identifiers/src/lib.rs | 8 ++-- .../{server_key_id.rs => signing_key_id.rs} | 42 +++++++++---------- ruma/src/lib.rs | 2 +- 17 files changed, 91 insertions(+), 78 deletions(-) rename ruma-identifiers-validation/src/{server_key_id.rs => signing_key_id.rs} (69%) rename ruma-identifiers/src/{server_key_id.rs => signing_key_id.rs} (53%) diff --git a/ruma-client-api/src/r0/membership.rs b/ruma-client-api/src/r0/membership.rs index 5830a42c..e41e35c6 100644 --- a/ruma-client-api/src/r0/membership.rs +++ b/ruma-client-api/src/r0/membership.rs @@ -15,7 +15,7 @@ pub mod unban_user; use std::collections::BTreeMap; use ruma_common::{thirdparty::Medium, Outgoing}; -use ruma_identifiers::{ServerKeyId, ServerNameBox}; +use ruma_identifiers::{ServerNameBox, SigningKeyId}; use serde::Serialize; /// A signature of an `m.third_party_invite` token to prove that this user owns a third party @@ -32,7 +32,7 @@ pub struct ThirdPartySigned<'a> { pub token: &'a str, /// A signatures object containing a signature of the entire signed object. - pub signatures: BTreeMap>, + pub signatures: BTreeMap>, } /// Represents third party IDs to invite to the room. diff --git a/ruma-events/src/pdu.rs b/ruma-events/src/pdu.rs index 5d95b66c..f71b510e 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, ServerKeyId, ServerNameBox, UserId}; +use ruma_identifiers::{EventId, RoomId, ServerNameBox, SigningKeyId, UserId}; use serde::{Deserialize, Serialize}; use serde_json::Value as JsonValue; @@ -86,7 +86,7 @@ pub struct RoomV1Pdu { pub hashes: EventHash, /// Signatures for the PDU. - pub signatures: BTreeMap>, + pub signatures: BTreeMap>, } /// A 'persistent data unit' (event) for room versions 3 and beyond. @@ -143,7 +143,7 @@ pub struct RoomV3Pdu { pub hashes: EventHash, /// Signatures for the PDU. - pub signatures: BTreeMap>, + pub signatures: BTreeMap>, } /// PDU type without event and room IDs. @@ -220,7 +220,7 @@ pub struct RoomV1PduStub { pub hashes: EventHash, /// Signatures for the PDU. - pub signatures: BTreeMap>, + pub signatures: BTreeMap>, } impl RoomV1PduStub { @@ -298,7 +298,7 @@ pub struct RoomV3PduStub { pub hashes: EventHash, /// Signatures for the PDU. - pub signatures: BTreeMap>, + pub signatures: BTreeMap>, } impl RoomV3PduStub { diff --git a/ruma-events/src/room/member.rs b/ruma-events/src/room/member.rs index e735e5c2..dd3d68b2 100644 --- a/ruma-events/src/room/member.rs +++ b/ruma-events/src/room/member.rs @@ -4,7 +4,7 @@ use std::collections::BTreeMap; use ruma_common::StringEnum; use ruma_events_macros::StateEventContent; -use ruma_identifiers::{ServerKeyId, ServerNameBox, UserId}; +use ruma_identifiers::{ServerNameBox, SigningKeyId, UserId}; use serde::{Deserialize, Serialize}; use crate::{StateEvent, StrippedStateEvent, SyncStateEvent}; @@ -109,7 +109,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>, + pub signatures: BTreeMap>, /// The token property of the containing third_party_invite object. pub token: String, diff --git a/ruma-federation-api/src/discovery.rs b/ruma-federation-api/src/discovery.rs index 54b5df7c..c43f87f9 100644 --- a/ruma-federation-api/src/discovery.rs +++ b/ruma-federation-api/src/discovery.rs @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, time::SystemTime}; -use ruma_identifiers::{ServerKeyId, ServerNameBox}; +use ruma_identifiers::{ServerNameBox, SigningKeyId}; use serde::{Deserialize, Serialize}; pub mod discover_homeserver; @@ -49,19 +49,19 @@ impl OldVerifyKey { /// Queried server key, signed by the notary server. #[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -pub struct ServerKey { +pub struct SigningKey { /// DNS name of the homeserver. pub server_name: ServerNameBox, /// Public keys of the homeserver for verifying digital signatures. - pub verify_keys: BTreeMap, + pub verify_keys: BTreeMap, /// Public keys that the homeserver used to use and when it stopped using them. - pub old_verify_keys: BTreeMap, + pub old_verify_keys: BTreeMap, /// Digital signatures of this object signed using the verify_keys. Map of /// server name to keys by key ID - pub signatures: BTreeMap>, + pub signatures: BTreeMap>, /// Timestamp when the keys should be refreshed. This field MUST be ignored in room /// versions 1, 2, 3, and 4. @@ -69,8 +69,8 @@ pub struct ServerKey { pub valid_until_ts: SystemTime, } -impl ServerKey { - /// Creates a new `ServerKey` with the given server name and validity timestamp. +impl SigningKey { + /// Creates a new `SigningKey` with the given server name and validity timestamp. /// /// All other fields will be empty. pub fn new(server_name: ServerNameBox, valid_until_ts: SystemTime) -> Self { diff --git a/ruma-federation-api/src/discovery/get_remote_server_keys/v2.rs b/ruma-federation-api/src/discovery/get_remote_server_keys/v2.rs index a95efce2..76c991e7 100644 --- a/ruma-federation-api/src/discovery/get_remote_server_keys/v2.rs +++ b/ruma-federation-api/src/discovery/get_remote_server_keys/v2.rs @@ -2,7 +2,7 @@ use std::time::SystemTime; -use crate::discovery::ServerKey; +use crate::discovery::SigningKey; use ruma_api::ruma_api; use ruma_identifiers::ServerName; @@ -34,7 +34,7 @@ ruma_api! { response: { /// The queried server's keys, signed by the notary server. - pub server_keys: Vec, + pub server_keys: Vec, } } @@ -47,7 +47,7 @@ impl<'a> Request<'a> { impl Response { /// Creates a new `Response` with the given keys. - pub fn new(server_keys: Vec) -> Self { + pub fn new(server_keys: Vec) -> Self { Self { server_keys } } } diff --git a/ruma-federation-api/src/discovery/get_remote_server_keys_batch/v2.rs b/ruma-federation-api/src/discovery/get_remote_server_keys_batch/v2.rs index 9373a2d4..3fce3a8e 100644 --- a/ruma-federation-api/src/discovery/get_remote_server_keys_batch/v2.rs +++ b/ruma-federation-api/src/discovery/get_remote_server_keys_batch/v2.rs @@ -2,9 +2,9 @@ use std::{collections::BTreeMap, time::SystemTime}; -use crate::discovery::ServerKey; +use crate::discovery::SigningKey; use ruma_api::ruma_api; -use ruma_identifiers::{ServerKeyId, ServerNameBox}; +use ruma_identifiers::{ServerNameBox, SigningKeyId}; use serde::{Deserialize, Serialize}; ruma_api! { @@ -28,7 +28,7 @@ ruma_api! { /// The notary server may return multiple keys regardless of the Key IDs /// given. #[ruma_api(body)] - pub server_keys: BTreeMap>, + pub server_keys: BTreeMap>, /// A millisecond POSIX timestamp in milliseconds indicating when the /// returned certificates will need to be valid until to be useful to @@ -43,14 +43,14 @@ ruma_api! { response: { /// The queried server's keys, signed by the notary server. - pub server_keys: Vec, + pub server_keys: Vec, } } impl Request { /// Creates a new `Request` with the given query criteria and `minimum_valid_until` timestamp. pub fn new( - server_keys: BTreeMap>, + server_keys: BTreeMap>, minimum_valid_until_ts: SystemTime, ) -> Self { Self { server_keys, minimum_valid_until_ts } @@ -59,7 +59,7 @@ impl Request { impl Response { /// Creates a new `Response` with the given keys. - pub fn new(server_keys: Vec) -> Self { + pub fn new(server_keys: Vec) -> Self { Self { server_keys } } } diff --git a/ruma-federation-api/src/discovery/get_server_keys/v2.rs b/ruma-federation-api/src/discovery/get_server_keys/v2.rs index c3f942f5..de5944f7 100644 --- a/ruma-federation-api/src/discovery/get_server_keys/v2.rs +++ b/ruma-federation-api/src/discovery/get_server_keys/v2.rs @@ -1,6 +1,6 @@ //! [GET /_matrix/key/v2/server](https://matrix.org/docs/spec/server_server/r0.1.4#get-matrix-key-v2-server-keyid) -use crate::discovery::ServerKey; +use crate::discovery::SigningKey; use ruma_api::ruma_api; ruma_api! { @@ -19,7 +19,7 @@ ruma_api! { response: { /// Queried server key, signed by the notary server. #[ruma_api(body)] - pub server_key: ServerKey, + pub server_key: SigningKey, } } @@ -32,13 +32,13 @@ impl Request { impl Response { /// Creates a new `Response` with the given server key. - pub fn new(server_key: ServerKey) -> Self { + pub fn new(server_key: SigningKey) -> Self { Self { server_key } } } -impl From for Response { - fn from(server_key: ServerKey) -> Self { +impl From for Response { + fn from(server_key: SigningKey) -> Self { Self::new(server_key) } } diff --git a/ruma-federation-api/src/thirdparty/bind_callback/v1.rs b/ruma-federation-api/src/thirdparty/bind_callback/v1.rs index ca55d0d9..14fe9f2c 100644 --- a/ruma-federation-api/src/thirdparty/bind_callback/v1.rs +++ b/ruma-federation-api/src/thirdparty/bind_callback/v1.rs @@ -2,7 +2,7 @@ use ruma_api::ruma_api; use ruma_common::thirdparty::Medium; -use ruma_identifiers::{RoomId, ServerKeyId, ServerNameBox, UserId}; +use ruma_identifiers::{RoomId, ServerNameBox, SigningKeyId, UserId}; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; @@ -61,7 +61,7 @@ pub struct ThirdPartyInvite { pub sender: UserId, /// Signature from the identity server using a long-term private key. - pub signed: BTreeMap>, + pub signed: BTreeMap>, } impl ThirdPartyInvite { @@ -71,7 +71,7 @@ impl ThirdPartyInvite { mxid: UserId, room_id: RoomId, sender: UserId, - signed: BTreeMap>, + signed: BTreeMap>, ) -> Self { Self { medium: Medium::Email, address, mxid, room_id, sender, signed } } diff --git a/ruma-identifiers-macros/src/lib.rs b/ruma-identifiers-macros/src/lib.rs index 1560bb08..be28e840 100644 --- a/ruma-identifiers-macros/src/lib.rs +++ b/ruma-identifiers-macros/src/lib.rs @@ -2,7 +2,7 @@ use proc_macro::TokenStream; use quote::quote; use ruma_identifiers_validation::{ - device_key_id, event_id, room_alias_id, room_id, room_version_id, server_key_id, server_name, + device_key_id, event_id, room_alias_id, room_id, room_version_id, server_name, signing_key_id, user_id, }; use syn::{parse::Parse, parse_macro_input, LitStr, Path, Token}; @@ -85,10 +85,10 @@ pub fn room_version_id(input: TokenStream) -> TokenStream { #[proc_macro] pub fn server_key_id(input: TokenStream) -> TokenStream { let Input { dollar_crate, id } = parse_macro_input!(input as Input); - assert!(server_key_id::validate(&id.value()).is_ok(), "Invalid server_key_id"); + assert!(signing_key_id::validate(&id.value()).is_ok(), "Invalid server_key_id"); let output = quote! { - <#dollar_crate::ServerKeyId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap() + <#dollar_crate::SigningKeyId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap() }; output.into() @@ -108,6 +108,18 @@ pub fn server_name(input: TokenStream) -> TokenStream { output.into() } +#[proc_macro] +pub fn signing_key_id(input: TokenStream) -> TokenStream { + let Input { dollar_crate, id } = parse_macro_input!(input as Input); + assert!(signing_key_id::validate(&id.value()).is_ok(), "Invalid signing_key_id"); + + let output = quote! { + <#dollar_crate::SigningKeyId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap() + }; + + output.into() +} + #[proc_macro] pub fn user_id(input: TokenStream) -> TokenStream { let Input { dollar_crate, id } = parse_macro_input!(input as Input); diff --git a/ruma-identifiers-validation/src/crypto_algorithms.rs b/ruma-identifiers-validation/src/crypto_algorithms.rs index 02f0a133..3d5b85d8 100644 --- a/ruma-identifiers-validation/src/crypto_algorithms.rs +++ b/ruma-identifiers-validation/src/crypto_algorithms.rs @@ -42,17 +42,17 @@ impl TryFrom for DeviceKeyAlgorithm { } } -/// The server key algorithms defined in the Matrix spec. +/// The signing key algorithms defined in the Matrix spec. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, AsRefStr, Display, EnumString)] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize), serde(rename_all = "snake_case"))] #[non_exhaustive] #[strum(serialize_all = "snake_case")] -pub enum ServerKeyAlgorithm { +pub enum SigningKeyAlgorithm { /// The Ed25519 signature algorithm. Ed25519, } -impl TryFrom<&'_ str> for ServerKeyAlgorithm { +impl TryFrom<&'_ str> for SigningKeyAlgorithm { type Error = strum::ParseError; fn try_from(value: &str) -> Result { @@ -60,7 +60,7 @@ impl TryFrom<&'_ str> for ServerKeyAlgorithm { } } -impl TryFrom for ServerKeyAlgorithm { +impl TryFrom for SigningKeyAlgorithm { type Error = strum::ParseError; fn try_from(value: String) -> Result { @@ -132,7 +132,7 @@ mod tests { use ruma_serde::test::serde_json_eq; use serde_json::json; - use super::{DeviceKeyAlgorithm, EventEncryptionAlgorithm, ServerKeyAlgorithm}; + use super::{DeviceKeyAlgorithm, EventEncryptionAlgorithm, SigningKeyAlgorithm}; #[test] fn parse_device_key_algorithm() { @@ -142,8 +142,8 @@ mod tests { } #[test] - fn parse_server_key_algorithm() { - assert_eq!("ed25519".parse(), Ok(ServerKeyAlgorithm::Ed25519)); + fn parse_signing_key_algorithm() { + assert_eq!("ed25519".parse(), Ok(SigningKeyAlgorithm::Ed25519)); } #[test] diff --git a/ruma-identifiers-validation/src/error.rs b/ruma-identifiers-validation/src/error.rs index 792be507..103817cb 100644 --- a/ruma-identifiers-validation/src/error.rs +++ b/ruma-identifiers-validation/src/error.rs @@ -29,7 +29,7 @@ pub enum Error { MissingDeviceKeyDelimiter, /// The ID is missing the colon delimiter between key algorithm and version. - MissingServerKeyDelimiter, + MissingSigningKeyDelimiter, /// The ID is missing the correct leading sigil. MissingSigil, @@ -48,7 +48,7 @@ impl Display for Error { Error::MaximumLengthExceeded => "ID exceeds 255 bytes", Error::MissingDelimiter => "colon is required between localpart and server name", Error::MissingDeviceKeyDelimiter => "colon is required between algorithm and device ID", - Error::MissingServerKeyDelimiter => "colon is required between algorithm and version", + Error::MissingSigningKeyDelimiter => "colon is required between algorithm and version", Error::MissingSigil => "leading sigil is incorrect or missing", Error::UnknownKeyAlgorithm => "unknown key algorithm specified", }; diff --git a/ruma-identifiers-validation/src/lib.rs b/ruma-identifiers-validation/src/lib.rs index de1c5e69..80477ae1 100644 --- a/ruma-identifiers-validation/src/lib.rs +++ b/ruma-identifiers-validation/src/lib.rs @@ -6,8 +6,8 @@ pub mod room_alias_id; pub mod room_id; pub mod room_id_or_alias_id; pub mod room_version_id; -pub mod server_key_id; pub mod server_name; +pub mod signing_key_id; pub mod user_id; use std::num::NonZeroU8; diff --git a/ruma-identifiers-validation/src/server_key_id.rs b/ruma-identifiers-validation/src/signing_key_id.rs similarity index 69% rename from ruma-identifiers-validation/src/server_key_id.rs rename to ruma-identifiers-validation/src/signing_key_id.rs index 76c35106..d039266b 100644 --- a/ruma-identifiers-validation/src/server_key_id.rs +++ b/ruma-identifiers-validation/src/signing_key_id.rs @@ -1,12 +1,12 @@ use std::{num::NonZeroU8, str::FromStr}; -use crate::{crypto_algorithms::ServerKeyAlgorithm, Error}; +use crate::{crypto_algorithms::SigningKeyAlgorithm, Error}; pub fn validate(s: &str) -> Result { - let colon_idx = NonZeroU8::new(s.find(':').ok_or(Error::MissingServerKeyDelimiter)? as u8) + let colon_idx = NonZeroU8::new(s.find(':').ok_or(Error::MissingSigningKeyDelimiter)? as u8) .ok_or(Error::UnknownKeyAlgorithm)?; - validate_server_key_algorithm(&s[..colon_idx.get() as usize])?; + validate_signing_key_algorithm(&s[..colon_idx.get() as usize])?; validate_version(&s[colon_idx.get() as usize + 1..])?; Ok(colon_idx) @@ -22,8 +22,8 @@ fn validate_version(version: &str) -> Result<(), Error> { Ok(()) } -fn validate_server_key_algorithm(algorithm: &str) -> Result<(), Error> { - match ServerKeyAlgorithm::from_str(algorithm) { +fn validate_signing_key_algorithm(algorithm: &str) -> Result<(), Error> { + match SigningKeyAlgorithm::from_str(algorithm) { Ok(_) => Ok(()), Err(_) => Err(Error::UnknownKeyAlgorithm), } diff --git a/ruma-identifiers/CHANGELOG.md b/ruma-identifiers/CHANGELOG.md index 28d8bf86..65b551ef 100644 --- a/ruma-identifiers/CHANGELOG.md +++ b/ruma-identifiers/CHANGELOG.md @@ -5,10 +5,11 @@ Breaking changes: * Update strum dependency to 0.19 * Remove deprecated constructors * Remove deprecated `is_` methods +* Rename `ServerKeyId` to `SigningKeyId` Improvements: -* Add `DeviceKeyId::from_parts` and `ServerKeyId::from_parts` +* Add `DeviceKeyId::from_parts` and `SigningKeyId::from_parts` * Add `DeviceIdBox` and `ServerNameBox` type aliases # 0.17.4 diff --git a/ruma-identifiers/src/lib.rs b/ruma-identifiers/src/lib.rs index 5884c5e4..6ae49988 100644 --- a/ruma-identifiers/src/lib.rs +++ b/ruma-identifiers/src/lib.rs @@ -28,13 +28,13 @@ pub use crate::{ room_id::RoomId, room_id_or_room_alias_id::RoomIdOrAliasId, room_version_id::RoomVersionId, - server_key_id::ServerKeyId, server_name::{ServerName, ServerNameBox}, + signing_key_id::SigningKeyId, user_id::UserId, }; #[doc(inline)] pub use ruma_identifiers_validation::{ - crypto_algorithms::{DeviceKeyAlgorithm, EventEncryptionAlgorithm, ServerKeyAlgorithm}, + crypto_algorithms::{DeviceKeyAlgorithm, EventEncryptionAlgorithm, SigningKeyAlgorithm}, error::Error, }; @@ -50,8 +50,8 @@ mod room_alias_id; mod room_id; mod room_id_or_room_alias_id; mod room_version_id; -mod server_key_id; mod server_name; +mod signing_key_id; /// Check whether a given string is a valid server name according to [the specification][]. /// @@ -137,7 +137,7 @@ macro_rules! room_version_id { }; } -/// Compile-time checked `ServerKeyId` construction. +/// Compile-time checked `SigningKeyId` construction. #[macro_export] macro_rules! server_key_id { ($s:literal) => { diff --git a/ruma-identifiers/src/server_key_id.rs b/ruma-identifiers/src/signing_key_id.rs similarity index 53% rename from ruma-identifiers/src/server_key_id.rs rename to ruma-identifiers/src/signing_key_id.rs index ae8f5971..e66aa72f 100644 --- a/ruma-identifiers/src/server_key_id.rs +++ b/ruma-identifiers/src/signing_key_id.rs @@ -2,18 +2,18 @@ use std::{convert::TryInto, num::NonZeroU8, str::FromStr}; -use ruma_identifiers_validation::{crypto_algorithms::ServerKeyAlgorithm, Error}; +use ruma_identifiers_validation::{crypto_algorithms::SigningKeyAlgorithm, Error}; /// Key identifiers used for homeserver signing keys. #[derive(Clone, Debug)] -pub struct ServerKeyId { +pub struct SigningKeyId { full_id: Box, colon_idx: NonZeroU8, } -impl ServerKeyId { - /// Create a `ServerKeyId` from a `ServerKeyAlgorithm` and a `ServerId`. - pub fn from_parts(algorithm: ServerKeyAlgorithm, version: &str) -> Self { +impl SigningKeyId { + /// Create a `SigningKeyId` from a `SigningKeyAlgorithm` and a `ServerId`. + pub fn from_parts(algorithm: SigningKeyAlgorithm, version: &str) -> Self { let algorithm: &str = algorithm.as_ref(); let mut res = String::with_capacity(algorithm.len() + 1 + version.len()); @@ -25,12 +25,12 @@ impl ServerKeyId { NonZeroU8::new(algorithm.len().try_into().expect("no algorithm name len > 255")) .expect("no empty algorithm name"); - ServerKeyId { full_id: res.into(), colon_idx } + SigningKeyId { full_id: res.into(), colon_idx } } /// Returns key algorithm of the server key ID. - pub fn algorithm(&self) -> ServerKeyAlgorithm { - ServerKeyAlgorithm::from_str(&self.full_id[..self.colon_idx.get() as usize]).unwrap() + pub fn algorithm(&self) -> SigningKeyAlgorithm { + SigningKeyAlgorithm::from_str(&self.full_id[..self.colon_idx.get() as usize]).unwrap() } /// Returns the version of the server key ID. @@ -39,15 +39,15 @@ impl ServerKeyId { } } -fn try_from(key_id: S) -> Result +fn try_from(key_id: S) -> Result where S: AsRef + Into>, { - let colon_idx = ruma_identifiers_validation::server_key_id::validate(key_id.as_ref())?; - Ok(ServerKeyId { full_id: key_id.into(), colon_idx }) + let colon_idx = ruma_identifiers_validation::signing_key_id::validate(key_id.as_ref())?; + Ok(SigningKeyId { full_id: key_id.into(), colon_idx }) } -common_impls!(ServerKeyId, try_from, "Key ID with algorithm and version"); +common_impls!(SigningKeyId, try_from, "Key ID with algorithm and version"); #[cfg(test)] mod tests { @@ -56,35 +56,35 @@ mod tests { #[cfg(feature = "serde")] use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; - use crate::{Error, ServerKeyId}; + use crate::{Error, SigningKeyId}; #[cfg(feature = "serde")] - use ruma_identifiers_validation::crypto_algorithms::ServerKeyAlgorithm; + use ruma_identifiers_validation::crypto_algorithms::SigningKeyAlgorithm; #[cfg(feature = "serde")] #[test] fn deserialize_id() { - let server_key_id: ServerKeyId = from_json_value(json!("ed25519:Abc_1")).unwrap(); - assert_eq!(server_key_id.algorithm(), ServerKeyAlgorithm::Ed25519); + let server_key_id: SigningKeyId = from_json_value(json!("ed25519:Abc_1")).unwrap(); + assert_eq!(server_key_id.algorithm(), SigningKeyAlgorithm::Ed25519); assert_eq!(server_key_id.version(), "Abc_1"); } #[cfg(feature = "serde")] #[test] fn serialize_id() { - let server_key_id: ServerKeyId = ServerKeyId::try_from("ed25519:abc123").unwrap(); + let server_key_id: SigningKeyId = SigningKeyId::try_from("ed25519:abc123").unwrap(); assert_eq!(to_json_value(&server_key_id).unwrap(), json!("ed25519:abc123")); } #[test] fn invalid_version_characters() { - assert_eq!(ServerKeyId::try_from("ed25519:Abc-1").unwrap_err(), Error::InvalidCharacters); + assert_eq!(SigningKeyId::try_from("ed25519:Abc-1").unwrap_err(), Error::InvalidCharacters); } #[test] fn invalid_key_algorithm() { assert_eq!( - ServerKeyId::try_from("signed_curve25519:Abc-1").unwrap_err(), + SigningKeyId::try_from("signed_curve25519:Abc-1").unwrap_err(), Error::UnknownKeyAlgorithm, ); } @@ -92,8 +92,8 @@ mod tests { #[test] fn missing_delimiter() { assert_eq!( - ServerKeyId::try_from("ed25519|Abc_1").unwrap_err(), - Error::MissingServerKeyDelimiter, + SigningKeyId::try_from("ed25519|Abc_1").unwrap_err(), + Error::MissingSigningKeyDelimiter, ); } } diff --git a/ruma/src/lib.rs b/ruma/src/lib.rs index 18b51c65..30718cdc 100644 --- a/ruma/src/lib.rs +++ b/ruma/src/lib.rs @@ -27,7 +27,7 @@ pub use ruma_serde as serde; pub use ruma_identifiers::{ device_id, device_key_id, event_id, room_alias_id, room_id, room_version_id, server_key_id, server_name, user_id, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, EventId, RoomAliasId, RoomId, - RoomIdOrAliasId, RoomVersionId, ServerKeyAlgorithm, ServerKeyId, ServerName, UserId, + RoomIdOrAliasId, RoomVersionId, ServerName, SigningKeyAlgorithm, SigningKeyId, UserId, }; #[cfg(feature = "ruma-events")]