mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-05 14:24:56 -04:00
Add type hints to the crypto module. (#8999)
This commit is contained in:
parent
a685bbb018
commit
1c9a850562
9 changed files with 158 additions and 113 deletions
|
@ -22,6 +22,7 @@ from signedjson.key import decode_verify_key_bytes
|
|||
|
||||
from synapse.storage._base import SQLBaseStore
|
||||
from synapse.storage.keys import FetchKeyResult
|
||||
from synapse.storage.types import Cursor
|
||||
from synapse.util.caches.descriptors import cached, cachedList
|
||||
from synapse.util.iterutils import batch_iter
|
||||
|
||||
|
@ -44,7 +45,7 @@ class KeyStore(SQLBaseStore):
|
|||
)
|
||||
async def get_server_verify_keys(
|
||||
self, server_name_and_key_ids: Iterable[Tuple[str, str]]
|
||||
) -> Dict[Tuple[str, str], Optional[FetchKeyResult]]:
|
||||
) -> Dict[Tuple[str, str], FetchKeyResult]:
|
||||
"""
|
||||
Args:
|
||||
server_name_and_key_ids:
|
||||
|
@ -56,7 +57,7 @@ class KeyStore(SQLBaseStore):
|
|||
"""
|
||||
keys = {}
|
||||
|
||||
def _get_keys(txn, batch):
|
||||
def _get_keys(txn: Cursor, batch: Tuple[Tuple[str, str]]) -> None:
|
||||
"""Processes a batch of keys to fetch, and adds the result to `keys`."""
|
||||
|
||||
# batch_iter always returns tuples so it's safe to do len(batch)
|
||||
|
@ -77,13 +78,12 @@ class KeyStore(SQLBaseStore):
|
|||
# `ts_valid_until_ms`.
|
||||
ts_valid_until_ms = 0
|
||||
|
||||
res = FetchKeyResult(
|
||||
keys[(server_name, key_id)] = FetchKeyResult(
|
||||
verify_key=decode_verify_key_bytes(key_id, bytes(key_bytes)),
|
||||
valid_until_ts=ts_valid_until_ms,
|
||||
)
|
||||
keys[(server_name, key_id)] = res
|
||||
|
||||
def _txn(txn):
|
||||
def _txn(txn: Cursor) -> Dict[Tuple[str, str], FetchKeyResult]:
|
||||
for batch in batch_iter(server_name_and_key_ids, 50):
|
||||
_get_keys(txn, batch)
|
||||
return keys
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue