aboutsummaryrefslogtreecommitdiff
path: root/lib/olm
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2021-01-23 15:57:39 +0100
committerTobias Fella <fella@posteo.de>2021-12-01 21:34:52 +0100
commite2075a1f33f7987385fc61338ce1756715fdaf6a (patch)
treea9d500374f15abe309773632ac7db0c69540a943 /lib/olm
parentc794d61b161ad48312bf079f1e5f483cfac1dc38 (diff)
downloadlibquotient-e2075a1f33f7987385fc61338ce1756715fdaf6a.tar.gz
libquotient-e2075a1f33f7987385fc61338ce1756715fdaf6a.zip
Start inboundsession wrapper
Diffstat (limited to 'lib/olm')
-rw-r--r--lib/olm/errors.h46
-rw-r--r--lib/olm/qolminboundsession.cpp30
-rw-r--r--lib/olm/qolminboundsession.h21
3 files changed, 97 insertions, 0 deletions
diff --git a/lib/olm/errors.h b/lib/olm/errors.h
new file mode 100644
index 00000000..e51400ef
--- /dev/null
+++ b/lib/olm/errors.h
@@ -0,0 +1,46 @@
+// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+
+#pragma once
+
+//! All errors that could be caused by an operation regarding an `QOlmAccount`.
+//! Errors are named exactly like the ones in libolm.
+enum OlmAccountError {
+ BadAccountKey,
+ BadMessageKeyId,
+ InvalidBase64,
+ NotEnoughRandom,
+ OutputBufferTooSmall,
+ Unknown,
+};
+
+//! All errors that could be caused by an operation regarding an `QOlmSession`.
+//! Errors are named exactly like the ones in libolm.
+enum OlmSessionError {
+ BadAccountKey,
+ BadMessageFormat,
+ BadMessageKeyId,
+ BadMessageMac,
+ BadMessageVersion,
+ InvalidBase64,
+ NotEnoughRandom,
+ OutputBufferTooSmall,
+ Unknown,
+};
+
+//! All errors that could be caused by an operation
+//! regarding QOlmOutboundGroupSession and QOlmInboundGroupSession.
+//! Errors are named exactly like the ones in libolm.
+enum OlmGroupSessionError {
+ BadAccountKey,
+ BadMessageFormat,
+ BadMessageMac,
+ BadMessageVersion,
+ BadSessionKey,
+ InvalidBase64,
+ NotEnoughRandom,
+ OutputBufferTooSmall,
+ UnknownMessageIndex,
+ Unknown,
+};
diff --git a/lib/olm/qolminboundsession.cpp b/lib/olm/qolminboundsession.cpp
new file mode 100644
index 00000000..fbcaa802
--- /dev/null
+++ b/lib/olm/qolminboundsession.cpp
@@ -0,0 +1,30 @@
+// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+
+#include <qolminboundsession.h>
+
+std::variant<QOlmInboundGroupSession, OlmInboundGroupSession> QOlmInboundGroupSession::create(const QString &key)
+{
+ auto olmInboundGroupSessionBuf = QByteArray(olm_inbound_group_session_size(), '0');
+
+ const auto olmInboundGroupSession = olm_inbound_group_session(olmInboundGroupSessionBuf.data());
+
+ QByteArray keyBuf = key.toUtf8();
+
+ const auto error = olm_init_inbound_group_session(olmInboundGroupSession, keyBuf.data(), keyBuf.size());
+
+ if (error == olm_error()) {
+ return
+ }
+
+ if create_error == errors::olm_error() {
+ Err(Self::last_error(olm_inbound_group_session_ptr))
+ } else {
+ Ok(OlmInboundGroupSession {
+ group_session_ptr: olm_inbound_group_session_ptr,
+ group_session_buf: olm_inbound_group_session_buf,
+ })
+ }
+
+}
diff --git a/lib/olm/qolminboundsession.h b/lib/olm/qolminboundsession.h
new file mode 100644
index 00000000..520f8b68
--- /dev/null
+++ b/lib/olm/qolminboundsession.h
@@ -0,0 +1,21 @@
+// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+
+#pragma once
+
+#include <QByteArray>
+#include <variant>
+
+//! An in-bound group session is responsible for decrypting incoming
+//! communication in a Megolm session.
+struct QOlmInboundGroupSession
+{
+public:
+ //! Creates a new instance of `OlmInboundGroupSession`.
+ static std::variant<OlmInboundGroupSession, OlmGroupSessionError> create(const QString &key);
+private:
+ OlmInboundGroupSession *m_groupSession
+ QByteArray m_buffer;
+};
+