Rename SigningKeyId to ServerSigningKeyId

This commit is contained in:
Jonas Platte 2020-11-08 19:24:48 +01:00
parent c6ef3a06fa
commit 374603f51c
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
11 changed files with 43 additions and 38 deletions

View File

@ -15,7 +15,7 @@ pub mod unban_user;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use ruma_common::{thirdparty::Medium, Outgoing}; use ruma_common::{thirdparty::Medium, Outgoing};
use ruma_identifiers::{ServerNameBox, SigningKeyId}; use ruma_identifiers::{ServerNameBox, ServerSigningKeyId};
use serde::Serialize; use serde::Serialize;
/// A signature of an `m.third_party_invite` token to prove that this user owns a third party /// 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, pub token: &'a str,
/// A signatures object containing a signature of the entire signed object. /// A signatures object containing a signature of the entire signed object.
pub signatures: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, String>>, pub signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
} }
/// Represents third party IDs to invite to the room. /// Represents third party IDs to invite to the room.

View File

@ -12,7 +12,7 @@ use std::{collections::BTreeMap, time::SystemTime};
use js_int::UInt; use js_int::UInt;
use ruma_events::EventType; use ruma_events::EventType;
use ruma_identifiers::{EventId, RoomId, ServerNameBox, SigningKeyId, UserId}; use ruma_identifiers::{EventId, RoomId, ServerNameBox, ServerSigningKeyId, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
@ -86,7 +86,7 @@ pub struct RoomV1Pdu {
pub hashes: EventHash, pub hashes: EventHash,
/// Signatures for the PDU. /// Signatures for the PDU.
pub signatures: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, String>>, pub signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
} }
/// A 'persistent data unit' (event) for room versions 3 and beyond. /// A 'persistent data unit' (event) for room versions 3 and beyond.
@ -143,7 +143,7 @@ pub struct RoomV3Pdu {
pub hashes: EventHash, pub hashes: EventHash,
/// Signatures for the PDU. /// Signatures for the PDU.
pub signatures: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, String>>, pub signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
} }
/// PDU type without event and room IDs. /// PDU type without event and room IDs.
@ -220,7 +220,7 @@ pub struct RoomV1PduStub {
pub hashes: EventHash, pub hashes: EventHash,
/// Signatures for the PDU. /// Signatures for the PDU.
pub signatures: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, String>>, pub signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
} }
impl RoomV1PduStub { impl RoomV1PduStub {
@ -298,7 +298,7 @@ pub struct RoomV3PduStub {
pub hashes: EventHash, pub hashes: EventHash,
/// Signatures for the PDU. /// Signatures for the PDU.
pub signatures: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, String>>, pub signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
} }
impl RoomV3PduStub { impl RoomV3PduStub {

View File

@ -4,7 +4,7 @@ use std::collections::BTreeMap;
use ruma_common::StringEnum; use ruma_common::StringEnum;
use ruma_events_macros::StateEventContent; use ruma_events_macros::StateEventContent;
use ruma_identifiers::{ServerNameBox, SigningKeyId, UserId}; use ruma_identifiers::{ServerNameBox, ServerSigningKeyId, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{StateEvent, StrippedStateEvent, SyncStateEvent}; 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 /// A single signature from the verifying server, in the format specified by the Signing Events
/// section of the server-server API. /// section of the server-server API.
pub signatures: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, String>>, pub signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
/// The token property of the containing third_party_invite object. /// The token property of the containing third_party_invite object.
pub token: String, pub token: String,

View File

@ -2,7 +2,7 @@
use std::{collections::BTreeMap, time::SystemTime}; use std::{collections::BTreeMap, time::SystemTime};
use ruma_identifiers::{ServerNameBox, SigningKeyId}; use ruma_identifiers::{ServerNameBox, ServerSigningKeyId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub mod discover_homeserver; pub mod discover_homeserver;
@ -54,14 +54,14 @@ pub struct SigningKey {
pub server_name: ServerNameBox, pub server_name: ServerNameBox,
/// Public keys of the homeserver for verifying digital signatures. /// Public keys of the homeserver for verifying digital signatures.
pub verify_keys: BTreeMap<SigningKeyId, VerifyKey>, pub verify_keys: BTreeMap<ServerSigningKeyId, VerifyKey>,
/// Public keys that the homeserver used to use and when it stopped using them. /// Public keys that the homeserver used to use and when it stopped using them.
pub old_verify_keys: BTreeMap<SigningKeyId, OldVerifyKey>, pub old_verify_keys: BTreeMap<ServerSigningKeyId, OldVerifyKey>,
/// Digital signatures of this object signed using the verify_keys. Map of /// Digital signatures of this object signed using the verify_keys. Map of
/// server name to keys by key ID /// server name to keys by key ID
pub signatures: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, String>>, pub signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
/// Timestamp when the keys should be refreshed. This field MUST be ignored in room /// Timestamp when the keys should be refreshed. This field MUST be ignored in room
/// versions 1, 2, 3, and 4. /// versions 1, 2, 3, and 4.

View File

@ -4,7 +4,7 @@ use std::{collections::BTreeMap, time::SystemTime};
use crate::discovery::SigningKey; use crate::discovery::SigningKey;
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_identifiers::{ServerNameBox, SigningKeyId}; use ruma_identifiers::{ServerNameBox, ServerSigningKeyId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
ruma_api! { ruma_api! {
@ -28,7 +28,7 @@ ruma_api! {
/// The notary server may return multiple keys regardless of the Key IDs /// The notary server may return multiple keys regardless of the Key IDs
/// given. /// given.
#[ruma_api(body)] #[ruma_api(body)]
pub server_keys: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, QueryCriteria>>, pub server_keys: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, QueryCriteria>>,
/// A millisecond POSIX timestamp in milliseconds indicating when the /// A millisecond POSIX timestamp in milliseconds indicating when the
/// returned certificates will need to be valid until to be useful to /// returned certificates will need to be valid until to be useful to
@ -50,7 +50,7 @@ ruma_api! {
impl Request { impl Request {
/// Creates a new `Request` with the given query criteria and `minimum_valid_until` timestamp. /// Creates a new `Request` with the given query criteria and `minimum_valid_until` timestamp.
pub fn new( pub fn new(
server_keys: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, QueryCriteria>>, server_keys: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, QueryCriteria>>,
minimum_valid_until_ts: SystemTime, minimum_valid_until_ts: SystemTime,
) -> Self { ) -> Self {
Self { server_keys, minimum_valid_until_ts } Self { server_keys, minimum_valid_until_ts }

View File

@ -2,7 +2,7 @@
use ruma_api::ruma_api; use ruma_api::ruma_api;
use ruma_common::thirdparty::Medium; use ruma_common::thirdparty::Medium;
use ruma_identifiers::{RoomId, ServerNameBox, SigningKeyId, UserId}; use ruma_identifiers::{RoomId, ServerNameBox, ServerSigningKeyId, UserId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -61,7 +61,7 @@ pub struct ThirdPartyInvite {
pub sender: UserId, pub sender: UserId,
/// Signature from the identity server using a long-term private key. /// Signature from the identity server using a long-term private key.
pub signed: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, String>>, pub signed: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
} }
impl ThirdPartyInvite { impl ThirdPartyInvite {
@ -71,7 +71,7 @@ impl ThirdPartyInvite {
mxid: UserId, mxid: UserId,
room_id: RoomId, room_id: RoomId,
sender: UserId, sender: UserId,
signed: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, String>>, signed: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
) -> Self { ) -> Self {
Self { medium: Medium::Email, address, mxid, room_id, sender, signed } Self { medium: Medium::Email, address, mxid, room_id, sender, signed }
} }

View File

@ -88,7 +88,7 @@ pub fn server_key_id(input: TokenStream) -> TokenStream {
assert!(signing_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! { let output = quote! {
<#dollar_crate::SigningKeyId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap() <#dollar_crate::ServerSigningKeyId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap()
}; };
output.into() output.into()
@ -114,7 +114,7 @@ pub fn signing_key_id(input: TokenStream) -> TokenStream {
assert!(signing_key_id::validate(&id.value()).is_ok(), "Invalid signing_key_id"); assert!(signing_key_id::validate(&id.value()).is_ok(), "Invalid signing_key_id");
let output = quote! { let output = quote! {
<#dollar_crate::SigningKeyId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap() <#dollar_crate::ServerSigningKeyId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap()
}; };
output.into() output.into()

View File

@ -5,7 +5,8 @@ Breaking changes:
* Update strum dependency to 0.19 * Update strum dependency to 0.19
* Remove deprecated constructors * Remove deprecated constructors
* Remove deprecated `is_` methods * Remove deprecated `is_` methods
* Rename `ServerKeyId` to `SigningKeyId` * Rename `ServerKeyAlgorithm` to `SigningKeyAlgorithm`
* Rename `ServerKeyId` to `ServerSigningKeyId`
Improvements: Improvements:

View File

@ -29,7 +29,7 @@ pub use crate::{
room_id_or_room_alias_id::RoomIdOrAliasId, room_id_or_room_alias_id::RoomIdOrAliasId,
room_version_id::RoomVersionId, room_version_id::RoomVersionId,
server_name::{ServerName, ServerNameBox}, server_name::{ServerName, ServerNameBox},
signing_key_id::SigningKeyId, signing_key_id::ServerSigningKeyId,
user_id::UserId, user_id::UserId,
}; };
#[doc(inline)] #[doc(inline)]
@ -137,7 +137,7 @@ macro_rules! room_version_id {
}; };
} }
/// Compile-time checked `SigningKeyId` construction. /// Compile-time checked `ServerSigningKeyId` construction.
#[macro_export] #[macro_export]
macro_rules! server_key_id { macro_rules! server_key_id {
($s:literal) => { ($s:literal) => {

View File

@ -6,13 +6,13 @@ use ruma_identifiers_validation::{crypto_algorithms::SigningKeyAlgorithm, Error}
/// Key identifiers used for homeserver signing keys. /// Key identifiers used for homeserver signing keys.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SigningKeyId { pub struct ServerSigningKeyId {
full_id: Box<str>, full_id: Box<str>,
colon_idx: NonZeroU8, colon_idx: NonZeroU8,
} }
impl SigningKeyId { impl ServerSigningKeyId {
/// Create a `SigningKeyId` from a `SigningKeyAlgorithm` and a `ServerId`. /// Create a `ServerSigningKeyId` from a `SigningKeyAlgorithm` and a `ServerId`.
pub fn from_parts(algorithm: SigningKeyAlgorithm, version: &str) -> Self { pub fn from_parts(algorithm: SigningKeyAlgorithm, version: &str) -> Self {
let algorithm: &str = algorithm.as_ref(); let algorithm: &str = algorithm.as_ref();
@ -25,7 +25,7 @@ impl SigningKeyId {
NonZeroU8::new(algorithm.len().try_into().expect("no algorithm name len > 255")) NonZeroU8::new(algorithm.len().try_into().expect("no algorithm name len > 255"))
.expect("no empty algorithm name"); .expect("no empty algorithm name");
SigningKeyId { full_id: res.into(), colon_idx } ServerSigningKeyId { full_id: res.into(), colon_idx }
} }
/// Returns key algorithm of the server key ID. /// Returns key algorithm of the server key ID.
@ -39,15 +39,15 @@ impl SigningKeyId {
} }
} }
fn try_from<S>(key_id: S) -> Result<SigningKeyId, Error> fn try_from<S>(key_id: S) -> Result<ServerSigningKeyId, Error>
where where
S: AsRef<str> + Into<Box<str>>, S: AsRef<str> + Into<Box<str>>,
{ {
let colon_idx = ruma_identifiers_validation::signing_key_id::validate(key_id.as_ref())?; let colon_idx = ruma_identifiers_validation::signing_key_id::validate(key_id.as_ref())?;
Ok(SigningKeyId { full_id: key_id.into(), colon_idx }) Ok(ServerSigningKeyId { full_id: key_id.into(), colon_idx })
} }
common_impls!(SigningKeyId, try_from, "Key ID with algorithm and version"); common_impls!(ServerSigningKeyId, try_from, "Key ID with algorithm and version");
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -56,7 +56,7 @@ mod tests {
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
use crate::{Error, SigningKeyId}; use crate::{Error, ServerSigningKeyId};
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use ruma_identifiers_validation::crypto_algorithms::SigningKeyAlgorithm; use ruma_identifiers_validation::crypto_algorithms::SigningKeyAlgorithm;
@ -64,7 +64,7 @@ mod tests {
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
#[test] #[test]
fn deserialize_id() { fn deserialize_id() {
let server_key_id: SigningKeyId = from_json_value(json!("ed25519:Abc_1")).unwrap(); let server_key_id: ServerSigningKeyId = from_json_value(json!("ed25519:Abc_1")).unwrap();
assert_eq!(server_key_id.algorithm(), SigningKeyAlgorithm::Ed25519); assert_eq!(server_key_id.algorithm(), SigningKeyAlgorithm::Ed25519);
assert_eq!(server_key_id.version(), "Abc_1"); assert_eq!(server_key_id.version(), "Abc_1");
} }
@ -72,19 +72,23 @@ mod tests {
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
#[test] #[test]
fn serialize_id() { fn serialize_id() {
let server_key_id: SigningKeyId = SigningKeyId::try_from("ed25519:abc123").unwrap(); let server_key_id: ServerSigningKeyId =
ServerSigningKeyId::try_from("ed25519:abc123").unwrap();
assert_eq!(to_json_value(&server_key_id).unwrap(), json!("ed25519:abc123")); assert_eq!(to_json_value(&server_key_id).unwrap(), json!("ed25519:abc123"));
} }
#[test] #[test]
fn invalid_version_characters() { fn invalid_version_characters() {
assert_eq!(SigningKeyId::try_from("ed25519:Abc-1").unwrap_err(), Error::InvalidCharacters); assert_eq!(
ServerSigningKeyId::try_from("ed25519:Abc-1").unwrap_err(),
Error::InvalidCharacters
);
} }
#[test] #[test]
fn invalid_key_algorithm() { fn invalid_key_algorithm() {
assert_eq!( assert_eq!(
SigningKeyId::try_from("signed_curve25519:Abc-1").unwrap_err(), ServerSigningKeyId::try_from("signed_curve25519:Abc-1").unwrap_err(),
Error::UnknownKeyAlgorithm, Error::UnknownKeyAlgorithm,
); );
} }
@ -92,7 +96,7 @@ mod tests {
#[test] #[test]
fn missing_delimiter() { fn missing_delimiter() {
assert_eq!( assert_eq!(
SigningKeyId::try_from("ed25519|Abc_1").unwrap_err(), ServerSigningKeyId::try_from("ed25519|Abc_1").unwrap_err(),
Error::MissingSigningKeyDelimiter, Error::MissingSigningKeyDelimiter,
); );
} }

View File

@ -27,7 +27,7 @@ pub use ruma_serde as serde;
pub use ruma_identifiers::{ pub use ruma_identifiers::{
device_id, device_key_id, event_id, room_alias_id, room_id, room_version_id, server_key_id, 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, server_name, user_id, DeviceId, DeviceKeyAlgorithm, DeviceKeyId, EventId, RoomAliasId, RoomId,
RoomIdOrAliasId, RoomVersionId, ServerName, SigningKeyAlgorithm, SigningKeyId, UserId, RoomIdOrAliasId, RoomVersionId, ServerName, ServerSigningKeyId, SigningKeyAlgorithm, UserId,
}; };
#[cfg(feature = "ruma-events")] #[cfg(feature = "ruma-events")]