1 /****************************************************************************** 2 * Copyright (C) 2017 Kitsune Ral <kitsune-ral@users.sf.net> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 #pragma once 20 21 #include "eventcontent.h" 22 #include "stateevent.h" 23 24 namespace Quotient { 25 class EncryptionEventContent : public EventContent::Base { 26 public: 27 enum EncryptionType : size_t { MegolmV1AesSha2 = 0, Undefined }; 28 29 explicit EncryptionEventContent(EncryptionType et = Undefined) encryption(et)30 : encryption(et) 31 {} 32 explicit EncryptionEventContent(const QJsonObject& json); 33 34 EncryptionType encryption; 35 QString algorithm; 36 int rotationPeriodMs; 37 int rotationPeriodMsgs; 38 39 protected: 40 void fillJson(QJsonObject* o) const override; 41 }; 42 43 using EncryptionType = EncryptionEventContent::EncryptionType; 44 45 class EncryptionEvent : public StateEvent<EncryptionEventContent> { 46 Q_GADGET 47 public: 48 DEFINE_EVENT_TYPEID("m.room.encryption", EncryptionEvent) 49 50 using EncryptionType = EncryptionEventContent::EncryptionType; 51 52 explicit EncryptionEvent(const QJsonObject& obj = {}) // TODO: apropriate 53 // default value StateEvent(typeId (),obj)54 : StateEvent(typeId(), obj) 55 {} 56 template <typename... ArgTs> EncryptionEvent(ArgTs &&...contentArgs)57 EncryptionEvent(ArgTs&&... contentArgs) 58 : StateEvent(typeId(), matrixTypeId(), QString(), 59 std::forward<ArgTs>(contentArgs)...) 60 {} 61 encryption()62 EncryptionType encryption() const { return content().encryption; } 63 algorithm()64 QString algorithm() const { return content().algorithm; } rotationPeriodMs()65 int rotationPeriodMs() const { return content().rotationPeriodMs; } rotationPeriodMsgs()66 int rotationPeriodMsgs() const { return content().rotationPeriodMsgs; } 67 68 private: 69 Q_ENUM(EncryptionType) 70 }; 71 72 REGISTER_EVENT_TYPE(EncryptionEvent) 73 } // namespace Quotient 74