From 7f2df68d62f0a2ab2a5099b472709f930cd0b304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 28 Jul 2020 16:24:45 +0200 Subject: [PATCH] crypto: Expose some SAS methods publicly. --- matrix_sdk_crypto/src/machine.rs | 17 ++++++++++++++++- matrix_sdk_crypto/src/verification/machine.rs | 9 ++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 1b490bdc..a5f5d36c 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -28,7 +28,7 @@ use super::store::memorystore::MemoryStore; #[cfg(feature = "sqlite-cryptostore")] use super::store::sqlite::SqliteStore; use super::{device::Device, store::Result as StoreResult, CryptoStore}; -use crate::verification::VerificationMachine; +use crate::verification::{Sas, VerificationMachine}; use matrix_sdk_common::events::{ forwarded_room_key::ForwardedRoomKeyEventContent, room::encrypted::EncryptedEventContent, @@ -1067,6 +1067,21 @@ impl OlmMachine { } } + /// Get the to-device requests that need to be sent out. + pub fn outgoing_to_device_requests(&self) -> Vec { + self.verification_machine.outgoing_to_device_requests() + } + + /// Mark an outgoing to-device requests as sent. + pub fn mark_to_device_request_as_sent(&self, request_id: &str) { + self.verification_machine.mark_requests_as_sent(request_id); + } + + /// Get a `Sas` verification object with the given flow id. + pub fn get_verification(&self, flow_id: &str) -> Option { + self.verification_machine.get_sas(flow_id) + } + /// Handle a sync response and update the internal state of the Olm machine. /// /// This will decrypt to-device events but will not touch events in the room diff --git a/matrix_sdk_crypto/src/verification/machine.rs b/matrix_sdk_crypto/src/verification/machine.rs index 8b03349b..f5439740 100644 --- a/matrix_sdk_crypto/src/verification/machine.rs +++ b/matrix_sdk_crypto/src/verification/machine.rs @@ -49,7 +49,7 @@ impl VerificationMachine { } } - fn get_sas(&self, transaction_id: &str) -> Option { + pub fn get_sas(&self, transaction_id: &str) -> Option { self.verifications.get(transaction_id).map(|s| s.clone()) } @@ -97,6 +97,13 @@ impl VerificationMachine { self.outgoing_to_device_messages.remove(uuid); } + pub fn outgoing_to_device_requests(&self) -> Vec { + self.outgoing_to_device_messages + .iter() + .map(|r| r.clone()) + .collect() + } + pub async fn receive_event( &self, event: &mut AnyToDeviceEvent,