aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-06-09 10:19:14 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-06-23 07:57:43 +0200
commit19746de7426aeb67eb90e8c48448356691e270b0 (patch)
treea398f362ff7351e86afb4af87b459f335b7efb10 /lib
parent7576f77799c3d446d3376b0801f218a86320480d (diff)
downloadlibquotient-19746de7426aeb67eb90e8c48448356691e270b0.tar.gz
libquotient-19746de7426aeb67eb90e8c48448356691e270b0.zip
Use QUO_CONTENT_GETTER
In keyverificationevent.*, this massively shortens repetitive getter definitions; the remaining few non-trivial ones are moved to keyverificationevent.h, dropping the respective .cpp file and therefore the dedicated translation unit. In roomkeyevent.h, it's just shorter.
Diffstat (limited to 'lib')
-rw-r--r--lib/events/keyverificationevent.cpp164
-rw-r--r--lib/events/keyverificationevent.h80
-rw-r--r--lib/events/roomkeyevent.h6
3 files changed, 54 insertions, 196 deletions
diff --git a/lib/events/keyverificationevent.cpp b/lib/events/keyverificationevent.cpp
deleted file mode 100644
index 4803955d..00000000
--- a/lib/events/keyverificationevent.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
-// SPDX-License-Identifier: LGPL-2.1-or-later
-
-#include "keyverificationevent.h"
-
-using namespace Quotient;
-
-KeyVerificationRequestEvent::KeyVerificationRequestEvent(const QJsonObject &obj)
- : Event(typeId(), obj)
-{}
-
-QString KeyVerificationRequestEvent::fromDevice() const
-{
- return contentPart<QString>("from_device"_ls);
-}
-
-QString KeyVerificationRequestEvent::transactionId() const
-{
- return contentPart<QString>("transaction_id"_ls);
-}
-
-QStringList KeyVerificationRequestEvent::methods() const
-{
- return contentPart<QStringList>("methods"_ls);
-}
-
-uint64_t KeyVerificationRequestEvent::timestamp() const
-{
- return contentPart<double>("timestamp"_ls);
-}
-
-KeyVerificationStartEvent::KeyVerificationStartEvent(const QJsonObject &obj)
- : Event(typeId(), obj)
-{}
-
-QString KeyVerificationStartEvent::fromDevice() const
-{
- return contentPart<QString>("from_device"_ls);
-}
-
-QString KeyVerificationStartEvent::transactionId() const
-{
- return contentPart<QString>("transaction_id"_ls);
-}
-
-QString KeyVerificationStartEvent::method() const
-{
- return contentPart<QString>("method"_ls);
-}
-
-Omittable<QString> KeyVerificationStartEvent::nextMethod() const
-{
- return contentPart<Omittable<QString>>("method_ls");
-}
-
-QStringList KeyVerificationStartEvent::keyAgreementProtocols() const
-{
- Q_ASSERT(method() == QStringLiteral("m.sas.v1"));
- return contentPart<QStringList>("key_agreement_protocols"_ls);
-}
-
-QStringList KeyVerificationStartEvent::hashes() const
-{
- Q_ASSERT(method() == QStringLiteral("m.sas.v1"));
- return contentPart<QStringList>("hashes"_ls);
-
-}
-
-QStringList KeyVerificationStartEvent::messageAuthenticationCodes() const
-{
- Q_ASSERT(method() == QStringLiteral("m.sas.v1"));
- return contentPart<QStringList>("message_authentication_codes"_ls);
-}
-
-QString KeyVerificationStartEvent::shortAuthenticationString() const
-{
- return contentPart<QString>("short_authentification_string"_ls);
-}
-
-KeyVerificationAcceptEvent::KeyVerificationAcceptEvent(const QJsonObject &obj)
- : Event(typeId(), obj)
-{}
-
-QString KeyVerificationAcceptEvent::transactionId() const
-{
- return contentPart<QString>("transaction_id"_ls);
-}
-
-QString KeyVerificationAcceptEvent::method() const
-{
- return contentPart<QString>("method"_ls);
-}
-
-QString KeyVerificationAcceptEvent::keyAgreementProtocol() const
-{
- return contentPart<QString>("key_agreement_protocol"_ls);
-}
-
-QString KeyVerificationAcceptEvent::hashData() const
-{
- return contentPart<QString>("hash"_ls);
-}
-
-QStringList KeyVerificationAcceptEvent::shortAuthenticationString() const
-{
- return contentPart<QStringList>("short_authentification_string"_ls);
-}
-
-QString KeyVerificationAcceptEvent::commitement() const
-{
- return contentPart<QString>("commitment"_ls);
-}
-
-KeyVerificationCancelEvent::KeyVerificationCancelEvent(const QJsonObject &obj)
- : Event(typeId(), obj)
-{}
-
-QString KeyVerificationCancelEvent::transactionId() const
-{
- return contentPart<QString>("transaction_id"_ls);
-}
-
-QString KeyVerificationCancelEvent::reason() const
-{
- return contentPart<QString>("reason"_ls);
-}
-
-QString KeyVerificationCancelEvent::code() const
-{
- return contentPart<QString>("code"_ls);
-}
-
-KeyVerificationKeyEvent::KeyVerificationKeyEvent(const QJsonObject &obj)
- : Event(typeId(), obj)
-{}
-
-QString KeyVerificationKeyEvent::transactionId() const
-{
- return contentPart<QString>("transaction_id"_ls);
-}
-
-QString KeyVerificationKeyEvent::key() const
-{
- return contentPart<QString>("key"_ls);
-}
-
-KeyVerificationMacEvent::KeyVerificationMacEvent(const QJsonObject &obj)
- : Event(typeId(), obj)
-{}
-
-QString KeyVerificationMacEvent::transactionId() const
-{
- return contentPart<QString>("transaction_id"_ls);
-}
-
-QString KeyVerificationMacEvent::keys() const
-{
- return contentPart<QString>("keys"_ls);
-}
-
-QHash<QString, QString> KeyVerificationMacEvent::mac() const
-{
- return contentPart<QHash<QString, QString>>("mac"_ls);
-}
diff --git a/lib/events/keyverificationevent.h b/lib/events/keyverificationevent.h
index 497e56a2..78457e0c 100644
--- a/lib/events/keyverificationevent.h
+++ b/lib/events/keyverificationevent.h
@@ -14,20 +14,20 @@ public:
explicit KeyVerificationRequestEvent(const QJsonObject& obj);
/// The device ID which is initiating the request.
- QString fromDevice() const;
+ QUO_CONTENT_GETTER(QString, fromDevice)
/// An opaque identifier for the verification request. Must
/// be unique with respect to the devices involved.
- QString transactionId() const;
+ QUO_CONTENT_GETTER(QString, transactionId)
/// The verification methods supported by the sender.
- QStringList methods() const;
+ QUO_CONTENT_GETTER(QStringList, methods)
/// The POSIX timestamp in milliseconds for when the request was
/// made. If the request is in the future by more than 5 minutes or
/// more than 10 minutes in the past, the message should be ignored
/// by the receiver.
- uint64_t timestamp() const;
+ QUO_CONTENT_GETTER(uint64_t, timestamp)
};
REGISTER_EVENT_TYPE(KeyVerificationRequestEvent)
@@ -39,36 +39,52 @@ public:
explicit KeyVerificationStartEvent(const QJsonObject &obj);
/// The device ID which is initiating the process.
- QString fromDevice() const;
+ QUO_CONTENT_GETTER(QString, fromDevice)
/// An opaque identifier for the verification request. Must
/// be unique with respect to the devices involved.
- QString transactionId() const;
+ QUO_CONTENT_GETTER(QString, transactionId)
/// The verification method to use.
- QString method() const;
+ QUO_CONTENT_GETTER(QString, method)
/// Optional method to use to verify the other user's key with.
- Omittable<QString> nextMethod() const;
+ QUO_CONTENT_GETTER(Omittable<QString>, nextMethod)
// SAS.V1 methods
/// The key agreement protocols the sending device understands.
/// \note Only exist if method is m.sas.v1
- QStringList keyAgreementProtocols() const;
+ QStringList keyAgreementProtocols() const
+ {
+ Q_ASSERT(method() == QStringLiteral("m.sas.v1"));
+ return contentPart<QStringList>("key_agreement_protocols"_ls);
+ }
/// The hash methods the sending device understands.
/// \note Only exist if method is m.sas.v1
- QStringList hashes() const;
+ QStringList hashes() const
+ {
+ Q_ASSERT(method() == QStringLiteral("m.sas.v1"));
+ return contentPart<QStringList>("hashes"_ls);
+ }
/// The message authentication codes that the sending device understands.
/// \note Only exist if method is m.sas.v1
- QStringList messageAuthenticationCodes() const;
+ QStringList messageAuthenticationCodes() const
+ {
+ Q_ASSERT(method() == QStringLiteral("m.sas.v1"));
+ return contentPart<QStringList>("message_authentication_codes"_ls);
+ }
/// The SAS methods the sending device (and the sending device's
/// user) understands.
/// \note Only exist if method is m.sas.v1
- QString shortAuthenticationString() const;
+ QString shortAuthenticationString() const
+ {
+ Q_ASSERT(method() == QStringLiteral("m.sas.v1"));
+ return contentPart<QString>("short_authentification_string"_ls);
+ }
};
REGISTER_EVENT_TYPE(KeyVerificationStartEvent)
@@ -81,30 +97,33 @@ public:
explicit KeyVerificationAcceptEvent(const QJsonObject& obj);
/// An opaque identifier for the verification process.
- QString transactionId() const;
+ QUO_CONTENT_GETTER(QString, transactionId)
/// The verification method to use. Must be 'm.sas.v1'.
- QString method() const;
+ QUO_CONTENT_GETTER(QString, method)
/// The key agreement protocol the device is choosing to use, out of
/// the options in the m.key.verification.start message.
- QString keyAgreementProtocol() const;
+ QUO_CONTENT_GETTER(QString, keyAgreementProtocol)
/// The hash method the device is choosing to use, out of the
/// options in the m.key.verification.start message.
- QString hashData() const;
+ QString hashData() const
+ {
+ return contentPart<QString>("hash"_ls);
+ }
/// The message authentication code the device is choosing to use, out
/// of the options in the m.key.verification.start message.
- QString messageAuthenticationCode() const;
+ QUO_CONTENT_GETTER(QString, messageAuthenticationCode)
/// The SAS methods both devices involved in the verification process understand.
- QStringList shortAuthenticationString() const;
+ QUO_CONTENT_GETTER(QStringList, shortAuthenticationString)
/// The hash (encoded as unpadded base64) of the concatenation of the
/// device's ephemeral public key (encoded as unpadded base64) and the
/// canonical JSON representation of the m.key.verification.start message.
- QString commitement() const;
+ QUO_CONTENT_GETTER(QString, commitment)
};
REGISTER_EVENT_TYPE(KeyVerificationAcceptEvent)
@@ -115,14 +134,14 @@ public:
explicit KeyVerificationCancelEvent(const QJsonObject &obj);
/// An opaque identifier for the verification process.
- QString transactionId() const;
+ 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.
- QString reason() const;
+ QUO_CONTENT_GETTER(QString, reason)
/// The error code for why the process/request was cancelled by the user.
- QString code() const;
+ QUO_CONTENT_GETTER(QString, code)
};
REGISTER_EVENT_TYPE(KeyVerificationCancelEvent)
@@ -134,11 +153,11 @@ public:
explicit KeyVerificationKeyEvent(const QJsonObject &obj);
- /// An opaque identifier for the verification process.
- QString transactionId() const;
+ /// An opaque identifier for the verification process.
+ QUO_CONTENT_GETTER(QString, transactionId)
/// The device's ephemeral public key, encoded as unpadded base64.
- QString key() const;
+ QUO_CONTENT_GETTER(QString, key)
};
REGISTER_EVENT_TYPE(KeyVerificationKeyEvent)
@@ -149,13 +168,16 @@ public:
explicit KeyVerificationMacEvent(const QJsonObject &obj);
- /// An opaque identifier for the verification process.
- QString transactionId() const;
+ /// An opaque identifier for the verification process.
+ QUO_CONTENT_GETTER(QString, transactionId)
/// The device's ephemeral public key, encoded as unpadded base64.
- QString keys() const;
+ QUO_CONTENT_GETTER(QString, keys)
- QHash<QString, QString> mac() const;
+ QHash<QString, QString> mac() const
+ {
+ return contentPart<QHash<QString, QString>>("mac"_ls);
+ }
};
REGISTER_EVENT_TYPE(KeyVerificationMacEvent)
} // namespace Quotient
diff --git a/lib/events/roomkeyevent.h b/lib/events/roomkeyevent.h
index 3093db41..9eb2854b 100644
--- a/lib/events/roomkeyevent.h
+++ b/lib/events/roomkeyevent.h
@@ -16,9 +16,9 @@ public:
const QString& sessionId, const QString& sessionKey,
const QString& senderId);
- QString algorithm() const { return contentPart<QString>("algorithm"_ls); }
- QString roomId() const { return contentPart<QString>(RoomIdKeyL); }
- QString sessionId() const { return contentPart<QString>("session_id"_ls); }
+ QUO_CONTENT_GETTER(QString, algorithm)
+ QUO_CONTENT_GETTER(QString, roomId)
+ QUO_CONTENT_GETTER(QString, sessionId)
QByteArray sessionKey() const
{
return contentPart<QString>("session_key"_ls).toLatin1();