From 12fff7408ea7539d778a641bbf1746693d30ee2a Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 27 Oct 2020 17:45:28 +0100 Subject: Optimize build --- src/Olm.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/Olm.cpp') diff --git a/src/Olm.cpp b/src/Olm.cpp index 6e68bd42..af8bb512 100644 --- a/src/Olm.cpp +++ b/src/Olm.cpp @@ -1,6 +1,7 @@ #include "Olm.h" #include +#include #include #include "Cache.h" @@ -20,6 +21,21 @@ auto client_ = std::make_unique(); } namespace olm { +void +from_json(const nlohmann::json &obj, OlmMessage &msg) +{ + if (obj.at("type") != "m.room.encrypted") + throw std::invalid_argument("invalid type for olm message"); + + if (obj.at("content").at("algorithm") != OLM_ALGO) + throw std::invalid_argument("invalid algorithm for olm message"); + + msg.sender = obj.at("sender"); + msg.sender_key = obj.at("content").at("sender_key"); + msg.ciphertext = obj.at("content") + .at("ciphertext") + .get>(); +} mtx::crypto::OlmClient * client() @@ -419,8 +435,8 @@ send_key_request_for(mtx::events::EncryptedEvent e, e.content.session_id); mtx::events::msg::KeyRequest request; - request.action = !cancel ? mtx::events::msg::RequestAction::Request - : mtx::events::msg::RequestAction::Cancellation; + request.action = !cancel ? mtx::events::msg::RequestAction::Request + : mtx::events::msg::RequestAction::Cancellation; request.algorithm = MEGOLM_ALGO; request.room_id = e.room_id; request.sender_key = e.content.sender_key; -- cgit 1.5.1