ruma_events/key/verification/key.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
//! Types for the [`m.key.verification.key`] event.
//!
//! [`m.key.verification.key`]: https://spec.matrix.org/latest/client-server-api/#mkeyverificationkey
use ruma_common::{serde::Base64, OwnedTransactionId};
use ruma_macros::EventContent;
use serde::{Deserialize, Serialize};
use crate::relation::Reference;
/// The content of a to-device `m.key.verification.key` event.
///
/// Sends the ephemeral public key for a device to the partner device.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.key.verification.key", kind = ToDevice)]
pub struct ToDeviceKeyVerificationKeyEventContent {
/// An opaque identifier for the verification process.
///
/// Must be the same as the one used for the `m.key.verification.start` message.
pub transaction_id: OwnedTransactionId,
/// The device's ephemeral public key, encoded as unpadded base64.
pub key: Base64,
}
impl ToDeviceKeyVerificationKeyEventContent {
/// Creates a new `ToDeviceKeyVerificationKeyEventContent` with the given transaction ID and
/// key.
pub fn new(transaction_id: OwnedTransactionId, key: Base64) -> Self {
Self { transaction_id, key }
}
}
/// The content of an in-room `m.key.verification.key` event.
///
/// Sends the ephemeral public key for a device to the partner device.
#[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
#[ruma_event(type = "m.key.verification.key", kind = MessageLike)]
pub struct KeyVerificationKeyEventContent {
/// The device's ephemeral public key, encoded as unpadded base64.
pub key: Base64,
/// Information about the related event.
#[serde(rename = "m.relates_to")]
pub relates_to: Reference,
}
impl KeyVerificationKeyEventContent {
/// Creates a new `KeyVerificationKeyEventContent` with the given key and reference.
pub fn new(key: Base64, relates_to: Reference) -> Self {
Self { key, relates_to }
}
}