libQuotient
A Qt library for building matrix clients
Loading...
Searching...
No Matches
filesourceinfo.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#pragma once
6
7#include <Quotient/converters.h>
8
9#include <array>
10
11namespace Quotient {
12/**
13 * JSON Web Key object as specified in
14 * https://spec.matrix.org/unstable/client-server-api/#extensions-to-mroommessage-msgtypes
15 * The only currently relevant member is `k`, the rest needs to be set to the defaults specified in the spec.
16 */
17struct JWK
18{
19 Q_GADGET
20 Q_PROPERTY(QString kty MEMBER kty CONSTANT)
25
26public:
28 QStringList keyOps;
29 QString alg;
30 QString k;
31 bool ext;
32};
33
42
43public:
44 QUrl url;
45 JWK key;
46 QString iv;
48 QString v;
49
50 bool isValid() const { return url.isValid(); }
51};
52
54 const QByteArray& plainText);
57
58template <>
60 static void dumpTo(QJsonObject& jo, const EncryptedFileMetadata& pod);
61 static void fillFrom(const QJsonObject& jo, EncryptedFileMetadata& pod);
62};
63
64template <>
66 static void dumpTo(QJsonObject& jo, const JWK& pod);
67 static void fillFrom(const QJsonObject& jo, JWK& pod);
68};
69
71
73
75
76QUOTIENT_API void setUrlInSourceInfo(FileSourceInfo& fsi, const QUrl& newUrl);
77
78// The way FileSourceInfo is stored in JSON requires an extra parameter so
79// the original template is not applicable
80template <>
81void fillJson(QJsonObject&, const FileSourceInfo&) = delete;
82
83//! \brief Export FileSourceInfo to a JSON object
84//!
85//! Depending on what is stored inside FileSourceInfo, this function will insert
86//! - a key-to-string pair where key is taken from jsonKeys[0] and the string
87//! is the URL, if FileSourceInfo stores a QUrl;
88//! - a key-to-object mapping where key is taken from jsonKeys[1] and the object
89//! is the result of converting EncryptedFileMetadata to JSON,
90//! if FileSourceInfo stores EncryptedFileMetadata
91QUOTIENT_API void fillJson(QJsonObject& jo, const FileSourceInfoKeys& jsonKeys,
92 const FileSourceInfo& fsi);
93
96
97namespace FileMetadataMap {
98 QUOTIENT_API void add(const QString& roomId,
99 const QString& eventId,
100 const EncryptedFileMetadata& fileMetadata);
101 QUOTIENT_API void remove(const QString& roomId,
102 const QString& eventId);
103
104 //! \brief Obtain file source information across connections, thread-safely
105 //! \return the previously saved EncryptedFileMetadata object, or an invalid
106 //! (default-constructed) object in case of unsuccessful lookup
107 QUOTIENT_API EncryptedFileMetadata lookup(const QString& roomId,
108 const QString& eventId);
109}
110
111} // namespace Quotient
QUOTIENT_API void remove(const QString &roomId, const QString &eventId)
QUOTIENT_API void add(const QString &roomId, const QString &eventId, const EncryptedFileMetadata &fileMetadata)
QUOTIENT_API void fillJson(QJsonObject &jo, const FileSourceInfoKeys &jsonKeys, const FileSourceInfo &fsi)
Export FileSourceInfo to a JSON object.
void fillJson(QJsonObject &, const FileSourceInfo &)=delete
QUOTIENT_API void setUrlInSourceInfo(FileSourceInfo &fsi, const QUrl &newUrl)
#define QUOTIENT_API