events: Make remaining types in key::* non-exhaustive
This commit is contained in:
parent
62b68966b7
commit
0d039a4ebb
@ -21,12 +21,12 @@ pub type AcceptEvent = MessageEvent<AcceptEventContent>;
|
|||||||
|
|
||||||
/// The payload for a to-device `AcceptEvent`.
|
/// The payload for a to-device `AcceptEvent`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.accept", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.accept", kind = ToDevice)]
|
||||||
pub struct AcceptToDeviceEventContent {
|
pub struct AcceptToDeviceEventContent {
|
||||||
/// An opaque identifier for the verification process.
|
/// An opaque identifier for the verification process.
|
||||||
///
|
///
|
||||||
/// Must be the same as the one used for the *m.key.verification.start*
|
/// Must be the same as the one used for the *m.key.verification.start* message.
|
||||||
/// message.
|
|
||||||
pub transaction_id: String,
|
pub transaction_id: String,
|
||||||
|
|
||||||
/// The method specific content.
|
/// The method specific content.
|
||||||
@ -34,11 +34,20 @@ pub struct AcceptToDeviceEventContent {
|
|||||||
pub method: AcceptMethod,
|
pub method: AcceptMethod,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AcceptToDeviceEventContent {
|
||||||
|
/// Creates a new `AcceptToDeviceEventContent` with the given transaction ID and method-specific
|
||||||
|
/// content.
|
||||||
|
pub fn new(transaction_id: String, method: AcceptMethod) -> Self {
|
||||||
|
Self { transaction_id, method }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The payload for a in-room `AcceptEvent`.
|
/// The payload for a in-room `AcceptEvent`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[ruma_event(type = "m.key.verification.accept", kind = Message)]
|
#[ruma_event(type = "m.key.verification.accept", kind = Message)]
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct AcceptEventContent {
|
pub struct AcceptEventContent {
|
||||||
/// The method specific content.
|
/// The method specific content.
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
@ -49,6 +58,15 @@ pub struct AcceptEventContent {
|
|||||||
pub relation: Relation,
|
pub relation: Relation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
impl AcceptEventContent {
|
||||||
|
/// Creates a new `AcceptToDeviceEventContent` with the given method-specific content and
|
||||||
|
/// relation.
|
||||||
|
pub fn new(method: AcceptMethod, relation: Relation) -> Self {
|
||||||
|
Self { method, relation }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An enum representing the different method specific
|
/// An enum representing the different method specific
|
||||||
/// *m.key.verification.accept* content.
|
/// *m.key.verification.accept* content.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
@ -16,6 +16,7 @@ pub type CancelEvent = MessageEvent<CancelEventContent>;
|
|||||||
|
|
||||||
/// The payload for a to-device `CancelEvent`.
|
/// The payload for a to-device `CancelEvent`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.cancel", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.cancel", kind = ToDevice)]
|
||||||
pub struct CancelToDeviceEventContent {
|
pub struct CancelToDeviceEventContent {
|
||||||
/// The opaque identifier for the verification process/request.
|
/// The opaque identifier for the verification process/request.
|
||||||
@ -30,11 +31,19 @@ pub struct CancelToDeviceEventContent {
|
|||||||
pub code: CancelCode,
|
pub code: CancelCode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl CancelToDeviceEventContent {
|
||||||
|
/// Creates a new `CancelToDeviceEventContent` with the given transaction ID, reason and code.
|
||||||
|
pub fn new(transaction_id: String, reason: String, code: CancelCode) -> Self {
|
||||||
|
Self { transaction_id, reason, code }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The payload for an in-room `CancelEvent`.
|
/// The payload for an in-room `CancelEvent`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[ruma_event(type = "m.key.verification.cancel", kind = Message)]
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
#[ruma_event(type = "m.key.verification.cancel", kind = Message)]
|
||||||
pub struct CancelEventContent {
|
pub struct CancelEventContent {
|
||||||
/// A human readable description of the `code`.
|
/// A human readable description of the `code`.
|
||||||
///
|
///
|
||||||
@ -49,6 +58,14 @@ pub struct CancelEventContent {
|
|||||||
pub relation: Relation,
|
pub relation: Relation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
impl CancelEventContent {
|
||||||
|
/// Creates a new `CancelEventContent` with the given reason, code and relation.
|
||||||
|
pub fn new(reason: String, code: CancelCode, relation: Relation) -> Self {
|
||||||
|
Self { reason, code, relation }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An error code for why the process/request was cancelled by the user.
|
/// An error code for why the process/request was cancelled by the user.
|
||||||
///
|
///
|
||||||
/// Custom error codes should use the Java package naming convention.
|
/// Custom error codes should use the Java package naming convention.
|
||||||
|
@ -12,6 +12,7 @@ pub type DoneEvent = MessageEvent<DoneEventContent>;
|
|||||||
|
|
||||||
/// The payload for a to-device `m.key.verification.done` event.
|
/// The payload for a to-device `m.key.verification.done` event.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.done", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.done", kind = ToDevice)]
|
||||||
pub struct DoneToDeviceEventContent {
|
pub struct DoneToDeviceEventContent {
|
||||||
/// An opaque identifier for the verification process.
|
/// An opaque identifier for the verification process.
|
||||||
@ -20,16 +21,30 @@ pub struct DoneToDeviceEventContent {
|
|||||||
pub transaction_id: String,
|
pub transaction_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DoneToDeviceEventContent {
|
||||||
|
/// Creates a new `DoneToDeviceEventContent` with the given transaction ID.
|
||||||
|
pub fn new(transaction_id: String) -> Self {
|
||||||
|
Self { transaction_id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The payload for a in-room `m.key.verification.done` event.
|
/// The payload for a in-room `m.key.verification.done` event.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.done", kind = Message)]
|
#[ruma_event(type = "m.key.verification.done", kind = Message)]
|
||||||
pub struct DoneEventContent {
|
pub struct DoneEventContent {
|
||||||
/// Relation signaling which verification request this event is responding
|
/// Relation signaling which verification request this event is responding to.
|
||||||
/// to.
|
|
||||||
#[serde(rename = "m.relates_to")]
|
#[serde(rename = "m.relates_to")]
|
||||||
pub relation: Relation,
|
pub relation: Relation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DoneEventContent {
|
||||||
|
/// Creates a new `DoneEventContent` with the given relation:
|
||||||
|
pub fn new(relation: Relation) -> Self {
|
||||||
|
Self { relation }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
|
@ -26,11 +26,19 @@ pub struct KeyToDeviceEventContent {
|
|||||||
pub key: String,
|
pub key: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl KeyToDeviceEventContent {
|
||||||
|
/// Creates a new `KeyToDeviceEventContent` with the given transaction ID and key.
|
||||||
|
pub fn new(transaction_id: String, key: String) -> Self {
|
||||||
|
Self { transaction_id, key }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The payload for in-room `KeyEvent`.
|
/// The payload for in-room `KeyEvent`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[ruma_event(type = "m.key.verification.key", kind = Message)]
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
#[ruma_event(type = "m.key.verification.key", kind = Message)]
|
||||||
pub struct KeyEventContent {
|
pub struct KeyEventContent {
|
||||||
/// The device's ephemeral public key, encoded as unpadded Base64.
|
/// The device's ephemeral public key, encoded as unpadded Base64.
|
||||||
pub key: String,
|
pub key: String,
|
||||||
@ -39,3 +47,11 @@ pub struct KeyEventContent {
|
|||||||
#[serde(rename = "m.relates_to")]
|
#[serde(rename = "m.relates_to")]
|
||||||
pub relation: Relation,
|
pub relation: Relation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
impl KeyEventContent {
|
||||||
|
/// Creates a new `KeyEventContent` with the given key and relation.
|
||||||
|
pub fn new(key: String, relation: Relation) -> Self {
|
||||||
|
Self { key, relation }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -17,6 +17,7 @@ pub type MacEvent = MessageEvent<MacEventContent>;
|
|||||||
|
|
||||||
/// The payload for a to-device `MacEvent`.
|
/// The payload for a to-device `MacEvent`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.mac", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.mac", kind = ToDevice)]
|
||||||
pub struct MacToDeviceEventContent {
|
pub struct MacToDeviceEventContent {
|
||||||
/// An opaque identifier for the verification process.
|
/// An opaque identifier for the verification process.
|
||||||
@ -34,6 +35,14 @@ pub struct MacToDeviceEventContent {
|
|||||||
pub keys: String,
|
pub keys: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl MacToDeviceEventContent {
|
||||||
|
/// Creates a new `MacToDeviceEventContent` with the given transaction ID, key ID to MAC map and
|
||||||
|
/// key MAC.
|
||||||
|
pub fn new(transaction_id: String, mac: BTreeMap<String, String>, keys: String) -> Self {
|
||||||
|
Self { transaction_id, mac, keys }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The payload for an in-room `MacEvent`.
|
/// The payload for an in-room `MacEvent`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[ruma_event(type = "m.key.verification.mac", kind = Message)]
|
#[ruma_event(type = "m.key.verification.mac", kind = Message)]
|
||||||
@ -53,3 +62,11 @@ pub struct MacEventContent {
|
|||||||
#[serde(rename = "m.relates_to")]
|
#[serde(rename = "m.relates_to")]
|
||||||
pub relation: Relation,
|
pub relation: Relation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
impl MacEventContent {
|
||||||
|
/// Creates a new `MacEventContent` with the given key ID to MAC map, key MAC and relation.
|
||||||
|
pub fn new(mac: BTreeMap<String, String>, keys: String, relation: Relation) -> Self {
|
||||||
|
Self { mac, keys, relation }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -12,6 +12,7 @@ pub type ReadyEvent = MessageEvent<ReadyEventContent>;
|
|||||||
|
|
||||||
/// The payload for a to-device `m.key.verification.ready` event.
|
/// The payload for a to-device `m.key.verification.ready` event.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.ready", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.ready", kind = ToDevice)]
|
||||||
pub struct ReadyToDeviceEventContent {
|
pub struct ReadyToDeviceEventContent {
|
||||||
/// The device ID which is initiating the request.
|
/// The device ID which is initiating the request.
|
||||||
@ -28,8 +29,21 @@ pub struct ReadyToDeviceEventContent {
|
|||||||
pub transaction_id: String,
|
pub transaction_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ReadyToDeviceEventContent {
|
||||||
|
/// Creates a new `ReadyToDeviceEventContent` with the given device ID, verification methods and
|
||||||
|
/// transaction ID.
|
||||||
|
pub fn new(
|
||||||
|
from_device: DeviceIdBox,
|
||||||
|
methods: Vec<VerificationMethod>,
|
||||||
|
transaction_id: String,
|
||||||
|
) -> Self {
|
||||||
|
Self { from_device, methods, transaction_id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The payload for an in-room `m.key.verification.ready` event.
|
/// The payload for an in-room `m.key.verification.ready` event.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.ready", kind = Message)]
|
#[ruma_event(type = "m.key.verification.ready", kind = Message)]
|
||||||
pub struct ReadyEventContent {
|
pub struct ReadyEventContent {
|
||||||
/// The device ID which is initiating the request.
|
/// The device ID which is initiating the request.
|
||||||
@ -44,6 +58,17 @@ pub struct ReadyEventContent {
|
|||||||
pub relation: Relation,
|
pub relation: Relation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ReadyEventContent {
|
||||||
|
/// Creates a new `ReadyEventContent` with the given device ID, methods and relation.
|
||||||
|
pub fn new(
|
||||||
|
from_device: DeviceIdBox,
|
||||||
|
methods: Vec<VerificationMethod>,
|
||||||
|
relation: Relation,
|
||||||
|
) -> Self {
|
||||||
|
Self { from_device, methods, relation }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use matches::assert_matches;
|
use matches::assert_matches;
|
||||||
|
@ -9,6 +9,7 @@ use super::VerificationMethod;
|
|||||||
|
|
||||||
/// The payload for `RequestEvent`.
|
/// The payload for `RequestEvent`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.request", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.request", kind = ToDevice)]
|
||||||
pub struct RequestToDeviceEventContent {
|
pub struct RequestToDeviceEventContent {
|
||||||
/// The device ID which is initiating the request.
|
/// The device ID which is initiating the request.
|
||||||
@ -28,3 +29,16 @@ pub struct RequestToDeviceEventContent {
|
|||||||
/// the past, the message should be ignored by the receiver.
|
/// the past, the message should be ignored by the receiver.
|
||||||
pub timestamp: MilliSecondsSinceUnixEpoch,
|
pub timestamp: MilliSecondsSinceUnixEpoch,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RequestToDeviceEventContent {
|
||||||
|
/// Creates a new `RequestToDeviceEventContent` with the given device ID, transaction ID,
|
||||||
|
/// methods and timestamp.
|
||||||
|
pub fn new(
|
||||||
|
from_device: DeviceIdBox,
|
||||||
|
transaction_id: String,
|
||||||
|
methods: Vec<VerificationMethod>,
|
||||||
|
timestamp: MilliSecondsSinceUnixEpoch,
|
||||||
|
) -> Self {
|
||||||
|
Self { from_device, transaction_id, methods, timestamp }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -23,6 +23,7 @@ pub type StartEvent = MessageEvent<StartEventContent>;
|
|||||||
|
|
||||||
/// The payload of a to-device *m.key.verification.start* event.
|
/// The payload of a to-device *m.key.verification.start* event.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[ruma_event(type = "m.key.verification.start", kind = ToDevice)]
|
#[ruma_event(type = "m.key.verification.start", kind = ToDevice)]
|
||||||
pub struct StartToDeviceEventContent {
|
pub struct StartToDeviceEventContent {
|
||||||
/// The device ID which is initiating the process.
|
/// The device ID which is initiating the process.
|
||||||
@ -40,11 +41,20 @@ pub struct StartToDeviceEventContent {
|
|||||||
pub method: StartMethod,
|
pub method: StartMethod,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl StartToDeviceEventContent {
|
||||||
|
/// Creates a new `StartToDeviceEventContent` with the given device ID, transaction ID and
|
||||||
|
/// method specific content.
|
||||||
|
pub fn new(from_device: DeviceIdBox, transaction_id: String, method: StartMethod) -> Self {
|
||||||
|
Self { from_device, transaction_id, method }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The payload of an in-room *m.key.verification.start* event.
|
/// The payload of an in-room *m.key.verification.start* event.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
|
||||||
#[ruma_event(type = "m.key.verification.start", kind = Message)]
|
|
||||||
#[cfg(feature = "unstable-pre-spec")]
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "unstable-pre-spec")))]
|
||||||
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
|
#[ruma_event(type = "m.key.verification.start", kind = Message)]
|
||||||
pub struct StartEventContent {
|
pub struct StartEventContent {
|
||||||
/// The device ID which is initiating the process.
|
/// The device ID which is initiating the process.
|
||||||
pub from_device: DeviceIdBox,
|
pub from_device: DeviceIdBox,
|
||||||
@ -58,6 +68,14 @@ pub struct StartEventContent {
|
|||||||
pub relation: Relation,
|
pub relation: Relation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "unstable-pre-spec")]
|
||||||
|
impl StartEventContent {
|
||||||
|
/// Creates a new `StartEventContent` with the given device ID, method and relation.
|
||||||
|
pub fn new(from_device: DeviceIdBox, method: StartMethod, relation: Relation) -> Self {
|
||||||
|
Self { from_device, method, relation }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An enum representing the different method specific
|
/// An enum representing the different method specific
|
||||||
/// *m.key.verification.start* content.
|
/// *m.key.verification.start* content.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user