mirror of
https://github.com/element-hq/synapse.git
synced 2024-12-22 20:50:23 +03:00
apply suggestions from PR review
This commit is contained in:
parent
e9d587d0d8
commit
0dc4c4e1ce
2 changed files with 21 additions and 16 deletions
|
@ -100,6 +100,8 @@ class E2eRoomKeysHandler(object):
|
||||||
rooms
|
rooms
|
||||||
session_id(string): session ID to delete keys for, for None to delete keys
|
session_id(string): session ID to delete keys for, for None to delete keys
|
||||||
for all sessions
|
for all sessions
|
||||||
|
Raises:
|
||||||
|
NotFoundError: if the backup version does not exist
|
||||||
Returns:
|
Returns:
|
||||||
A dict containing the count and hash for the backup version
|
A dict containing the count and hash for the backup version
|
||||||
"""
|
"""
|
||||||
|
@ -216,7 +218,7 @@ class E2eRoomKeysHandler(object):
|
||||||
if changed:
|
if changed:
|
||||||
version_hash = version_hash + 1
|
version_hash = version_hash + 1
|
||||||
yield self.store.update_e2e_room_keys_version(
|
yield self.store.update_e2e_room_keys_version(
|
||||||
user_id, version, {"hash": str(version_hash)}
|
user_id, version, None, version_hash
|
||||||
)
|
)
|
||||||
|
|
||||||
count = yield self.store.count_e2e_room_keys(user_id, version)
|
count = yield self.store.count_e2e_room_keys(user_id, version)
|
||||||
|
@ -366,10 +368,6 @@ class E2eRoomKeysHandler(object):
|
||||||
if old_info["algorithm"] != version_info["algorithm"]:
|
if old_info["algorithm"] != version_info["algorithm"]:
|
||||||
raise SynapseError(400, "Algorithm does not match", Codes.INVALID_PARAM)
|
raise SynapseError(400, "Algorithm does not match", Codes.INVALID_PARAM)
|
||||||
|
|
||||||
# don't allow the user to set the hash
|
|
||||||
if "hash" in version_info:
|
|
||||||
del version_info["hash"]
|
|
||||||
|
|
||||||
yield self.store.update_e2e_room_keys_version(
|
yield self.store.update_e2e_room_keys_version(
|
||||||
user_id, version, version_info
|
user_id, version, version_info
|
||||||
)
|
)
|
||||||
|
|
|
@ -169,7 +169,7 @@ class EndToEndRoomKeyStore(SQLBaseStore):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_e2e_room_keys_multi_txn(txn, user_id, version, room_keys):
|
def _get_e2e_room_keys_multi_txn(txn, user_id, version, room_keys):
|
||||||
if not len(room_keys):
|
if not room_keys:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
where_clauses = []
|
where_clauses = []
|
||||||
|
@ -185,6 +185,10 @@ class EndToEndRoomKeyStore(SQLBaseStore):
|
||||||
% (",".join(["?" for _ in sessions]),)
|
% (",".join(["?" for _ in sessions]),)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# check if we're actually querying something
|
||||||
|
if not where_clauses:
|
||||||
|
return {}
|
||||||
|
|
||||||
sql = """
|
sql = """
|
||||||
SELECT room_id, session_id, first_message_index, forwarded_count,
|
SELECT room_id, session_id, first_message_index, forwarded_count,
|
||||||
is_verified, session_data
|
is_verified, session_data
|
||||||
|
@ -282,6 +286,7 @@ class EndToEndRoomKeyStore(SQLBaseStore):
|
||||||
version(str)
|
version(str)
|
||||||
algorithm(str)
|
algorithm(str)
|
||||||
auth_data(object): opaque dict supplied by the client
|
auth_data(object): opaque dict supplied by the client
|
||||||
|
hash(int): tag of the keys in the backup
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _get_e2e_room_keys_version_info_txn(txn):
|
def _get_e2e_room_keys_version_info_txn(txn):
|
||||||
|
@ -351,27 +356,29 @@ class EndToEndRoomKeyStore(SQLBaseStore):
|
||||||
"create_e2e_room_keys_version_txn", _create_e2e_room_keys_version_txn
|
"create_e2e_room_keys_version_txn", _create_e2e_room_keys_version_txn
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_e2e_room_keys_version(self, user_id, version, info):
|
def update_e2e_room_keys_version(self, user_id, version, info=None, version_hash=None):
|
||||||
"""Update a given backup version
|
"""Update a given backup version
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
user_id(str): the user whose backup version we're updating
|
user_id(str): the user whose backup version we're updating
|
||||||
version(str): the version ID of the backup version we're updating
|
version(str): the version ID of the backup version we're updating
|
||||||
info(dict): the new backup version info to store
|
info(dict): the new backup version info to store
|
||||||
|
version_hash(str): tag of the keys in the backup
|
||||||
"""
|
"""
|
||||||
updatevalues = {}
|
updatevalues = {}
|
||||||
|
|
||||||
if "auth_data" in info:
|
if info and "auth_data" in info:
|
||||||
updatevalues["auth_data"] = json.dumps(info["auth_data"])
|
updatevalues["auth_data"] = json.dumps(info["auth_data"])
|
||||||
if "hash" in info:
|
if version_hash:
|
||||||
updatevalues["hash"] = info["hash"]
|
updatevalues["hash"] = version_hash
|
||||||
|
|
||||||
return self._simple_update(
|
if updatevalues:
|
||||||
table="e2e_room_keys_versions",
|
return self._simple_update(
|
||||||
keyvalues={"user_id": user_id, "version": version},
|
table="e2e_room_keys_versions",
|
||||||
updatevalues=updatevalues,
|
keyvalues={"user_id": user_id, "version": version},
|
||||||
desc="update_e2e_room_keys_version",
|
updatevalues=updatevalues,
|
||||||
)
|
desc="update_e2e_room_keys_version",
|
||||||
|
)
|
||||||
|
|
||||||
def delete_e2e_room_keys_version(self, user_id, version=None):
|
def delete_e2e_room_keys_version(self, user_id, version=None):
|
||||||
"""Delete a given backup version of the user's room keys.
|
"""Delete a given backup version of the user's room keys.
|
||||||
|
|
Loading…
Reference in a new issue