aboutsummaryrefslogtreecommitdiff
path: root/lib/events/keyverificationevent.h
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-09-11 20:25:46 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-09-11 20:25:46 +0200
commit6abdd5358c9c5ed89cda5bc5e50a76af423b0634 (patch)
treefc7d34ad3811b55e0cef2fb025d3ee2a1939ecfe /lib/events/keyverificationevent.h
parentfa34778cc377ab98a0b8f3944063e426c73a3941 (diff)
downloadlibquotient-6abdd5358c9c5ed89cda5bc5e50a76af423b0634.tar.gz
libquotient-6abdd5358c9c5ed89cda5bc5e50a76af423b0634.zip
KeyVerificationEvent; KeyVerificationSession::handleEvent()
Key verification events gain their own base type and KeyVerificationSession gets a single point of entry for all kinds of incoming events. This allows to drop a pile of `incoming*` signals in Connection and a stack of options inside switchOnType in processIfVerification(). KVS::handleEvent() also makes (some) allowed state transitions a bit clearer.
Diffstat (limited to 'lib/events/keyverificationevent.h')
-rw-r--r--lib/events/keyverificationevent.h74
1 files changed, 28 insertions, 46 deletions
diff --git a/lib/events/keyverificationevent.h b/lib/events/keyverificationevent.h
index 0ffd8b2c..0e939508 100644
--- a/lib/events/keyverificationevent.h
+++ b/lib/events/keyverificationevent.h
@@ -9,13 +9,24 @@ namespace Quotient {
static constexpr auto SasV1Method = "m.sas.v1"_ls;
+class QUOTIENT_API KeyVerificationEvent : public Event {
+public:
+ QUO_BASE_EVENT(KeyVerificationEvent, "m.key.*"_ls, Event::BaseMetaType)
+
+ using Event::Event;
+
+ /// An opaque identifier for the verification request. Must
+ /// be unique with respect to the devices involved.
+ QUO_CONTENT_GETTER(QString, transactionId)
+};
+
/// Requests a key verification with another user's devices.
/// Typically sent as a to-device event.
-class QUOTIENT_API KeyVerificationRequestEvent : public Event {
+class QUOTIENT_API KeyVerificationRequestEvent : public KeyVerificationEvent {
public:
QUO_EVENT(KeyVerificationRequestEvent, "m.key.verification.request")
- using Event::Event;
+ using KeyVerificationEvent::KeyVerificationEvent;
KeyVerificationRequestEvent(const QString& transactionId,
const QString& fromDevice,
const QStringList& methods,
@@ -30,10 +41,6 @@ public:
/// The device ID which is initiating the request.
QUO_CONTENT_GETTER(QString, fromDevice)
- /// An opaque identifier for the verification request. Must
- /// be unique with respect to the devices involved.
- QUO_CONTENT_GETTER(QString, transactionId)
-
/// The verification methods supported by the sender.
QUO_CONTENT_GETTER(QStringList, methods)
@@ -44,11 +51,11 @@ public:
QUO_CONTENT_GETTER(QDateTime, timestamp)
};
-class QUOTIENT_API KeyVerificationReadyEvent : public Event {
+class QUOTIENT_API KeyVerificationReadyEvent : public KeyVerificationEvent {
public:
QUO_EVENT(KeyVerificationReadyEvent, "m.key.verification.ready")
- using Event::Event;
+ using KeyVerificationEvent::KeyVerificationEvent;
KeyVerificationReadyEvent(const QString& transactionId,
const QString& fromDevice,
const QStringList& methods)
@@ -61,19 +68,16 @@ public:
/// The device ID which is accepting the request.
QUO_CONTENT_GETTER(QString, fromDevice)
- /// The transaction id of the verification request
- QUO_CONTENT_GETTER(QString, transactionId)
-
/// The verification methods supported by the sender.
QUO_CONTENT_GETTER(QStringList, methods)
};
/// Begins a key verification process.
-class QUOTIENT_API KeyVerificationStartEvent : public Event {
+class QUOTIENT_API KeyVerificationStartEvent : public KeyVerificationEvent {
public:
QUO_EVENT(KeyVerificationStartEvent, "m.key.verification.start")
- using Event::Event;
+ using KeyVerificationEvent::KeyVerificationEvent;
KeyVerificationStartEvent(const QString& transactionId,
const QString& fromDevice)
: KeyVerificationStartEvent(
@@ -92,10 +96,6 @@ public:
/// The device ID which is initiating the process.
QUO_CONTENT_GETTER(QString, fromDevice)
- /// An opaque identifier for the verification request. Must
- /// be unique with respect to the devices involved.
- QUO_CONTENT_GETTER(QString, transactionId)
-
/// The verification method to use.
QUO_CONTENT_GETTER(QString, method)
@@ -140,11 +140,11 @@ public:
/// Accepts a previously sent m.key.verification.start message.
/// Typically sent as a to-device event.
-class QUOTIENT_API KeyVerificationAcceptEvent : public Event {
+class QUOTIENT_API KeyVerificationAcceptEvent : public KeyVerificationEvent {
public:
QUO_EVENT(KeyVerificationAcceptEvent, "m.key.verification.accept")
- using Event::Event;
+ using KeyVerificationEvent::KeyVerificationEvent;
KeyVerificationAcceptEvent(const QString& transactionId,
const QString& commitment)
: KeyVerificationAcceptEvent(basicJson(
@@ -158,9 +158,6 @@ public:
{ "commitment"_ls, commitment } }))
{}
- /// An opaque identifier for the verification process.
- QUO_CONTENT_GETTER(QString, transactionId)
-
/// The verification method to use. Must be 'm.sas.v1'.
QUO_CONTENT_GETTER(QString, method)
@@ -170,10 +167,7 @@ public:
/// The hash method the device is choosing to use, out of the
/// options in the m.key.verification.start message.
- QString hashData() const
- {
- return contentPart<QString>("hash"_ls);
- }
+ QUO_CONTENT_GETTER_X(QString, hashData, "hash"_ls)
/// The message authentication code the device is choosing to use, out
/// of the options in the m.key.verification.start message.
@@ -188,11 +182,11 @@ public:
QUO_CONTENT_GETTER(QString, commitment)
};
-class QUOTIENT_API KeyVerificationCancelEvent : public Event {
+class QUOTIENT_API KeyVerificationCancelEvent : public KeyVerificationEvent {
public:
QUO_EVENT(KeyVerificationCancelEvent, "m.key.verification.cancel")
- using Event::Event;
+ using KeyVerificationEvent::KeyVerificationEvent;
KeyVerificationCancelEvent(const QString& transactionId,
const QString& reason)
: KeyVerificationCancelEvent(
@@ -203,9 +197,6 @@ public:
}))
{}
- /// An opaque identifier for the verification process.
- QUO_CONTENT_GETTER(QString, transactionId)
-
/// A human readable description of the code. The client should only
/// rely on this string if it does not understand the code.
QUO_CONTENT_GETTER(QString, reason)
@@ -216,30 +207,27 @@ public:
/// Sends the ephemeral public key for a device to the partner device.
/// Typically sent as a to-device event.
-class QUOTIENT_API KeyVerificationKeyEvent : public Event {
+class KeyVerificationKeyEvent : public KeyVerificationEvent {
public:
QUO_EVENT(KeyVerificationKeyEvent, "m.key.verification.key")
- using Event::Event;
+ using KeyVerificationEvent::KeyVerificationEvent;
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)
-
/// The device's ephemeral public key, encoded as unpadded base64.
QUO_CONTENT_GETTER(QString, key)
};
/// Sends the MAC of a device's key to the partner device.
-class QUOTIENT_API KeyVerificationMacEvent : public Event {
+class QUOTIENT_API KeyVerificationMacEvent : public KeyVerificationEvent {
public:
QUO_EVENT(KeyVerificationMacEvent, "m.key.verification.mac")
- using Event::Event;
+ using KeyVerificationEvent::KeyVerificationEvent;
KeyVerificationMacEvent(const QString& transactionId, const QString& keys,
const QJsonObject& mac)
: KeyVerificationMacEvent(
@@ -248,9 +236,6 @@ public:
{ "mac"_ls, mac } }))
{}
- /// An opaque identifier for the verification process.
- QUO_CONTENT_GETTER(QString, transactionId)
-
/// The device's ephemeral public key, encoded as unpadded base64.
QUO_CONTENT_GETTER(QString, keys)
@@ -260,17 +245,14 @@ public:
}
};
-class QUOTIENT_API KeyVerificationDoneEvent : public Event {
+class QUOTIENT_API KeyVerificationDoneEvent : public KeyVerificationEvent {
public:
QUO_EVENT(KeyVerificationDoneEvent, "m.key.verification.done")
- using Event::Event;
+ using KeyVerificationEvent::KeyVerificationEvent;
explicit KeyVerificationDoneEvent(const QString& transactionId)
: KeyVerificationDoneEvent(
basicJson(TypeId, { { "transaction_id"_ls, transactionId } }))
{}
-
- /// The same transactionId as before
- QUO_CONTENT_GETTER(QString, transactionId)
};
} // namespace Quotient