From 1cf67730a0880a520ae04bdf4ef61592daa9fe06 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 26 Sep 2017 20:57:28 +0900 Subject: Introduce EncryptionEvent class This allows to detect if a room has been encrypted (no room state, just an event as of yet). Closes #84. --- lib/events/encryptionevent.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lib/events/encryptionevent.h (limited to 'lib/events/encryptionevent.h') diff --git a/lib/events/encryptionevent.h b/lib/events/encryptionevent.h new file mode 100644 index 00000000..b44e0eeb --- /dev/null +++ b/lib/events/encryptionevent.h @@ -0,0 +1,43 @@ +/****************************************************************************** + * Copyright (C) 2017 Kitsune Ral + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include "roomevent.h" + +namespace QMatrixClient +{ + class EncryptionEvent : public RoomEvent + { + public: + DEFINE_EVENT_TYPEID("m.room.encryption", EncryptionEvent) + + explicit EncryptionEvent(const QJsonObject& obj) + : RoomEvent(typeId(), obj) + , _algorithm(contentJson()["algorithm"].toString()) + { } + + QString algorithm() const { return _algorithm; } + + private: + QString _algorithm; + }; + REGISTER_EVENT_TYPE(EncryptionEvent) + DEFINE_EVENTTYPE_ALIAS(Encryption, EncryptionEvent) +} // namespace QMatrixClient + -- cgit v1.2.3 From bb98bd26bdd72998e09553e1703d552d1d217f86 Mon Sep 17 00:00:00 2001 From: Alexey Andreyev Date: Sat, 25 May 2019 03:31:55 +0300 Subject: Add full EncryptionEvent to room logic. Issue #95 --- lib/events/encryptionevent.h | 47 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'lib/events/encryptionevent.h') diff --git a/lib/events/encryptionevent.h b/lib/events/encryptionevent.h index b44e0eeb..6a4a1c67 100644 --- a/lib/events/encryptionevent.h +++ b/lib/events/encryptionevent.h @@ -18,25 +18,58 @@ #pragma once -#include "roomevent.h" +#include "stateevent.h" +#include "eventcontent.h" namespace QMatrixClient { - class EncryptionEvent : public RoomEvent + class EncryptionEventContent: public EventContent::Base { + public: + enum EncryptionType : size_t { MegolmV1AesSha2 = 0, + Undefined }; + + explicit EncryptionEventContent(EncryptionType et = Undefined) + : encryption(et) + { } + explicit EncryptionEventContent(const QJsonObject& json); + + EncryptionType encryption; + QString algorithm; + int rotationPeriodMs; + int rotationPeriodMsgs; + + protected: + void fillJson(QJsonObject* o) const override; + }; + + using EncryptionType = EncryptionEventContent::EncryptionType; + + class EncryptionEvent : public StateEvent + { + Q_GADGET public: DEFINE_EVENT_TYPEID("m.room.encryption", EncryptionEvent) - explicit EncryptionEvent(const QJsonObject& obj) - : RoomEvent(typeId(), obj) - , _algorithm(contentJson()["algorithm"].toString()) + using EncryptionType = EncryptionEventContent::EncryptionType; + + explicit EncryptionEvent(const QJsonObject& obj = {}) // TODO: apropriate default value + : StateEvent(typeId(), obj) { } + EncryptionEvent(EncryptionEventContent&& c) + : StateEvent(typeId(), matrixTypeId(), c) + { } + + EncryptionType encryption() const { return content().encryption; } - QString algorithm() const { return _algorithm; } + QString algorithm() const { return content().algorithm; } + int rotationPeriodMs() const { return content().rotationPeriodMs; } + int rotationPeriodMsgs() const { return content().rotationPeriodMsgs; } private: - QString _algorithm; + REGISTER_ENUM(EncryptionType) }; + REGISTER_EVENT_TYPE(EncryptionEvent) DEFINE_EVENTTYPE_ALIAS(Encryption, EncryptionEvent) } // namespace QMatrixClient -- cgit v1.2.3 From 4e521ae29a55deaab2ca9d62cddd3791015c6cfb Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 6 Jul 2019 21:58:41 +0900 Subject: EncryptionEvent: Adjust upon merge from master --- lib/events/encryptionevent.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/events/encryptionevent.h') diff --git a/lib/events/encryptionevent.h b/lib/events/encryptionevent.h index 6a4a1c67..b9e108f0 100644 --- a/lib/events/encryptionevent.h +++ b/lib/events/encryptionevent.h @@ -56,8 +56,10 @@ namespace QMatrixClient explicit EncryptionEvent(const QJsonObject& obj = {}) // TODO: apropriate default value : StateEvent(typeId(), obj) { } - EncryptionEvent(EncryptionEventContent&& c) - : StateEvent(typeId(), matrixTypeId(), c) + template + EncryptionEvent(ArgTs&&... contentArgs) + : StateEvent(typeId(), matrixTypeId(), QString(), + std::forward(contentArgs)...) { } EncryptionType encryption() const { return content().encryption; } -- cgit v1.2.3