Use strong types in signatures fields
This commit is contained in:
		
							parent
							
								
									7240184c1d
								
							
						
					
					
						commit
						7eb945976c
					
				| @ -52,6 +52,8 @@ Breaking changes: | ||||
| * 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: | ||||
| 
 | ||||
|  | ||||
| @ -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.
 | ||||
|  | ||||
| @ -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 | ||||
| 
 | ||||
|  | ||||
| @ -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 { | ||||
|  | ||||
| @ -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" | ||||
|  | ||||
| @ -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})); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user