aboutsummaryrefslogtreecommitdiff
path: root/lib/events
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-02-15 20:51:32 +0100
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-02-16 17:58:17 +0100
commit53dfa70601b2d27a6be12d52e86af123d0b26b79 (patch)
treea8629e4a229edfeec7c5f32ab72db7d63dc1ed06 /lib/events
parent52a787eefb3fb3d147648d08fc439a4b8a966fd3 (diff)
downloadlibquotient-53dfa70601b2d27a6be12d52e86af123d0b26b79.tar.gz
libquotient-53dfa70601b2d27a6be12d52e86af123d0b26b79.zip
Cleanup
A note on switching to QLatin1String for JSON key constants - this is more concise and barely affects (if at all) runtime performance (padding each QChar with zeros is trivial for assignment; and comparison can be done directly with the same performance as for two QStrings).
Diffstat (limited to 'lib/events')
-rw-r--r--lib/events/encryptedevent.cpp13
-rw-r--r--lib/events/encryptedevent.h14
2 files changed, 17 insertions, 10 deletions
diff --git a/lib/events/encryptedevent.cpp b/lib/events/encryptedevent.cpp
index 1b5e4441..ba4dd154 100644
--- a/lib/events/encryptedevent.cpp
+++ b/lib/events/encryptedevent.cpp
@@ -33,6 +33,19 @@ EncryptedEvent::EncryptedEvent(const QJsonObject& obj)
qCDebug(E2EE) << "Encrypted event from" << senderId();
}
+QString EncryptedEvent::algorithm() const
+{
+ auto algo = contentPart<QString>(AlgorithmKeyL);
+ static constexpr auto SupportedAlgorithms =
+ make_array(OlmV1Curve25519AesSha2AlgoKey, MegolmV1AesSha2AlgoKey);
+ if (std::find(SupportedAlgorithms.cbegin(), SupportedAlgorithms.cend(),
+ algo) == SupportedAlgorithms.cend()) {
+ qWarning(MAIN) << "The EncryptedEvent's algorithm" << algo
+ << "is not supported";
+ }
+ return algo;
+}
+
RoomEventPtr EncryptedEvent::createDecrypted(const QString &decrypted) const
{
auto eventObject = QJsonDocument::fromJson(decrypted.toUtf8()).object();
diff --git a/lib/events/encryptedevent.h b/lib/events/encryptedevent.h
index c838bbd8..72efffd4 100644
--- a/lib/events/encryptedevent.h
+++ b/lib/events/encryptedevent.h
@@ -39,22 +39,16 @@ public:
const QString& deviceId, const QString& sessionId);
explicit EncryptedEvent(const QJsonObject& obj);
- QString algorithm() const
- {
- QString algo = contentPart<QString>(AlgorithmKeyL);
- if (!SupportedAlgorithms.contains(algo)) {
- qWarning(MAIN) << "The EncryptedEvent's algorithm" << algo
- << "is not supported";
- }
- return algo;
- }
+ QString algorithm() const;
QByteArray ciphertext() const
{
return contentPart<QString>(CiphertextKeyL).toLatin1();
}
QJsonObject ciphertext(const QString& identityKey) const
{
- return contentPart<QJsonObject>(CiphertextKeyL).value(identityKey).toObject();
+ return contentPart<QJsonObject>(CiphertextKeyL)
+ .value(identityKey)
+ .toObject();
}
QString senderKey() const { return contentPart<QString>(SenderKeyKeyL); }