matrix_sdk_crypto/types/requests/verification.rs
1// Copyright 2020 The Matrix.org Foundation C.I.C.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use ruma::TransactionId;
16
17use super::{RoomMessageRequest, ToDeviceRequest};
18
19/// An enum over the different outgoing verification based requests.
20#[derive(Clone, Debug)]
21pub enum OutgoingVerificationRequest {
22 /// The to-device verification request variant.
23 ToDevice(ToDeviceRequest),
24 /// The in-room verification request variant.
25 // `Box` the `RoomMessageRequest` to reduce the size of the enum.
26 InRoom(Box<RoomMessageRequest>),
27}
28
29impl OutgoingVerificationRequest {
30 /// Get the unique id of this request.
31 pub fn request_id(&self) -> &TransactionId {
32 match self {
33 OutgoingVerificationRequest::ToDevice(t) => &t.txn_id,
34 OutgoingVerificationRequest::InRoom(r) => &r.txn_id,
35 }
36 }
37}
38
39impl From<ToDeviceRequest> for OutgoingVerificationRequest {
40 fn from(r: ToDeviceRequest) -> Self {
41 OutgoingVerificationRequest::ToDevice(r)
42 }
43}
44
45impl From<RoomMessageRequest> for OutgoingVerificationRequest {
46 fn from(r: RoomMessageRequest) -> Self {
47 OutgoingVerificationRequest::InRoom(Box::new(r))
48 }
49}