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 ruma_common::{thirdparty::Medium, Outgoing};
use ruma_identifiers::{ServerNameBox, SigningKeyId};
use ruma_identifiers::{ServerNameBox, ServerSigningKeyId};
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<ServerNameBox, BTreeMap<SigningKeyId, String>>,
pub signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
}
/// 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 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_json::Value as JsonValue;
@ -86,7 +86,7 @@ pub struct RoomV1Pdu {
pub hashes: EventHash,
/// 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.
@ -143,7 +143,7 @@ pub struct RoomV3Pdu {
pub hashes: EventHash,
/// 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.
@ -220,7 +220,7 @@ pub struct RoomV1PduStub {
pub hashes: EventHash,
/// Signatures for the PDU.
pub signatures: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, String>>,
pub signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
}
impl RoomV1PduStub {
@ -298,7 +298,7 @@ pub struct RoomV3PduStub {
pub hashes: EventHash,
/// Signatures for the PDU.
pub signatures: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, String>>,
pub signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
}
impl RoomV3PduStub {

View File

@ -4,7 +4,7 @@ use std::collections::BTreeMap;
use ruma_common::StringEnum;
use ruma_events_macros::StateEventContent;
use ruma_identifiers::{ServerNameBox, SigningKeyId, UserId};
use ruma_identifiers::{ServerNameBox, ServerSigningKeyId, 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<ServerNameBox, BTreeMap<SigningKeyId, String>>,
pub signatures: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
/// The token property of the containing third_party_invite object.
pub token: String,

View File

@ -2,7 +2,7 @@
use std::{collections::BTreeMap, time::SystemTime};
use ruma_identifiers::{ServerNameBox, SigningKeyId};
use ruma_identifiers::{ServerNameBox, ServerSigningKeyId};
use serde::{Deserialize, Serialize};
pub mod discover_homeserver;
@ -54,14 +54,14 @@ pub struct SigningKey {
pub server_name: ServerNameBox,
/// 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.
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
/// 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
/// versions 1, 2, 3, and 4.

View File

@ -4,7 +4,7 @@ use std::{collections::BTreeMap, time::SystemTime};
use crate::discovery::SigningKey;
use ruma_api::ruma_api;
use ruma_identifiers::{ServerNameBox, SigningKeyId};
use ruma_identifiers::{ServerNameBox, ServerSigningKeyId};
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<ServerNameBox, BTreeMap<SigningKeyId, QueryCriteria>>,
pub server_keys: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, QueryCriteria>>,
/// A millisecond POSIX timestamp in milliseconds indicating when the
/// returned certificates will need to be valid until to be useful to
@ -50,7 +50,7 @@ ruma_api! {
impl Request {
/// Creates a new `Request` with the given query criteria and `minimum_valid_until` timestamp.
pub fn new(
server_keys: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, QueryCriteria>>,
server_keys: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, QueryCriteria>>,
minimum_valid_until_ts: SystemTime,
) -> Self {
Self { server_keys, minimum_valid_until_ts }

View File

@ -2,7 +2,7 @@
use ruma_api::ruma_api;
use ruma_common::thirdparty::Medium;
use ruma_identifiers::{RoomId, ServerNameBox, SigningKeyId, UserId};
use ruma_identifiers::{RoomId, ServerNameBox, ServerSigningKeyId, 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<ServerNameBox, BTreeMap<SigningKeyId, String>>,
pub signed: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
}
impl ThirdPartyInvite {
@ -71,7 +71,7 @@ impl ThirdPartyInvite {
mxid: UserId,
room_id: RoomId,
sender: UserId,
signed: BTreeMap<ServerNameBox, BTreeMap<SigningKeyId, String>>,
signed: BTreeMap<ServerNameBox, BTreeMap<ServerSigningKeyId, String>>,
) -> Self {
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");
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()
@ -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");
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()

View File

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

View File

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

View File

@ -6,13 +6,13 @@ use ruma_identifiers_validation::{crypto_algorithms::SigningKeyAlgorithm, Error}
/// Key identifiers used for homeserver signing keys.
#[derive(Clone, Debug)]
pub struct SigningKeyId {
pub struct ServerSigningKeyId {
full_id: Box<str>,
colon_idx: NonZeroU8,
}
impl SigningKeyId {
/// Create a `SigningKeyId` from a `SigningKeyAlgorithm` and a `ServerId`.
impl ServerSigningKeyId {
/// Create a `ServerSigningKeyId` from a `SigningKeyAlgorithm` and a `ServerId`.
pub fn from_parts(algorithm: SigningKeyAlgorithm, version: &str) -> Self {
let algorithm: &str = algorithm.as_ref();
@ -25,7 +25,7 @@ impl SigningKeyId {
NonZeroU8::new(algorithm.len().try_into().expect("no algorithm name len > 255"))
.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.
@ -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
S: AsRef<str> + Into<Box<str>>,
{
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)]
mod tests {
@ -56,7 +56,7 @@ mod tests {
#[cfg(feature = "serde")]
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")]
use ruma_identifiers_validation::crypto_algorithms::SigningKeyAlgorithm;
@ -64,7 +64,7 @@ mod tests {
#[cfg(feature = "serde")]
#[test]
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.version(), "Abc_1");
}
@ -72,19 +72,23 @@ mod tests {
#[cfg(feature = "serde")]
#[test]
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"));
}
#[test]
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]
fn invalid_key_algorithm() {
assert_eq!(
SigningKeyId::try_from("signed_curve25519:Abc-1").unwrap_err(),
ServerSigningKeyId::try_from("signed_curve25519:Abc-1").unwrap_err(),
Error::UnknownKeyAlgorithm,
);
}
@ -92,7 +96,7 @@ mod tests {
#[test]
fn missing_delimiter() {
assert_eq!(
SigningKeyId::try_from("ed25519|Abc_1").unwrap_err(),
ServerSigningKeyId::try_from("ed25519|Abc_1").unwrap_err(),
Error::MissingSigningKeyDelimiter,
);
}

View File

@ -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, ServerName, SigningKeyAlgorithm, SigningKeyId, UserId,
RoomIdOrAliasId, RoomVersionId, ServerName, ServerSigningKeyId, SigningKeyAlgorithm, UserId,
};
#[cfg(feature = "ruma-events")]