Fix issues with new key ID / signature types

This commit is contained in:
Jonas Platte 2020-12-02 13:50:58 +01:00
parent 1ceade7b61
commit 62135a9630
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
6 changed files with 31 additions and 45 deletions

View File

@ -84,7 +84,7 @@ pub fn room_version_id(input: TokenStream) -> TokenStream {
#[proc_macro] #[proc_macro]
pub fn server_signing_key_id(input: TokenStream) -> TokenStream { pub fn server_signing_key_id(input: TokenStream) -> TokenStream {
let Input { dollar_crate, id } = parse_macro_input!(input as Input); let Input { dollar_crate, id } = parse_macro_input!(input as Input);
assert!(key_id::validate(&id.value()).is_ok(), "Invalid server_key_id"); assert!(key_id::validate(&id.value()).is_ok(), "Invalid server_signing_key_id");
let output = quote! { let output = quote! {
<#dollar_crate::ServerSigningKeyId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap() <#dollar_crate::ServerSigningKeyId as ::std::convert::TryFrom<&str>>::try_from(#id).unwrap()

View File

@ -38,7 +38,7 @@ impl Display for Error {
let message = match self { let message = match self {
Error::EmptyRoomVersionId => "room version ID is empty", Error::EmptyRoomVersionId => "room version ID is empty",
Error::InvalidCharacters => "localpart contains invalid characters", Error::InvalidCharacters => "localpart contains invalid characters",
Error::InvalidKeyAlgorithm => "unknown key algorithm specified", Error::InvalidKeyAlgorithm => "invalid key algorithm specified",
Error::InvalidKeyVersion => "key ID version contains invalid characters", Error::InvalidKeyVersion => "key ID version contains invalid characters",
Error::InvalidServerName => "server name is not a valid IP address or domain name", Error::InvalidServerName => "server name is not a valid IP address or domain name",
Error::MaximumLengthExceeded => "ID exceeds 255 bytes", Error::MaximumLengthExceeded => "ID exceeds 255 bytes",

View File

@ -8,16 +8,22 @@ pub type EntitySignatures<K> = BTreeMap<SigningKeyId<K>, String>;
/// Map of all signatures, grouped by entity /// Map of all signatures, grouped by entity
/// ///
/// ``` /// ```
/// # use ruma_identifiers::{server_name, KeyId, Signatures, SigningKeyAlgorithm};
/// let key_identifier = KeyId::from_parts(SigningKeyAlgorithm::Ed25519, "1"); /// let key_identifier = KeyId::from_parts(SigningKeyAlgorithm::Ed25519, "1");
/// let mut signatures = Signatures::new(); /// let mut signatures = Signatures::new();
/// let server_name = server_name!("example.org"); /// let server_name = server_name!("example.org");
/// let signature = "YbJva03ihSj5mPk+CHMJKUKlCXCPFXjXOK6VqBnN9nA2evksQcTGn6hwQfrgRHIDDXO2le49x7jnWJHMJrJoBQ"; /// let signature = "YbJva03ihSj5mPk+CHMJKUKlCXCPFXjXOK6VqBnN9nA2evksQcTGn6hwQfrgRHIDDXO2le49x7jnWJHMJrJoBQ";
/// signatures.add(server_name, key_identifier, signature); /// signatures.insert(server_name, key_identifier, signature.into());
/// ``` /// ```
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct Signatures<E: Ord, K>(BTreeMap<E, EntitySignatures<K>>); pub struct Signatures<E: Ord, K: ?Sized>(BTreeMap<E, EntitySignatures<K>>);
impl<E: Ord, K: ?Sized> Signatures<E, K> {
/// Creates an empty signature map.
pub fn new() -> Self {
Self(BTreeMap::new())
}
impl<E: Ord, K: Ord> Signatures<E, K> {
/// Add a signature for the given server name and key identifier. /// Add a signature for the given server name and key identifier.
/// ///
/// If there was already one, it is returned. /// If there was already one, it is returned.

View File

@ -6,7 +6,7 @@ fn main() {
let _ = ruma_identifiers::room_id!("!1234567890:matrix.org"); let _ = ruma_identifiers::room_id!("!1234567890:matrix.org");
let _ = ruma_identifiers::room_version_id!("1"); let _ = ruma_identifiers::room_version_id!("1");
let _ = ruma_identifiers::room_version_id!("1-custom"); let _ = ruma_identifiers::room_version_id!("1-custom");
let _ = ruma_identifiers::server_key_id!("ed25519:Abc_1"); let _ = ruma_identifiers::server_signing_key_id!("ed25519:Abc_1");
let _ = ruma_identifiers::server_name!("myserver.fish"); let _ = ruma_identifiers::server_name!("myserver.fish");
let _ = ruma_identifiers::user_id!("@user:ruma.io"); let _ = ruma_identifiers::user_id!("@user:ruma.io");
} }

View File

@ -1,11 +1,9 @@
fn main() { fn main() {
let _ = ruma_identifiers::device_key_id!("ed2519:JLAFKJWSCS");
let _ = ruma_identifiers::event_id!("39hvsi03hlne:example.com"); let _ = ruma_identifiers::event_id!("39hvsi03hlne:example.com");
let _ = ruma_identifiers::event_id!("acR1l0raoZnm60CBwAVgqbZqoO/mYU81xysh1u7XcJk"); let _ = ruma_identifiers::event_id!("acR1l0raoZnm60CBwAVgqbZqoO/mYU81xysh1u7XcJk");
let _ = ruma_identifiers::room_alias_id!("alias:server.tld"); let _ = ruma_identifiers::room_alias_id!("alias:server.tld");
let _ = ruma_identifiers::room_id!("1234567890:matrix.org"); let _ = ruma_identifiers::room_id!("1234567890:matrix.org");
let _ = ruma_identifiers::room_version_id!(""); let _ = ruma_identifiers::room_version_id!("");
let _ = ruma_identifiers::server_key_id!("ed219:Abc_1");
let _ = ruma_identifiers::server_name!(""); let _ = ruma_identifiers::server_name!("");
let _ = ruma_identifiers::user_id!("user:ruma.io"); let _ = ruma_identifiers::user_id!("user:ruma.io");
} }

View File

@ -1,17 +1,17 @@
error: proc macro panicked error: proc macro panicked
--> $DIR/02-invalid-id-macros.rs:2:13 --> $DIR/02-invalid-id-macros.rs:2:13
| |
2 | let _ = ruma_identifiers::device_key_id!("ed2519:JLAFKJWSCS"); 2 | let _ = ruma_identifiers::event_id!("39hvsi03hlne:example.com");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: message: Invalid device key id = help: message: Invalid event id
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: proc macro panicked error: proc macro panicked
--> $DIR/02-invalid-id-macros.rs:3:13 --> $DIR/02-invalid-id-macros.rs:3:13
| |
3 | let _ = ruma_identifiers::event_id!("39hvsi03hlne:example.com"); 3 | let _ = ruma_identifiers::event_id!("acR1l0raoZnm60CBwAVgqbZqoO/mYU81xysh1u7XcJk");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: message: Invalid event id = help: message: Invalid event id
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
@ -19,61 +19,43 @@ error: proc macro panicked
error: proc macro panicked error: proc macro panicked
--> $DIR/02-invalid-id-macros.rs:4:13 --> $DIR/02-invalid-id-macros.rs:4:13
| |
4 | let _ = ruma_identifiers::event_id!("acR1l0raoZnm60CBwAVgqbZqoO/mYU81xysh1u7XcJk"); 4 | let _ = ruma_identifiers::room_alias_id!("alias:server.tld");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: message: Invalid event id
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: proc macro panicked
--> $DIR/02-invalid-id-macros.rs:5:13
|
5 | let _ = ruma_identifiers::room_alias_id!("alias:server.tld");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: message: Invalid room_alias_id = help: message: Invalid room_alias_id
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: proc macro panicked error: proc macro panicked
--> $DIR/02-invalid-id-macros.rs:6:13 --> $DIR/02-invalid-id-macros.rs:5:13
| |
6 | let _ = ruma_identifiers::room_id!("1234567890:matrix.org"); 5 | let _ = ruma_identifiers::room_id!("1234567890:matrix.org");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: message: Invalid room_id = help: message: Invalid room_id
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: proc macro panicked error: proc macro panicked
--> $DIR/02-invalid-id-macros.rs:7:13 --> $DIR/02-invalid-id-macros.rs:6:13
| |
7 | let _ = ruma_identifiers::room_version_id!(""); 6 | let _ = ruma_identifiers::room_version_id!("");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: message: Invalid room_version_id = help: message: Invalid room_version_id
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: proc macro panicked error: proc macro panicked
--> $DIR/02-invalid-id-macros.rs:8:13 --> $DIR/02-invalid-id-macros.rs:7:13
| |
8 | let _ = ruma_identifiers::server_key_id!("ed219:Abc_1"); 7 | let _ = ruma_identifiers::server_name!("");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: message: Invalid server_key_id
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: proc macro panicked
--> $DIR/02-invalid-id-macros.rs:9:13
|
9 | let _ = ruma_identifiers::server_name!("");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: message: Invalid server_name = help: message: Invalid server_name
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: proc macro panicked error: proc macro panicked
--> $DIR/02-invalid-id-macros.rs:10:13 --> $DIR/02-invalid-id-macros.rs:8:13
| |
10 | let _ = ruma_identifiers::user_id!("user:ruma.io"); 8 | let _ = ruma_identifiers::user_id!("user:ruma.io");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
= help: message: Invalid user_id = help: message: Invalid user_id