aboutsummaryrefslogtreecommitdiff
path: root/lib/events/encryptionevent.cpp
diff options
context:
space:
mode:
authorAlexey Andreyev <aa13q@ya.ru>2019-05-25 03:31:55 +0300
committerAlexey Andreyev <aa13q@ya.ru>2019-07-04 11:21:06 +0300
commitbb98bd26bdd72998e09553e1703d552d1d217f86 (patch)
treeb4fbff3b8fafa11c534841218d2e9abd45d59dc5 /lib/events/encryptionevent.cpp
parentaf623d68df8cec92277e9a40f18beac617b5d397 (diff)
downloadlibquotient-bb98bd26bdd72998e09553e1703d552d1d217f86.tar.gz
libquotient-bb98bd26bdd72998e09553e1703d552d1d217f86.zip
Add full EncryptionEvent to room logic. Issue #95
Diffstat (limited to 'lib/events/encryptionevent.cpp')
-rw-r--r--lib/events/encryptionevent.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/events/encryptionevent.cpp b/lib/events/encryptionevent.cpp
index 7b620bce..b8e2b575 100644
--- a/lib/events/encryptionevent.cpp
+++ b/lib/events/encryptionevent.cpp
@@ -1,5 +1,53 @@
//
// Created by rusakov on 26/09/2017.
+// Contributed by andreev on 27/06/2019.
//
#include "encryptionevent.h"
+
+#include "converters.h"
+#include "logging.h"
+
+#include <array>
+
+static const std::array<QString, 1> encryptionStrings = { {
+ QStringLiteral("m.megolm.v1.aes-sha2")
+} };
+
+namespace QMatrixClient {
+ template <>
+ struct JsonConverter<EncryptionType>
+ {
+ static EncryptionType load(const QJsonValue& jv)
+ {
+ const auto& encryptionString = jv.toString();
+ for (auto it = encryptionStrings.begin();
+ it != encryptionStrings.end(); ++it)
+ if (encryptionString == *it)
+ return EncryptionType(it - encryptionStrings.begin());
+
+ qCWarning(EVENTS) << "Unknown EncryptionType: " << encryptionString;
+ return EncryptionType::Undefined;
+ }
+ };
+}
+
+using namespace QMatrixClient;
+
+EncryptionEventContent::EncryptionEventContent(const QJsonObject& json)
+ : encryption(fromJson<EncryptionType>(json["algorithm"_ls]))
+ , algorithm(sanitized(json["algorithm"_ls].toString()))
+ , rotationPeriodMs(json["rotation_period_ms"_ls].toInt(604800000))
+ , rotationPeriodMsgs(json["rotation_period_msgs"_ls].toInt(100))
+{ }
+
+void EncryptionEventContent::fillJson(QJsonObject* o) const
+{
+ Q_ASSERT(o);
+ Q_ASSERT_X(encryption != EncryptionType::Undefined, __FUNCTION__,
+ "The key 'algorithm' must be explicit in EncryptionEventContent");
+ if (encryption != EncryptionType::Undefined)
+ o->insert(QStringLiteral("algorithm"), algorithm);
+ o->insert(QStringLiteral("rotation_period_ms"), rotationPeriodMs);
+ o->insert(QStringLiteral("rotation_period_msgs"), rotationPeriodMsgs);
+}