File: key_backup.h

package info (click to toggle)
libquotient 0.9.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,588 kB
  • sloc: xml: 39,103; cpp: 25,226; sh: 97; makefile: 10
file content (541 lines) | stat: -rw-r--r-- 20,701 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
// THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN

#pragma once

#include <Quotient/csapi/definitions/key_backup_data.h>
#include <Quotient/csapi/definitions/room_key_backup.h>

#include <Quotient/jobs/basejob.h>

namespace Quotient {

//! \brief Create a new backup.
//!
//! Creates a new backup.
class QUOTIENT_API PostRoomKeysVersionJob : public BaseJob {
public:
    //! \param algorithm
    //!   The algorithm used for storing backups.
    //!
    //! \param authData
    //!   Algorithm-dependent data. See the documentation for the backup
    //!   algorithms in [Server-side key backups](/client-server-api/#server-side-key-backups) for
    //!   more information on the expected format of the data.
    explicit PostRoomKeysVersionJob(const QString& algorithm, const QJsonObject& authData);

    // Result properties

    //! The backup version. This is an opaque string.
    QString version() const { return loadFromJson<QString>("version"_L1); }
};

inline auto collectResponse(const PostRoomKeysVersionJob* job) { return job->version(); }

//! \brief Get information about the latest backup version.
//!
//! Get information about the latest backup version.
class QUOTIENT_API GetRoomKeysVersionCurrentJob : public BaseJob {
public:
    explicit GetRoomKeysVersionCurrentJob();

    //! \brief Construct a URL without creating a full-fledged job object
    //!
    //! This function can be used when a URL for GetRoomKeysVersionCurrentJob
    //! is necessary but the job itself isn't.
    static QUrl makeRequestUrl(const HomeserverData& hsData);

    // Result properties

    //! The algorithm used for storing backups.
    QString algorithm() const { return loadFromJson<QString>("algorithm"_L1); }

    //! Algorithm-dependent data. See the documentation for the backup
    //! algorithms in [Server-side key backups](/client-server-api/#server-side-key-backups) for
    //! more information on the expected format of the data.
    QJsonObject authData() const { return loadFromJson<QJsonObject>("auth_data"_L1); }

    //! The number of keys stored in the backup.
    int count() const { return loadFromJson<int>("count"_L1); }

    //! An opaque string representing stored keys in the backup.
    //! Clients can compare it with the `etag` value they received
    //! in the request of their last key storage request.  If not
    //! equal, another client has modified the backup.
    QString etag() const { return loadFromJson<QString>("etag"_L1); }

    //! The backup version.
    QString version() const { return loadFromJson<QString>("version"_L1); }

    struct Response {
        //! The algorithm used for storing backups.
        QString algorithm{};

        //! Algorithm-dependent data. See the documentation for the backup
        //! algorithms in [Server-side key backups](/client-server-api/#server-side-key-backups) for
        //! more information on the expected format of the data.
        QJsonObject authData{};

        //! The number of keys stored in the backup.
        int count{};

        //! An opaque string representing stored keys in the backup.
        //! Clients can compare it with the `etag` value they received
        //! in the request of their last key storage request.  If not
        //! equal, another client has modified the backup.
        QString etag{};

        //! The backup version.
        QString version{};
    };
};

template <std::derived_from<GetRoomKeysVersionCurrentJob> JobT>
constexpr inline auto doCollectResponse<JobT> =
    [](JobT* j) -> GetRoomKeysVersionCurrentJob::Response {
    return { j->algorithm(), j->authData(), j->count(), j->etag(), j->version() };
};

//! \brief Get information about an existing backup.
//!
//! Get information about an existing backup.
class QUOTIENT_API GetRoomKeysVersionJob : public BaseJob {
public:
    //! \param version
    //!   The backup version to get, as returned in the `version` parameter
    //!   of the response in
    //!   [`POST
    //!   /_matrix/client/v3/room_keys/version`](/client-server-api/#post_matrixclientv3room_keysversion)
    //!   or this endpoint.
    explicit GetRoomKeysVersionJob(const QString& version);

    //! \brief Construct a URL without creating a full-fledged job object
    //!
    //! This function can be used when a URL for GetRoomKeysVersionJob
    //! is necessary but the job itself isn't.
    static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& version);

    // Result properties

    //! The algorithm used for storing backups.
    QString algorithm() const { return loadFromJson<QString>("algorithm"_L1); }

    //! Algorithm-dependent data. See the documentation for the backup
    //! algorithms in [Server-side key backups](/client-server-api/#server-side-key-backups) for
    //! more information on the expected format of the data.
    QJsonObject authData() const { return loadFromJson<QJsonObject>("auth_data"_L1); }

    //! The number of keys stored in the backup.
    int count() const { return loadFromJson<int>("count"_L1); }

    //! An opaque string representing stored keys in the backup.
    //! Clients can compare it with the `etag` value they received
    //! in the request of their last key storage request.  If not
    //! equal, another client has modified the backup.
    QString etag() const { return loadFromJson<QString>("etag"_L1); }

    //! The backup version.
    QString version() const { return loadFromJson<QString>("version"_L1); }

    struct Response {
        //! The algorithm used for storing backups.
        QString algorithm{};

        //! Algorithm-dependent data. See the documentation for the backup
        //! algorithms in [Server-side key backups](/client-server-api/#server-side-key-backups) for
        //! more information on the expected format of the data.
        QJsonObject authData{};

        //! The number of keys stored in the backup.
        int count{};

        //! An opaque string representing stored keys in the backup.
        //! Clients can compare it with the `etag` value they received
        //! in the request of their last key storage request.  If not
        //! equal, another client has modified the backup.
        QString etag{};

        //! The backup version.
        QString version{};
    };
};

template <std::derived_from<GetRoomKeysVersionJob> JobT>
constexpr inline auto doCollectResponse<JobT> = [](JobT* j) -> GetRoomKeysVersionJob::Response {
    return { j->algorithm(), j->authData(), j->count(), j->etag(), j->version() };
};

//! \brief Update information about an existing backup.
//!
//! Update information about an existing backup.  Only `auth_data` can be modified.
class QUOTIENT_API PutRoomKeysVersionJob : public BaseJob {
public:
    //! \param version
    //!   The backup version to update, as returned in the `version`
    //!   parameter in the response of
    //!   [`POST
    //!   /_matrix/client/v3/room_keys/version`](/client-server-api/#post_matrixclientv3room_keysversion)
    //!   or [`GET
    //!   /_matrix/client/v3/room_keys/version/{version}`](/client-server-api/#get_matrixclientv3room_keysversionversion).
    //!
    //! \param algorithm
    //!   The algorithm used for storing backups.  Must be the same as
    //!   the algorithm currently used by the backup.
    //!
    //! \param authData
    //!   Algorithm-dependent data. See the documentation for the backup
    //!   algorithms in [Server-side key backups](/client-server-api/#server-side-key-backups) for
    //!   more information on the expected format of the data.
    explicit PutRoomKeysVersionJob(const QString& version, const QString& algorithm,
                                   const QJsonObject& authData);
};

//! \brief Delete an existing key backup.
//!
//! Delete an existing key backup. Both the information about the backup,
//! as well as all key data related to the backup will be deleted.
class QUOTIENT_API DeleteRoomKeysVersionJob : public BaseJob {
public:
    //! \param version
    //!   The backup version to delete, as returned in the `version`
    //!   parameter in the response of
    //!   [`POST
    //!   /_matrix/client/v3/room_keys/version`](/client-server-api/#post_matrixclientv3room_keysversion)
    //!   or [`GET
    //!   /_matrix/client/v3/room_keys/version/{version}`](/client-server-api/#get_matrixclientv3room_keysversionversion).
    explicit DeleteRoomKeysVersionJob(const QString& version);

    //! \brief Construct a URL without creating a full-fledged job object
    //!
    //! This function can be used when a URL for DeleteRoomKeysVersionJob
    //! is necessary but the job itself isn't.
    static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& version);
};

//! \brief Store a key in the backup.
//!
//! Store a key in the backup.
class QUOTIENT_API PutRoomKeyBySessionIdJob : public BaseJob {
public:
    //! \param roomId
    //!   The ID of the room that the key is for.
    //!
    //! \param sessionId
    //!   The ID of the megolm session that the key is for.
    //!
    //! \param version
    //!   The backup in which to store the key. Must be the current backup.
    //!
    //! \param data
    //!   The key data.
    explicit PutRoomKeyBySessionIdJob(const QString& roomId, const QString& sessionId,
                                      const QString& version, const KeyBackupData& data);

    // Result properties

    //! The new etag value representing stored keys in the backup.
    //! See `GET /room_keys/version/{version}` for more details.
    QString etag() const { return loadFromJson<QString>("etag"_L1); }

    //! The number of keys stored in the backup
    int count() const { return loadFromJson<int>("count"_L1); }

    struct Response {
        //! The new etag value representing stored keys in the backup.
        //! See `GET /room_keys/version/{version}` for more details.
        QString etag{};

        //! The number of keys stored in the backup
        int count{};
    };
};

template <std::derived_from<PutRoomKeyBySessionIdJob> JobT>
constexpr inline auto doCollectResponse<JobT> =
    [](JobT* j) -> PutRoomKeyBySessionIdJob::Response { return { j->etag(), j->count() }; };

//! \brief Retrieve a key from the backup.
//!
//! Retrieve a key from the backup.
class QUOTIENT_API GetRoomKeyBySessionIdJob : public BaseJob {
public:
    //! \param roomId
    //!   The ID of the room that the requested key is for.
    //!
    //! \param sessionId
    //!   The ID of the megolm session whose key is requested.
    //!
    //! \param version
    //!   The backup from which to retrieve the key.
    explicit GetRoomKeyBySessionIdJob(const QString& roomId, const QString& sessionId,
                                      const QString& version);

    //! \brief Construct a URL without creating a full-fledged job object
    //!
    //! This function can be used when a URL for GetRoomKeyBySessionIdJob
    //! is necessary but the job itself isn't.
    static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
                               const QString& sessionId, const QString& version);

    // Result properties

    //! The key data
    KeyBackupData data() const { return fromJson<KeyBackupData>(jsonData()); }
};

inline auto collectResponse(const GetRoomKeyBySessionIdJob* job) { return job->data(); }

//! \brief Delete a key from the backup.
//!
//! Delete a key from the backup.
class QUOTIENT_API DeleteRoomKeyBySessionIdJob : public BaseJob {
public:
    //! \param roomId
    //!   The ID of the room that the specified key is for.
    //!
    //! \param sessionId
    //!   The ID of the megolm session whose key is to be deleted.
    //!
    //! \param version
    //!   The backup from which to delete the key
    explicit DeleteRoomKeyBySessionIdJob(const QString& roomId, const QString& sessionId,
                                         const QString& version);

    //! \brief Construct a URL without creating a full-fledged job object
    //!
    //! This function can be used when a URL for DeleteRoomKeyBySessionIdJob
    //! is necessary but the job itself isn't.
    static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
                               const QString& sessionId, const QString& version);

    // Result properties

    //! The new etag value representing stored keys in the backup.
    //! See `GET /room_keys/version/{version}` for more details.
    QString etag() const { return loadFromJson<QString>("etag"_L1); }

    //! The number of keys stored in the backup
    int count() const { return loadFromJson<int>("count"_L1); }

    struct Response {
        //! The new etag value representing stored keys in the backup.
        //! See `GET /room_keys/version/{version}` for more details.
        QString etag{};

        //! The number of keys stored in the backup
        int count{};
    };
};

template <std::derived_from<DeleteRoomKeyBySessionIdJob> JobT>
constexpr inline auto doCollectResponse<JobT> =
    [](JobT* j) -> DeleteRoomKeyBySessionIdJob::Response { return { j->etag(), j->count() }; };

//! \brief Store several keys in the backup for a given room.
//!
//! Store several keys in the backup for a given room.
class QUOTIENT_API PutRoomKeysByRoomIdJob : public BaseJob {
public:
    //! \param roomId
    //!   The ID of the room that the keys are for.
    //!
    //! \param version
    //!   The backup in which to store the keys. Must be the current backup.
    //!
    //! \param backupData
    //!   The backup data
    explicit PutRoomKeysByRoomIdJob(const QString& roomId, const QString& version,
                                    const RoomKeyBackup& backupData);

    // Result properties

    //! The new etag value representing stored keys in the backup.
    //! See `GET /room_keys/version/{version}` for more details.
    QString etag() const { return loadFromJson<QString>("etag"_L1); }

    //! The number of keys stored in the backup
    int count() const { return loadFromJson<int>("count"_L1); }

    struct Response {
        //! The new etag value representing stored keys in the backup.
        //! See `GET /room_keys/version/{version}` for more details.
        QString etag{};

        //! The number of keys stored in the backup
        int count{};
    };
};

template <std::derived_from<PutRoomKeysByRoomIdJob> JobT>
constexpr inline auto doCollectResponse<JobT> =
    [](JobT* j) -> PutRoomKeysByRoomIdJob::Response { return { j->etag(), j->count() }; };

//! \brief Retrieve the keys from the backup for a given room.
//!
//! Retrieve the keys from the backup for a given room.
class QUOTIENT_API GetRoomKeysByRoomIdJob : public BaseJob {
public:
    //! \param roomId
    //!   The ID of the room that the requested key is for.
    //!
    //! \param version
    //!   The backup from which to retrieve the key.
    explicit GetRoomKeysByRoomIdJob(const QString& roomId, const QString& version);

    //! \brief Construct a URL without creating a full-fledged job object
    //!
    //! This function can be used when a URL for GetRoomKeysByRoomIdJob
    //! is necessary but the job itself isn't.
    static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
                               const QString& version);

    // Result properties

    //! The key data.  If no keys are found, then an object with an empty
    //! `sessions` property will be returned (`{"sessions": {}}`).
    RoomKeyBackup data() const { return fromJson<RoomKeyBackup>(jsonData()); }
};

inline auto collectResponse(const GetRoomKeysByRoomIdJob* job) { return job->data(); }

//! \brief Delete the keys from the backup for a given room.
//!
//! Delete the keys from the backup for a given room.
class QUOTIENT_API DeleteRoomKeysByRoomIdJob : public BaseJob {
public:
    //! \param roomId
    //!   The ID of the room that the specified key is for.
    //!
    //! \param version
    //!   The backup from which to delete the key.
    explicit DeleteRoomKeysByRoomIdJob(const QString& roomId, const QString& version);

    //! \brief Construct a URL without creating a full-fledged job object
    //!
    //! This function can be used when a URL for DeleteRoomKeysByRoomIdJob
    //! is necessary but the job itself isn't.
    static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
                               const QString& version);

    // Result properties

    //! The new etag value representing stored keys in the backup.
    //! See `GET /room_keys/version/{version}` for more details.
    QString etag() const { return loadFromJson<QString>("etag"_L1); }

    //! The number of keys stored in the backup
    int count() const { return loadFromJson<int>("count"_L1); }

    struct Response {
        //! The new etag value representing stored keys in the backup.
        //! See `GET /room_keys/version/{version}` for more details.
        QString etag{};

        //! The number of keys stored in the backup
        int count{};
    };
};

template <std::derived_from<DeleteRoomKeysByRoomIdJob> JobT>
constexpr inline auto doCollectResponse<JobT> =
    [](JobT* j) -> DeleteRoomKeysByRoomIdJob::Response { return { j->etag(), j->count() }; };

//! \brief Store several keys in the backup.
//!
//! Store several keys in the backup.
class QUOTIENT_API PutRoomKeysJob : public BaseJob {
public:
    //! \param version
    //!   The backup in which to store the keys. Must be the current backup.
    //!
    //! \param rooms
    //!   A map of room IDs to room key backup data.
    explicit PutRoomKeysJob(const QString& version, const QHash<RoomId, RoomKeyBackup>& rooms);

    // Result properties

    //! The new etag value representing stored keys in the backup.
    //! See `GET /room_keys/version/{version}` for more details.
    QString etag() const { return loadFromJson<QString>("etag"_L1); }

    //! The number of keys stored in the backup
    int count() const { return loadFromJson<int>("count"_L1); }

    struct Response {
        //! The new etag value representing stored keys in the backup.
        //! See `GET /room_keys/version/{version}` for more details.
        QString etag{};

        //! The number of keys stored in the backup
        int count{};
    };
};

template <std::derived_from<PutRoomKeysJob> JobT>
constexpr inline auto doCollectResponse<JobT> =
    [](JobT* j) -> PutRoomKeysJob::Response { return { j->etag(), j->count() }; };

//! \brief Retrieve the keys from the backup.
//!
//! Retrieve the keys from the backup.
class QUOTIENT_API GetRoomKeysJob : public BaseJob {
public:
    //! \param version
    //!   The backup from which to retrieve the keys.
    explicit GetRoomKeysJob(const QString& version);

    //! \brief Construct a URL without creating a full-fledged job object
    //!
    //! This function can be used when a URL for GetRoomKeysJob
    //! is necessary but the job itself isn't.
    static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& version);

    // Result properties

    //! A map of room IDs to room key backup data.
    QHash<RoomId, RoomKeyBackup> rooms() const
    {
        return loadFromJson<QHash<RoomId, RoomKeyBackup>>("rooms"_L1);
    }
};

inline auto collectResponse(const GetRoomKeysJob* job) { return job->rooms(); }

//! \brief Delete the keys from the backup.
//!
//! Delete the keys from the backup.
class QUOTIENT_API DeleteRoomKeysJob : public BaseJob {
public:
    //! \param version
    //!   The backup from which to delete the key
    explicit DeleteRoomKeysJob(const QString& version);

    //! \brief Construct a URL without creating a full-fledged job object
    //!
    //! This function can be used when a URL for DeleteRoomKeysJob
    //! is necessary but the job itself isn't.
    static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& version);

    // Result properties

    //! The new etag value representing stored keys in the backup.
    //! See `GET /room_keys/version/{version}` for more details.
    QString etag() const { return loadFromJson<QString>("etag"_L1); }

    //! The number of keys stored in the backup
    int count() const { return loadFromJson<int>("count"_L1); }

    struct Response {
        //! The new etag value representing stored keys in the backup.
        //! See `GET /room_keys/version/{version}` for more details.
        QString etag{};

        //! The number of keys stored in the backup
        int count{};
    };
};

template <std::derived_from<DeleteRoomKeysJob> JobT>
constexpr inline auto doCollectResponse<JobT> =
    [](JobT* j) -> DeleteRoomKeysJob::Response { return { j->etag(), j->count() }; };

} // namespace Quotient