-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1546e8
commit 7fb9f2e
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<QString>(AlgorithmKeyL); | ||
Q_ASSERT(SupportedAlgorithms.contains(algo)); | ||
return algo; | ||
} | ||
|
||
QString EncryptedEvent::ciphertext() const | ||
{ | ||
return content<QString>("ciphertext"_ls); | ||
} | ||
|
||
QString EncryptedEvent::senderKey() const | ||
{ | ||
return content<QString>("sender_key"_ls); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<RoomEvent>& decryptedEvent() const | ||
{ | ||
return _decryptedEvent; | ||
} | ||
|
||
private: | ||
event_ptr_tt<RoomEvent> _decryptedEvent; | ||
}; | ||
REGISTER_EVENT_TYPE(EncryptedEvent) | ||
|
||
} // namespace QMatrixClient |