Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable key backup API #693

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ if (API_GENERATION_ENABLED)
${ABS_GTAD_PATH} --config ../gtad/gtad.yaml --out ${CSAPI_DIR}
${FULL_CSAPI_SRC_DIR}
old_sync.yaml- room_initial_sync.yaml- # deprecated
key_backup.yaml- # immature and buggy in terms of API definition
sync.yaml- # we have a better handcrafted implementation
${GTAD_ARGS}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/Quotient
Expand Down
1 change: 1 addition & 0 deletions Quotient/csapi/administrative_contact.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <Quotient/csapi/definitions/request_email_validation.h>
#include <Quotient/csapi/definitions/request_msisdn_validation.h>
#include <Quotient/csapi/definitions/request_token_response.h>

#include <Quotient/jobs/basejob.h>

namespace Quotient {
Expand Down
4 changes: 2 additions & 2 deletions Quotient/csapi/content-repo.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

#pragma once

#include <Quotient/jobs/basejob.h>

#include <QtCore/QIODevice>
#include <QtNetwork/QNetworkReply>

#include <Quotient/jobs/basejob.h>

namespace Quotient {

/*! \brief Upload some content to the content repository.
Expand Down
1 change: 1 addition & 0 deletions Quotient/csapi/cross_signing.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <Quotient/csapi/definitions/auth_data.h>
#include <Quotient/csapi/definitions/cross_signing_key.h>

#include <Quotient/jobs/basejob.h>

namespace Quotient {
Expand Down
49 changes: 49 additions & 0 deletions Quotient/csapi/definitions/key_backup_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/******************************************************************************
* THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
*/

#pragma once

#include <Quotient/converters.h>

namespace Quotient {
/// The key data
struct KeyBackupData {
/// The index of the first message in the session that the key can decrypt.
int firstMessageIndex;

/// The number of times this key has been forwarded via key-sharing between
/// devices.
int forwardedCount;

/// Whether the device backing up the key verified the device that the key
/// is from.
bool isVerified;

/// 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 sessionData;
};

template <>
struct JsonObjectConverter<KeyBackupData> {
static void dumpTo(QJsonObject& jo, const KeyBackupData& pod)
{
addParam<>(jo, QStringLiteral("first_message_index"),
pod.firstMessageIndex);
addParam<>(jo, QStringLiteral("forwarded_count"), pod.forwardedCount);
addParam<>(jo, QStringLiteral("is_verified"), pod.isVerified);
addParam<>(jo, QStringLiteral("session_data"), pod.sessionData);
}
static void fillFrom(const QJsonObject& jo, KeyBackupData& pod)
{
fillFromJson(jo.value("first_message_index"_ls), pod.firstMessageIndex);
fillFromJson(jo.value("forwarded_count"_ls), pod.forwardedCount);
fillFromJson(jo.value("is_verified"_ls), pod.isVerified);
fillFromJson(jo.value("session_data"_ls), pod.sessionData);
}
};

} // namespace Quotient
3 changes: 2 additions & 1 deletion Quotient/csapi/definitions/push_rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

#pragma once

#include <Quotient/converters.h>
#include <Quotient/csapi/definitions/push_condition.h>

#include <Quotient/converters.h>

namespace Quotient {

struct PushRule {
Expand Down
3 changes: 2 additions & 1 deletion Quotient/csapi/definitions/push_ruleset.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

#pragma once

#include <Quotient/converters.h>
#include <Quotient/csapi/definitions/push_rule.h>

#include <Quotient/converters.h>

namespace Quotient {

struct PushRuleset {
Expand Down
3 changes: 2 additions & 1 deletion Quotient/csapi/definitions/room_event_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

#pragma once

#include <Quotient/converters.h>
#include <Quotient/csapi/definitions/event_filter.h>

#include <Quotient/converters.h>

namespace Quotient {

struct RoomEventFilter : EventFilter {
Expand Down
30 changes: 30 additions & 0 deletions Quotient/csapi/definitions/room_key_backup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/******************************************************************************
* THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
*/

#pragma once

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

#include <Quotient/converters.h>

namespace Quotient {
/// The backed up keys for a room.
struct RoomKeyBackup {
/// A map of session IDs to key data.
QHash<QString, KeyBackupData> sessions;
};

template <>
struct JsonObjectConverter<RoomKeyBackup> {
static void dumpTo(QJsonObject& jo, const RoomKeyBackup& pod)
{
addParam<>(jo, QStringLiteral("sessions"), pod.sessions);
}
static void fillFrom(const QJsonObject& jo, RoomKeyBackup& pod)
{
fillFromJson(jo.value("sessions"_ls), pod.sessions);
}
};

} // namespace Quotient
3 changes: 2 additions & 1 deletion Quotient/csapi/definitions/sync_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

#pragma once

#include <Quotient/converters.h>
#include <Quotient/csapi/definitions/event_filter.h>
#include <Quotient/csapi/definitions/room_event_filter.h>

#include <Quotient/converters.h>

namespace Quotient {
/// Filters to be applied to room data.
struct RoomFilter {
Expand Down
3 changes: 2 additions & 1 deletion Quotient/csapi/definitions/wellknown/full.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

#pragma once

#include <Quotient/converters.h>
#include <Quotient/csapi/definitions/wellknown/homeserver.h>
#include <Quotient/csapi/definitions/wellknown/identity_server.h>

#include <Quotient/converters.h>

namespace Quotient {
/// Used by clients to determine the homeserver, identity server, and other
/// optional components they should be interacting with.
Expand Down
1 change: 1 addition & 0 deletions Quotient/csapi/device_management.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <Quotient/csapi/definitions/auth_data.h>
#include <Quotient/csapi/definitions/client_device.h>

#include <Quotient/jobs/basejob.h>

namespace Quotient {
Expand Down
1 change: 1 addition & 0 deletions Quotient/csapi/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <Quotient/csapi/definitions/sync_filter.h>

#include <Quotient/jobs/basejob.h>

namespace Quotient {
Expand Down
1 change: 1 addition & 0 deletions Quotient/csapi/joining.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <Quotient/csapi/definitions/third_party_signed.h>

#include <Quotient/jobs/basejob.h>

namespace Quotient {
Expand Down
Loading