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 InRoom(RoomMessageRequest),
26}
27
28impl OutgoingVerificationRequest {
29 /// Get the unique id of this request.
30 pub fn request_id(&self) -> &TransactionId {
31 match self {
32 OutgoingVerificationRequest::ToDevice(t) => &t.txn_id,
33 OutgoingVerificationRequest::InRoom(r) => &r.txn_id,
34 }
35 }
36}
37
38impl From<ToDeviceRequest> for OutgoingVerificationRequest {
39 fn from(r: ToDeviceRequest) -> Self {
40 OutgoingVerificationRequest::ToDevice(r)
41 }
42}
43
44impl From<RoomMessageRequest> for OutgoingVerificationRequest {
45 fn from(r: RoomMessageRequest) -> Self {
46 OutgoingVerificationRequest::InRoom(r)
47 }
48}