diff options
author | Carl Schwan <carl@carlschwan.eu> | 2021-01-29 20:23:42 +0100 |
---|---|---|
committer | Tobias Fella <fella@posteo.de> | 2021-12-01 21:34:52 +0100 |
commit | 10b89faeea9e385ea901d45418491cd91dff99b9 (patch) | |
tree | d4051a67856e1c1f37034d7efc9a9d8647ef1556 /lib/crypto/e2ee.h | |
parent | 0769764249e10f2f6d1a84ac87e93b2fa3b6c61a (diff) | |
download | libquotient-10b89faeea9e385ea901d45418491cd91dff99b9.tar.gz libquotient-10b89faeea9e385ea901d45418491cd91dff99b9.zip |
More tests
Diffstat (limited to 'lib/crypto/e2ee.h')
-rw-r--r-- | lib/crypto/e2ee.h | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/lib/crypto/e2ee.h b/lib/crypto/e2ee.h index 73dd7f65..2d280185 100644 --- a/lib/crypto/e2ee.h +++ b/lib/crypto/e2ee.h @@ -7,10 +7,13 @@ #include <optional> #include <string> +#include "converters.h" #include <variant> #include <QMap> +#include <QHash> #include <QStringList> +#include <QMetaType> #include "util.h" @@ -68,16 +71,56 @@ struct OneTimeKeys }; //! Struct representing the signed one-time keys. -struct SignedOneTimeKey +class SignedOneTimeKey { +public: + SignedOneTimeKey() = default; + SignedOneTimeKey(const SignedOneTimeKey &) = default; + SignedOneTimeKey &operator=(const SignedOneTimeKey &) = default; //! 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. - QMap<QString, QMap<QString, QString>> signatures; + QHash<QString, QHash<QString, QString>> signatures; +}; + + +template <> +struct JsonObjectConverter<SignedOneTimeKey> { + 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); + } }; bool operator==(const IdentityKeys& lhs, const IdentityKeys& rhs); +template <typename T> +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; +}; + } // namespace Quotient + +Q_DECLARE_METATYPE(Quotient::SignedOneTimeKey) |