diff --git a/CMakeLists.txt b/CMakeLists.txt index 19fbdcbeb..75314a910 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,6 +138,7 @@ set(libqmatrixclient_SRCS lib/events/callinviteevent.cpp lib/events/directchatevent.cpp lib/events/encryptionevent.cpp + lib/events/encryptedevent.cpp lib/jobs/requestdata.cpp lib/jobs/basejob.cpp lib/jobs/syncjob.cpp diff --git a/lib/events/encryptedevent.cpp b/lib/events/encryptedevent.cpp new file mode 100644 index 000000000..42d45edf9 --- /dev/null +++ b/lib/events/encryptedevent.cpp @@ -0,0 +1,28 @@ +#include "encryptedevent.h" + +using namespace QMatrixClient; + +EncryptedEvent::EncryptedEvent() + : RoomEvent(typeId(), matrixTypeId()) +{ } + +EncryptedEvent::EncryptedEvent(const QJsonObject &obj) + : RoomEvent(typeId(), obj) +{ } + +QString EncryptedEvent::algorithm() const +{ + QString algo = content(AlgorithmKeyL); + Q_ASSERT(SupportedAlgorithms.contains(algo)); + return algo; +} + +QString EncryptedEvent::ciphertext() const +{ + return content("ciphertext"_ls); +} + +QString EncryptedEvent::senderKey() const +{ + return content("sender_key"_ls); +} diff --git a/lib/events/encryptedevent.h b/lib/events/encryptedevent.h new file mode 100644 index 000000000..d722dd708 --- /dev/null +++ b/lib/events/encryptedevent.h @@ -0,0 +1,55 @@ +#pragma once + +#include "roomevent.h" +#include "e2ee.h" + +namespace QMatrixClient +{ + + /* + * While the specification states: + * + * "This event type is used when sending encrypted events. + * It can be used either within a room + * (in which case it will have all of the Room Event fields), + * or as a to-device event." + * "The encrypted payload can contain any message event." + * https://matrix.org/docs/spec/client_server/latest#id493 + * + * -- for most of the cases the message event is the room message event. + * And even for the to-device events the context is for the room. + * + * So, to simplify integration to the timeline, EncryptedEvent is a RoomEvent inheritor. + * Strictly speaking though, it's not always a RoomEvent, but an Event in general. + * It's possible, because RoomEvent interface is similar to Event's one + * and doesn't add new restrictions, just provides additional features. + */ + class EncryptedEvent : public RoomEvent + { + Q_GADGET + public: + DEFINE_EVENT_TYPEID("m.room.encrypted", EncryptedEvent) + // recipient Curve25519 identity key + EncryptedEvent(); + explicit EncryptedEvent(const QJsonObject& obj); + + QString algorithm() const; + QString ciphertext() const; + QString senderKey() const; + + // Required with Megolm: + QString deviceId() const; + QString sessionId() const; + + + const event_ptr_tt& decryptedEvent() const + { + return _decryptedEvent; + } + + private: + event_ptr_tt _decryptedEvent; + }; + REGISTER_EVENT_TYPE(EncryptedEvent) + +} // namespace QMatrixClient