aboutsummaryrefslogtreecommitdiff
path: root/lib/events
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-08-25 19:58:18 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-08-25 19:59:20 +0200
commit376da43a29f3ebad807da2761e7a0c0b105587ec (patch)
tree363a75478136230343e273831293dce75134b176 /lib/events
parent2e1f179bf75da9705963be9305ab6db34afa4d6d (diff)
downloadlibquotient-376da43a29f3ebad807da2761e7a0c0b105587ec.tar.gz
libquotient-376da43a29f3ebad807da2761e7a0c0b105587ec.zip
More code reorganisation
- Common switchOnType() piece for key verification events is factored out into processIfVerificationEvent() - Bare event JSON removed from KeyVerificationSession into constructors of respective events - Connection::sendToDevice() uses assembleEncryptedContent() introduced in the previous commit - commonSupportedMethods() moved out to .cpp; error/string converters made static
Diffstat (limited to 'lib/events')
-rw-r--r--lib/events/keyverificationevent.h77
1 files changed, 73 insertions, 4 deletions
diff --git a/lib/events/keyverificationevent.h b/lib/events/keyverificationevent.h
index cdbd5d74..f635d07b 100644
--- a/lib/events/keyverificationevent.h
+++ b/lib/events/keyverificationevent.h
@@ -18,6 +18,16 @@ public:
explicit KeyVerificationRequestEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationRequestEvent(const QString& transactionId,
+ const QString& fromDevice,
+ const QStringList& methods,
+ const QDateTime& timestamp)
+ : KeyVerificationRequestEvent(
+ basicJson(TypeId, { { "transaction_id"_ls, transactionId },
+ { "from_device"_ls, fromDevice },
+ { "methods"_ls, toJson(methods) },
+ { "timestamp"_ls, toJson(timestamp) } }))
+ {}
/// The device ID which is initiating the request.
QUO_CONTENT_GETTER(QString, fromDevice)
@@ -44,6 +54,14 @@ public:
explicit KeyVerificationReadyEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationReadyEvent(const QString& transactionId,
+ const QString& fromDevice,
+ const QStringList& methods)
+ : KeyVerificationReadyEvent(
+ basicJson(TypeId, { { "transaction_id"_ls, transactionId },
+ { "from_device"_ls, fromDevice },
+ { "methods"_ls, toJson(methods) } }))
+ {}
/// The device ID which is accepting the request.
QUO_CONTENT_GETTER(QString, fromDevice)
@@ -62,9 +80,23 @@ class QUOTIENT_API KeyVerificationStartEvent : public Event {
public:
DEFINE_EVENT_TYPEID("m.key.verification.start", KeyVerificationStartEvent)
- explicit KeyVerificationStartEvent(const QJsonObject &obj)
+ explicit KeyVerificationStartEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationStartEvent(const QString& transactionId,
+ const QString& fromDevice)
+ : KeyVerificationStartEvent(
+ basicJson(TypeId, { { "transaction_id"_ls, transactionId },
+ { "from_device"_ls, fromDevice },
+ { "method"_ls, SasV1Method },
+ { "hashes"_ls, QJsonArray{ "sha256"_ls } },
+ { "key_agreement_protocols"_ls,
+ QJsonArray{ "curve25519-hkdf-sha256"_ls } },
+ { "message_authentication_codes"_ls,
+ QJsonArray{ "hkdf-hmac-sha256"_ls } },
+ { "short_authentication_string"_ls,
+ QJsonArray{ "decimal"_ls, "emoji"_ls } } }))
+ {}
/// The device ID which is initiating the process.
QUO_CONTENT_GETTER(QString, fromDevice)
@@ -125,6 +157,18 @@ public:
explicit KeyVerificationAcceptEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationAcceptEvent(const QString& transactionId,
+ const QString& commitment)
+ : KeyVerificationAcceptEvent(basicJson(
+ TypeId, { { "transaction_id"_ls, transactionId },
+ { "method"_ls, SasV1Method },
+ { "key_agreement_protocol"_ls, "curve25519-hkdf-sha256" },
+ { "hash"_ls, "sha256" },
+ { "message_authentication_code"_ls, "hkdf-hmac-sha256" },
+ { "short_authentication_string"_ls,
+ QJsonArray{ "decimal"_ls, "emoji"_ls, } },
+ { "commitment"_ls, commitment } }))
+ {}
/// An opaque identifier for the verification process.
QUO_CONTENT_GETTER(QString, transactionId)
@@ -161,9 +205,18 @@ class QUOTIENT_API KeyVerificationCancelEvent : public Event {
public:
DEFINE_EVENT_TYPEID("m.key.verification.cancel", KeyVerificationCancelEvent)
- explicit KeyVerificationCancelEvent(const QJsonObject &obj)
+ explicit KeyVerificationCancelEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationCancelEvent(const QString& transactionId,
+ const QString& reason)
+ : KeyVerificationCancelEvent(
+ basicJson(TypeId, {
+ { "transaction_id"_ls, transactionId },
+ { "reason"_ls, reason },
+ { "code"_ls, reason } // Not a typo
+ }))
+ {}
/// An opaque identifier for the verification process.
QUO_CONTENT_GETTER(QString, transactionId)
@@ -183,9 +236,14 @@ class QUOTIENT_API KeyVerificationKeyEvent : public Event {
public:
DEFINE_EVENT_TYPEID("m.key.verification.key", KeyVerificationKeyEvent)
- explicit KeyVerificationKeyEvent(const QJsonObject &obj)
+ explicit KeyVerificationKeyEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationKeyEvent(const QString& transactionId, const QString& key)
+ : KeyVerificationKeyEvent(
+ basicJson(TypeId, { { "transaction_id"_ls, transactionId },
+ { "key"_ls, key } }))
+ {}
/// An opaque identifier for the verification process.
QUO_CONTENT_GETTER(QString, transactionId)
@@ -200,9 +258,16 @@ class QUOTIENT_API KeyVerificationMacEvent : public Event {
public:
DEFINE_EVENT_TYPEID("m.key.verification.mac", KeyVerificationMacEvent)
- explicit KeyVerificationMacEvent(const QJsonObject &obj)
+ explicit KeyVerificationMacEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ KeyVerificationMacEvent(const QString& transactionId, const QString& keys,
+ const QJsonObject& mac)
+ : KeyVerificationMacEvent(
+ basicJson(TypeId, { { "transaction_id"_ls, transactionId },
+ { "keys"_ls, keys },
+ { "mac"_ls, mac } }))
+ {}
/// An opaque identifier for the verification process.
QUO_CONTENT_GETTER(QString, transactionId)
@@ -224,6 +289,10 @@ public:
explicit KeyVerificationDoneEvent(const QJsonObject& obj)
: Event(TypeId, obj)
{}
+ explicit KeyVerificationDoneEvent(const QString& transactionId)
+ : KeyVerificationDoneEvent(
+ basicJson(TypeId, { { "transaction_id"_ls, transactionId } }))
+ {}
/// The same transactionId as before
QUO_CONTENT_GETTER(QString, transactionId)