aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTobias Fella <fella@posteo.de>2021-11-27 00:52:24 +0100
committerTobias Fella <fella@posteo.de>2021-12-01 21:56:59 +0100
commit8020505eb582479cf62d0157fe866f63a888f1a9 (patch)
treeec09f922b9b8f00488e3048674d7b29f72fb9b80 /lib
parente99802772ebab9802e2f35d83ce1de9f83691d90 (diff)
downloadlibquotient-8020505eb582479cf62d0157fe866f63a888f1a9.tar.gz
libquotient-8020505eb582479cf62d0157fe866f63a888f1a9.zip
Apply more suggestions
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.h2
-rw-r--r--lib/encryptionmanager.cpp5
-rw-r--r--lib/networkaccessmanager.cpp6
-rw-r--r--lib/room.cpp21
4 files changed, 8 insertions, 26 deletions
diff --git a/lib/connection.h b/lib/connection.h
index 824c7fb4..d2347d1d 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -573,7 +573,7 @@ public Q_SLOTS:
const QString& localFilename = {});
#ifdef Quotient_E2EE_ENABLED
- DownloadFileJob* downloadFile(const QUrl& url, const EncryptedFile file,
+ DownloadFileJob* downloadFile(const QUrl& url, const EncryptedFile& file,
const QString& localFilename = {});
#endif
/**
diff --git a/lib/encryptionmanager.cpp b/lib/encryptionmanager.cpp
index c816eda7..84282dbf 100644
--- a/lib/encryptionmanager.cpp
+++ b/lib/encryptionmanager.cpp
@@ -107,12 +107,7 @@ public:
rootObj.insert(QStringLiteral("sessions"), sessionsJson);
}
- #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
const auto data = QJsonDocument(rootObj).toJson(QJsonDocument::Compact);
- #else
- QJsonDocument json { rootObj };
- const auto data = json.toJson(QJsonDocument::Compact);
- #endif
outFile.write(data.data(), data.size());
qCDebug(E2EE) << "Sessions saved to" << outFile.fileName();
diff --git a/lib/networkaccessmanager.cpp b/lib/networkaccessmanager.cpp
index c660cff8..d0380cec 100644
--- a/lib/networkaccessmanager.cpp
+++ b/lib/networkaccessmanager.cpp
@@ -12,12 +12,6 @@
#include <QtCore/QThreadStorage>
#include <QtCore/QSettings>
#include <QtNetwork/QNetworkReply>
-#include "accountregistry.h"
-#include "mxcreply.h"
-#include "connection.h"
-#include "events/eventcontent.h"
-
-#include "room.h"
using namespace Quotient;
diff --git a/lib/room.cpp b/lib/room.cpp
index fca1912f..e143747b 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -430,12 +430,7 @@ public:
rootObj.insert(QStringLiteral("sessions"), sessionsJson);
}
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
const auto data = QJsonDocument(rootObj).toJson(QJsonDocument::Compact);
-#else
- QJsonDocument json { rootObj };
- const auto data = json.toJson(QJsonDocument::Compact);
-#endif
outFile.write(data.data(), data.size());
qCDebug(E2EE) << "Megolm sessions saved to" << outFile.fileName();
@@ -476,26 +471,26 @@ public:
"this message";
return QString();
}
- auto& senderSession = *groupSessionIt;
+ auto& senderSession = groupSessionIt->second;
auto decryptResult = senderSession->decrypt(cipher);
if(std::holds_alternative<QOlmError>(decryptResult)) {
qCWarning(E2EE) << "Unable to decrypt event" << eventId
<< "with matching megolm session:" << std::get<QOlmError>(decryptResult);
return QString();
}
- std::pair<QString, uint32_t> decrypted = std::get<std::pair<QString, uint32_t>>(decryptResult);
- QPair<QString, QDateTime> properties = groupSessionIndexRecord.value(qMakePair(senderSession->sessionId(), decrypted.second));
- if (properties.first.isEmpty()) {
- groupSessionIndexRecord.insert(qMakePair(senderSession->sessionId(), decrypted.second), qMakePair(eventId, timestamp));
+ const auto& [content, index] = std::get<std::pair<QString, uint32_t>>(decryptResult);
+ const auto& [recordEventId, ts] = groupSessionIndexRecord.value({senderSession->sessionId(), index});
+ if (eventId.isEmpty()) {
+ groupSessionIndexRecord.insert({senderSession->sessionId(), index}, {recordEventId, timestamp});
} else {
- if ((properties.first != eventId) || (properties.second != timestamp)) {
+ if ((eventId != recordEventId) || (ts != timestamp)) {
qCWarning(E2EE) << "Detected a replay attack on event" << eventId;
return QString();
}
}
//TODO is this necessary?
saveMegOlmSessions();
- return decrypted.first;
+ return content;
}
#endif // Quotient_E2EE_ENABLED
@@ -2673,7 +2668,6 @@ Room::Changes Room::Private::addNewMessageEvents(RoomEvents&& events)
QElapsedTimer et;
et.start();
- //TODO should this be done before dropDuplicateEvents?
for(long unsigned int i = 0; i < events.size(); i++) {
if(auto* encrypted = eventCast<EncryptedEvent>(events[i])) {
auto decrypted = q->decryptMessage(*encrypted);
@@ -2836,7 +2830,6 @@ void Room::Private::addHistoricalMessageEvents(RoomEvents&& events)
Changes changes {};
- //TODO should this be done before dropDuplicateEvents?
for(long unsigned int i = 0; i < events.size(); i++) {
if(auto* encrypted = eventCast<EncryptedEvent>(events[i])) {
qDebug() << "Encrypted Event";