ruma_events/key/verification/
request.rs

1//! Types for the [`m.key.verification.request`] event.
2//!
3//! [`m.key.verification.request`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationrequest
4
5use ruma_common::{MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedTransactionId};
6use ruma_macros::EventContent;
7use serde::{Deserialize, Serialize};
8
9use super::VerificationMethod;
10
11/// The content of an `m.key.verification.request` event.
12#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
13#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
14#[ruma_event(type = "m.key.verification.request", kind = ToDevice)]
15pub struct ToDeviceKeyVerificationRequestEventContent {
16    /// The device ID which is initiating the request.
17    pub from_device: OwnedDeviceId,
18
19    /// An opaque identifier for the verification request.
20    ///
21    /// Must be unique with respect to the devices involved.
22    pub transaction_id: OwnedTransactionId,
23
24    /// The verification methods supported by the sender.
25    pub methods: Vec<VerificationMethod>,
26
27    /// The time in milliseconds for when the request was made.
28    ///
29    /// If the request is in the future by more than 5 minutes or more than 10 minutes in
30    /// the past, the message should be ignored by the receiver.
31    pub timestamp: MilliSecondsSinceUnixEpoch,
32}
33
34impl ToDeviceKeyVerificationRequestEventContent {
35    /// Creates a new `ToDeviceKeyVerificationRequestEventContent` with the given device ID,
36    /// transaction ID, methods and timestamp.
37    pub fn new(
38        from_device: OwnedDeviceId,
39        transaction_id: OwnedTransactionId,
40        methods: Vec<VerificationMethod>,
41        timestamp: MilliSecondsSinceUnixEpoch,
42    ) -> Self {
43        Self { from_device, transaction_id, methods, timestamp }
44    }
45}