aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/olm/session.cpp4
-rw-r--r--lib/olm/session.h13
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/olm/session.cpp b/lib/olm/session.cpp
index a05e0786..94f12db6 100644
--- a/lib/olm/session.cpp
+++ b/lib/olm/session.cpp
@@ -108,13 +108,13 @@ std::variant<QByteArray, OlmError> QOlmSession::pickle(const PicklingMode &mode)
return pickledBuf;
}
-std::variant<std::unique_ptr<QOlmSession>, OlmError> QOlmSession::unpickle(QByteArray &pickled, const PicklingMode &mode)
+std::variant<std::unique_ptr<QOlmSession>, OlmError> QOlmSession::unpickle(const QByteArray &pickled, const PicklingMode &mode)
{
QByteArray pickledBuf = pickled;
auto *olmSession = create();
QByteArray key = toKey(mode);
const auto error = olm_unpickle_session(olmSession, key.data(), key.length(),
- pickled.data(), pickled.length());
+ pickledBuf.data(), pickledBuf.length());
if (error == olm_error()) {
return lastError(olmSession);
}
diff --git a/lib/olm/session.h b/lib/olm/session.h
index 3f1622c7..03b3514e 100644
--- a/lib/olm/session.h
+++ b/lib/olm/session.h
@@ -9,6 +9,7 @@
#include "olm/e2ee.h"
#include "olm/message.h"
#include "olm/errors.h"
+#include <QDebug>
#include "olm/qolmaccount.h"
namespace Quotient {
@@ -29,7 +30,7 @@ public:
//! Serialises an `QOlmSession` to encrypted Base64.
std::variant<QByteArray, OlmError> pickle(const PicklingMode &mode);
//! Deserialises from encrypted Base64 that was previously obtained by pickling a `QOlmSession`.
- static std::variant<std::unique_ptr<QOlmSession>, OlmError> unpickle(QByteArray &pickled, const PicklingMode &mode);
+ static std::variant<std::unique_ptr<QOlmSession>, OlmError> unpickle(const QByteArray &pickled, const PicklingMode &mode);
//! Encrypts a plaintext message using the session.
Message encrypt(const QString &plaintext);
@@ -50,6 +51,15 @@ public:
//! Checks if the 'prekey' message is for this in-bound session.
std::variant<bool, OlmError> matchesInboundSession(Message &preKeyMessage);
+ friend bool operator<(const QOlmSession& lhs, const QOlmSession& rhs)
+ {
+ return lhs.sessionId() < rhs.sessionId();
+ }
+
+ friend bool operator<(const std::unique_ptr<QOlmSession> &lhs, const std::unique_ptr<QOlmSession> &rhs) {
+ return *lhs < *rhs;
+ }
+
QOlmSession(OlmSession* session);
private:
//! Helper function for creating new sessions and handling errors.
@@ -58,6 +68,7 @@ private:
OlmSession* m_session;
};
+
//using QOlmSessionPtr = std::unique_ptr<QOlmSession>;
} //namespace Quotient