aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/connection.cpp12
-rw-r--r--lib/database.cpp10
-rw-r--r--lib/e2ee/qolmoutboundsession.cpp2
-rw-r--r--lib/e2ee/qolmoutboundsession.h2
-rw-r--r--lib/room.cpp16
5 files changed, 21 insertions, 21 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 82046d53..a5615f64 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -2251,8 +2251,8 @@ QPair<QOlmMessage::Type, QByteArray> Connection::olmEncryptMessage(User* user, c
QOlmMessage::Type type = d->olmSessions[curveKey][0]->encryptMessageType();
auto result = d->olmSessions[curveKey][0]->encrypt(message);
auto pickle = d->olmSessions[curveKey][0]->pickle(picklingMode());
- if (std::holds_alternative<QByteArray>(pickle)) {
- database()->updateOlmSession(curveKey, d->olmSessions[curveKey][0]->sessionId(), std::get<QByteArray>(pickle));
+ if (pickle) {
+ database()->updateOlmSession(curveKey, d->olmSessions[curveKey][0]->sessionId(), *pickle);
} else {
qCWarning(E2EE) << "Failed to pickle olm session.";
}
@@ -2262,12 +2262,12 @@ QPair<QOlmMessage::Type, QByteArray> Connection::olmEncryptMessage(User* user, c
void Connection::createOlmSession(const QString& theirIdentityKey, const QString& theirOneTimeKey)
{
auto session = QOlmSession::createOutboundSession(olmAccount(), theirIdentityKey, theirOneTimeKey);
- if (std::holds_alternative<QOlmError>(session)) {
- qCWarning(E2EE) << "Failed to create olm session for " << theirIdentityKey << std::get<QOlmError>(session);
+ if (!session) {
+ qCWarning(E2EE) << "Failed to create olm session for " << theirIdentityKey << session.error();
return;
}
- d->saveSession(std::get<std::unique_ptr<QOlmSession>>(session), theirIdentityKey);
- d->olmSessions[theirIdentityKey].push_back(std::move(std::get<std::unique_ptr<QOlmSession>>(session)));
+ d->saveSession(**session, theirIdentityKey);
+ d->olmSessions[theirIdentityKey].push_back(std::move(*session));
}
QOlmOutboundGroupSessionPtr Connection::loadCurrentOutboundMegolmSession(Room* room)
diff --git a/lib/database.cpp b/lib/database.cpp
index d2d33006..87275e1f 100644
--- a/lib/database.cpp
+++ b/lib/database.cpp
@@ -132,7 +132,7 @@ void Database::migrateTo3()
commit();
}
-void Database::migrateTo3()
+void Database::migrateTo4()
{
qCDebug(DATABASE) << "Migrating database to version 4";
transaction();
@@ -313,7 +313,7 @@ void Database::setOlmSessionLastReceived(const QString& sessionId, const QDateTi
void Database::saveCurrentOutboundMegolmSession(const QString& roomId, const PicklingMode& picklingMode, const QOlmOutboundGroupSessionPtr& session)
{
const auto pickle = session->pickle(picklingMode);
- if (std::holds_alternative<QByteArray>(pickle)) {
+ if (pickle) {
auto deleteQuery = prepareQuery(QStringLiteral("DELETE FROM outbound_megolm_sessions WHERE roomId=:roomId AND sessionId=:sessionId;"));
deleteQuery.bindValue(":roomId", roomId);
deleteQuery.bindValue(":sessionId", session->sessionId());
@@ -321,7 +321,7 @@ void Database::saveCurrentOutboundMegolmSession(const QString& roomId, const Pic
auto insertQuery = prepareQuery(QStringLiteral("INSERT INTO outbound_megolm_sessions(roomId, sessionId, pickle, creationTime, messageCount) VALUES(:roomId, :sessionId, :pickle, :creationTime, :messageCount);"));
insertQuery.bindValue(":roomId", roomId);
insertQuery.bindValue(":sessionId", session->sessionId());
- insertQuery.bindValue(":pickle", std::get<QByteArray>(pickle));
+ insertQuery.bindValue(":pickle", pickle.value());
insertQuery.bindValue(":creationTime", session->creationTime());
insertQuery.bindValue(":messageCount", session->messageCount());
@@ -339,8 +339,8 @@ QOlmOutboundGroupSessionPtr Database::loadCurrentOutboundMegolmSession(const QSt
execute(query);
if (query.next()) {
auto sessionResult = QOlmOutboundGroupSession::unpickle(query.value("pickle").toByteArray(), picklingMode);
- if (std::holds_alternative<QOlmOutboundGroupSessionPtr>(sessionResult)) {
- auto session = std::move(std::get<QOlmOutboundGroupSessionPtr>(sessionResult));
+ if (sessionResult) {
+ auto session = std::move(*sessionResult);
session->setCreationTime(query.value("creationTime").toDateTime());
session->setMessageCount(query.value("messageCount").toInt());
return session;
diff --git a/lib/e2ee/qolmoutboundsession.cpp b/lib/e2ee/qolmoutboundsession.cpp
index 10b0c4de..76188d08 100644
--- a/lib/e2ee/qolmoutboundsession.cpp
+++ b/lib/e2ee/qolmoutboundsession.cpp
@@ -60,7 +60,7 @@ QOlmExpected<QByteArray> QOlmOutboundGroupSession::pickle(const PicklingMode &mo
return pickledBuf;
}
-QOlmExpected<QOlmOutboundGroupSessionPtr> QOlmOutboundGroupSession::unpickle(QByteArray &pickled, const PicklingMode &mode)
+QOlmExpected<QOlmOutboundGroupSessionPtr> QOlmOutboundGroupSession::unpickle(const QByteArray &pickled, const PicklingMode &mode)
{
QByteArray pickledBuf = pickled;
auto *olmOutboundGroupSession = olm_outbound_group_session(new uint8_t[olm_outbound_group_session_size()]);
diff --git a/lib/e2ee/qolmoutboundsession.h b/lib/e2ee/qolmoutboundsession.h
index 56b25974..c20613d3 100644
--- a/lib/e2ee/qolmoutboundsession.h
+++ b/lib/e2ee/qolmoutboundsession.h
@@ -25,7 +25,7 @@ public:
//! Deserialises from encrypted Base64 that was previously obtained by
//! pickling a `QOlmOutboundGroupSession`.
static QOlmExpected<QOlmOutboundGroupSessionPtr> unpickle(
- QByteArray& pickled, const PicklingMode& mode);
+ const QByteArray& pickled, const PicklingMode& mode);
//! Encrypts a plaintext message using the session.
QOlmExpected<QByteArray> encrypt(const QString& plaintext);
diff --git a/lib/room.cpp b/lib/room.cpp
index 35de59ed..d77bf9ef 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -448,11 +448,11 @@ public:
connection->saveCurrentOutboundMegolmSession(q, currentOutboundMegolmSession);
const auto sessionKey = currentOutboundMegolmSession->sessionKey();
- if(std::holds_alternative<QOlmError>(sessionKey)) {
+ if(!sessionKey) {
qCWarning(E2EE) << "Failed to load key for new megolm session";
return;
}
- addInboundGroupSession(currentOutboundMegolmSession->sessionId(), std::get<QByteArray>(sessionKey), q->localUser()->id(), "SELF"_ls);
+ addInboundGroupSession(currentOutboundMegolmSession->sessionId(), *sessionKey, q->localUser()->id(), "SELF"_ls);
}
std::unique_ptr<EncryptedEvent> payloadForUserDevice(User* user, const QString& device, const QByteArray& sessionId, const QByteArray& sessionKey)
@@ -526,7 +526,7 @@ public:
signedData.remove("unsigned");
signedData.remove("signatures");
auto signatureMatch = QOlmUtility().ed25519Verify(connection->edKeyForUserDevice(user->id(), device).toLatin1(), QJsonDocument(signedData).toJson(QJsonDocument::Compact), signature);
- if (std::holds_alternative<QOlmError>(signatureMatch)) {
+ if (!signatureMatch) {
qCWarning(E2EE) << "Failed to verify one-time-key signature for" << user->id() << device << ". Skipping this device.";
continue;
} else {
@@ -547,11 +547,11 @@ public:
// Save the session to this device
const auto sessionId = currentOutboundMegolmSession->sessionId();
const auto _sessionKey = currentOutboundMegolmSession->sessionKey();
- if(std::holds_alternative<QOlmError>(_sessionKey)) {
+ if(!_sessionKey) {
qCWarning(E2EE) << "Error loading session key";
return;
}
- const auto sessionKey = std::get<QByteArray>(_sessionKey);
+ const auto sessionKey = *_sessionKey;
const auto senderKey = q->connection()->olmAccount()->identityKeys().curve25519;
// Send the session to other people
@@ -2101,11 +2101,11 @@ QString Room::Private::doSendEvent(const RoomEvent* pEvent)
const auto encrypted = currentOutboundMegolmSession->encrypt(QJsonDocument(pEvent->fullJson()).toJson());
currentOutboundMegolmSession->setMessageCount(currentOutboundMegolmSession->messageCount() + 1);
connection->saveCurrentOutboundMegolmSession(q, currentOutboundMegolmSession);
- if(std::holds_alternative<QOlmError>(encrypted)) {
- qWarning(E2EE) << "Error encrypting message" << std::get<QOlmError>(encrypted);
+ if(!encrypted) {
+ qWarning(E2EE) << "Error encrypting message" << encrypted.error();
return {};
}
- auto encryptedEvent = new EncryptedEvent(std::get<QByteArray>(encrypted), q->connection()->olmAccount()->identityKeys().curve25519, q->connection()->deviceId(), currentOutboundMegolmSession->sessionId());
+ auto encryptedEvent = new EncryptedEvent(*encrypted, q->connection()->olmAccount()->identityKeys().curve25519, q->connection()->deviceId(), currentOutboundMegolmSession->sessionId());
encryptedEvent->setTransactionId(connection->generateTxnId());
encryptedEvent->setRoomId(id);
encryptedEvent->setSender(connection->userId());