// SPDX-FileCopyrightText: 2019 Alexey Andreyev // SPDX-FileCopyrightText: 2019 Kitsune Ral // SPDX-FileCopyrightText: 2021 Carl Schwan // SPDX-License-Identifier: LGPL-2.1-or-later #pragma once #include "converters.h" #include "quotient_common.h" #include #include namespace Quotient { constexpr auto CiphertextKeyL = "ciphertext"_ls; constexpr auto SenderKeyKeyL = "sender_key"_ls; constexpr auto DeviceIdKeyL = "device_id"_ls; constexpr auto SessionIdKeyL = "session_id"_ls; constexpr auto AlgorithmKeyL = "algorithm"_ls; constexpr auto RotationPeriodMsKeyL = "rotation_period_ms"_ls; constexpr auto RotationPeriodMsgsKeyL = "rotation_period_msgs"_ls; constexpr auto AlgorithmKey = "algorithm"_ls; constexpr auto RotationPeriodMsKey = "rotation_period_ms"_ls; constexpr auto RotationPeriodMsgsKey = "rotation_period_msgs"_ls; constexpr auto Ed25519Key = "ed25519"_ls; constexpr auto Curve25519Key = "curve25519"_ls; constexpr auto SignedCurve25519Key = "signed_curve25519"_ls; constexpr auto OlmV1Curve25519AesSha2AlgoKey = "m.olm.v1.curve25519-aes-sha2"_ls; constexpr auto MegolmV1AesSha2AlgoKey = "m.megolm.v1.aes-sha2"_ls; struct Unencrypted {}; struct Encrypted { QByteArray key; }; using PicklingMode = std::variant; class QOlmSession; using QOlmSessionPtr = std::unique_ptr; class QOlmInboundGroupSession; using QOlmInboundGroupSessionPtr = std::unique_ptr; struct IdentityKeys { QByteArray curve25519; QByteArray ed25519; }; //! Struct representing the one-time keys. struct QUOTIENT_API OneTimeKeys { QMap> keys; //! Get the HashMap containing the curve25519 one-time keys. QMap curve25519() const; //! Get a reference to the hashmap corresponding to given key type. // std::optional> get(QString keyType) const; }; //! Struct representing the signed one-time keys. class SignedOneTimeKey { public: //! Required. The unpadded Base64-encoded 32-byte Curve25519 public key. QString key; //! Required. Signatures of the key object. //! The signature is calculated using the process described at Signing JSON. QHash> signatures; }; template <> struct JsonObjectConverter { static void fillFrom(const QJsonObject& jo, SignedOneTimeKey& result) { fromJson(jo.value("key"_ls), result.key); fromJson(jo.value("signatures"_ls), result.signatures); } static void dumpTo(QJsonObject &jo, const SignedOneTimeKey &result) { addParam<>(jo, QStringLiteral("key"), result.key); addParam<>(jo, QStringLiteral("signatures"), result.signatures); } }; template class asKeyValueRange { public: asKeyValueRange(T& data) : m_data { data } {} auto begin() { return m_data.keyValueBegin(); } auto end() { return m_data.keyValueEnd(); } private: T &m_data; }; template asKeyValueRange(T&) -> asKeyValueRange; } // namespace Quotient Q_DECLARE_METATYPE(Quotient::SignedOneTimeKey)