diff options
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/rest/client/keys.py | 44 | ||||
-rw-r--r-- | synapse/storage/databases/main/end_to_end_keys.py | 4 |
2 files changed, 34 insertions, 14 deletions
diff --git a/synapse/rest/client/keys.py b/synapse/rest/client/keys.py index 5ba4fabbbc..8379092ac0 100644 --- a/synapse/rest/client/keys.py +++ b/synapse/rest/client/keys.py @@ -15,10 +15,20 @@ # limitations under the License. import logging -from typing import TYPE_CHECKING, Any, Optional, Tuple, Union, Dict, Sequence, TypeVar, Type +from typing import ( + TYPE_CHECKING, + Any, + Dict, + Optional, + Sequence, + Tuple, + Type, + TypeVar, + Union, +) import attr -from attr.validators import instance_of, deep_iterable, deep_mapping, optional +from attr.validators import deep_iterable, deep_mapping, instance_of, optional from synapse.api.errors import InvalidAPICallError, SynapseError from synapse.http.server import HttpServer @@ -50,11 +60,13 @@ def check_str_or_jsondict(instance: Any, attribute: str, input: Any) -> None: if isinstance(input, str): pass elif isinstance(input, dict): - for key, val in input.items(): + for key in input: if not isinstance(key, str): raise TypeError(f"{attribute} dictionary has non-string key {key}") else: - raise TypeError(f"{attribute} should be a string, or a map from strings to any type.") + raise TypeError( + f"{attribute} should be a string, or a map from strings to any type." + ) @attr.s(frozen=True, slots=True) @@ -62,19 +74,23 @@ class DeviceKeys: user_id: str = attr.ib(validator=instance_of(str)) device_id: str = attr.ib(validator=instance_of(str)) algorithms: Sequence[str] = attr.ib(validator=deep_iterable(instance_of(str))) - keys: Dict[str, str] = attr.ib(validator=deep_mapping(instance_of(str), instance_of(str))) - signatures: Signatures = attr.ib(validator=deep_mapping( - instance_of(str), deep_mapping(instance_of(str), instance_of(str)) - )) + keys: Dict[str, str] = attr.ib( + validator=deep_mapping(instance_of(str), instance_of(str)) + ) + signatures: Signatures = attr.ib( + validator=deep_mapping( + instance_of(str), deep_mapping(instance_of(str), instance_of(str)) + ) + ) @attr.s(frozen=True, slots=True, auto_attribs=True) class KeyUploadBody: - device_keys: Optional[DeviceKeys] = attr.ib(converter=attr.converters.optional(DeviceKeys)) + device_keys: Optional[DeviceKeys] = attr.ib( + converter=attr.converters.optional(DeviceKeys) + ) one_time_keys: Optional[Dict[str, Union[str, JsonDict]]] = attr.ib( - validator=optional(deep_mapping( - instance_of(str), check_str_or_jsondict - )) + validator=optional(deep_mapping(instance_of(str), check_str_or_jsondict)) ) org_matrix_msc2732_fallback_keys: Optional[Dict[str, Union[str, JsonDict]]] @@ -83,7 +99,9 @@ class KeyUploadBody: return cls( device_keys=src.get("device_keys"), one_time_keys=src.get("one_time_keys"), - org_matrix_msc2732_fallback_keys=src.get("org.matrix.msc2732.fallback.keys"), + org_matrix_msc2732_fallback_keys=src.get( + "org.matrix.msc2732.fallback.keys" + ), ) diff --git a/synapse/storage/databases/main/end_to_end_keys.py b/synapse/storage/databases/main/end_to_end_keys.py index 20e019e923..dfe48b082c 100644 --- a/synapse/storage/databases/main/end_to_end_keys.py +++ b/synapse/storage/databases/main/end_to_end_keys.py @@ -925,7 +925,9 @@ class EndToEndKeyStore(EndToEndKeyWorkerStore, SQLBaseStore): # In py3 we need old_key_json to match new_key_json type. The DB # returns unicode while encode_canonical_json returns bytes. - new_key_json = encode_canonical_json(attr.asdict(device_keys)).decode("utf-8") + new_key_json = encode_canonical_json(attr.asdict(device_keys)).decode( + "utf-8" + ) if old_key_json == new_key_json: log_kv({"Message": "Device key already stored."}) |