diff options
author | Carl Schwan <carl@carlschwan.eu> | 2021-01-26 20:13:20 +0100 |
---|---|---|
committer | Tobias Fella <fella@posteo.de> | 2021-12-01 21:34:52 +0100 |
commit | 987d399bc9ce628c376d505e3ebb78ae703d7c68 (patch) | |
tree | 6480f5790dc77d209ae0855b8b9245b390aae899 /lib/olm/qolmsession.cpp | |
parent | dca69e8326ce6fd0374123ad8c167a2b0051d8fb (diff) | |
download | libquotient-987d399bc9ce628c376d505e3ebb78ae703d7c68.tar.gz libquotient-987d399bc9ce628c376d505e3ebb78ae703d7c68.zip |
Improve API
Diffstat (limited to 'lib/olm/qolmsession.cpp')
-rw-r--r-- | lib/olm/qolmsession.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/olm/qolmsession.cpp b/lib/olm/qolmsession.cpp new file mode 100644 index 00000000..32a108a8 --- /dev/null +++ b/lib/olm/qolmsession.cpp @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org> +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "olm/qolmsession.h" + +using namespace Quotient; + +std::optional<OlmMessage> fromTypeAndCipthertext(size_t messageType, const QByteArray &ciphertext) +{ + if (messageType == OLM_MESSAGE_TYPE_PRE_KEY) { + return PreKeyMessage { ciphertext }; + } else if (messageType == OLM_MESSAGE_TYPE_MESSAGE) { + return Message { ciphertext }; + } + return std::nullopt; +} + +std::pair<OlmMessageType, QByteArray> toPair(const OlmMessage &message) +{ + return std::visit([](auto &arg) { + using T = std::decay_t<decltype(arg)>; + if constexpr (std::is_same_v<T, Message>) { + return std::make_pair<OlmMessageType, QByteArray>(MessageType, QByteArray(arg.message)); + } else if constexpr (std::is_same_v<T, PreKeyMessage>) { + return std::make_pair<OlmMessageType, QByteArray>(PreKeyType, QByteArray(arg.message)); + } + }, message); +} |