diff options
Diffstat (limited to 'lib/csapi/definitions/device_keys.h')
-rw-r--r-- | lib/csapi/definitions/device_keys.h | 81 |
1 files changed, 46 insertions, 35 deletions
diff --git a/lib/csapi/definitions/device_keys.h b/lib/csapi/definitions/device_keys.h index 6023e7e8..84ecefae 100644 --- a/lib/csapi/definitions/device_keys.h +++ b/lib/csapi/definitions/device_keys.h @@ -6,40 +6,51 @@ #include "converters.h" -#include <QtCore/QHash> - -namespace QMatrixClient -{ - // Data structures - - /// Device identity keys - struct DeviceKeys +namespace Quotient { +/// Device identity keys +struct DeviceKeys { + /// The ID of the user the device belongs to. Must match the user ID used + /// when logging in. + QString userId; + + /// The ID of the device these keys belong to. Must match the device ID used + /// when logging in. + QString deviceId; + + /// The encryption algorithms supported by this device. + QStringList algorithms; + + /// Public identity keys. The names of the properties should be in the + /// format `<algorithm>:<device_id>`. The keys themselves should be + /// encoded as specified by the key algorithm. + QHash<QString, QString> keys; + + /// Signatures for the device key object. A map from user ID, to a map from + /// `<algorithm>:<device_id>` to the signature. + /// + /// The signature is calculated using the process described at [Signing + /// JSON](/appendices/#signing-json). + QHash<QString, QHash<QString, QString>> signatures; +}; + +template <> +struct JsonObjectConverter<DeviceKeys> { + static void dumpTo(QJsonObject& jo, const DeviceKeys& pod) { - /// The ID of the user the device belongs to. Must match the user ID used - /// when logging in. - QString userId; - /// The ID of the device these keys belong to. Must match the device ID used - /// when logging in. - QString deviceId; - /// The encryption algorithms supported by this device. - QStringList algorithms; - /// Public identity keys. The names of the properties should be in the - /// format ``<algorithm>:<device_id>``. The keys themselves should be - /// encoded as specified by the key algorithm. - QHash<QString, QString> keys; - /// Signatures for the device key object. A map from user ID, to a map from - /// ``<algorithm>:<device_id>`` to the signature. - /// - /// The signature is calculated using the process described at `Signing - /// JSON`_. - QHash<QString, QHash<QString, QString>> signatures; - }; - - QJsonObject toJson(const DeviceKeys& pod); - - template <> struct FromJsonObject<DeviceKeys> + addParam<>(jo, QStringLiteral("user_id"), pod.userId); + addParam<>(jo, QStringLiteral("device_id"), pod.deviceId); + addParam<>(jo, QStringLiteral("algorithms"), pod.algorithms); + addParam<>(jo, QStringLiteral("keys"), pod.keys); + addParam<>(jo, QStringLiteral("signatures"), pod.signatures); + } + static void fillFrom(const QJsonObject& jo, DeviceKeys& pod) { - DeviceKeys operator()(const QJsonObject& jo) const; - }; - -} // namespace QMatrixClient + fromJson(jo.value("user_id"_ls), pod.userId); + fromJson(jo.value("device_id"_ls), pod.deviceId); + fromJson(jo.value("algorithms"_ls), pod.algorithms); + fromJson(jo.value("keys"_ls), pod.keys); + fromJson(jo.value("signatures"_ls), pod.signatures); + } +}; + +} // namespace Quotient |