From 9f0430a6da8a1de6916edba0b41411e9b0d68cc5 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 4 Jan 2021 11:56:17 +0200 Subject: [PATCH] Improve types. --- etebase_fastapi/routers/authentication.py | 2 +- etebase_fastapi/utils.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/etebase_fastapi/routers/authentication.py b/etebase_fastapi/routers/authentication.py index be6a7e8..f8628b2 100644 --- a/etebase_fastapi/routers/authentication.py +++ b/etebase_fastapi/routers/authentication.py @@ -125,7 +125,7 @@ def get_login_user(request: Request, challenge: LoginChallengeIn) -> UserType: raise AuthenticationFailed(code="user_not_found", detail="User not found") -def get_encryption_key(salt): +def get_encryption_key(salt: bytes): key = nacl.hash.blake2b(settings.SECRET_KEY.encode(), encoder=nacl.encoding.RawEncoder) return nacl.hash.blake2b( b"", diff --git a/etebase_fastapi/utils.py b/etebase_fastapi/utils.py index c9db61c..9f915e2 100644 --- a/etebase_fastapi/utils.py +++ b/etebase_fastapi/utils.py @@ -50,21 +50,21 @@ def is_collection_admin(collection, user): return (member is not None) and (member.accessLevel == AccessLevels.ADMIN) -def msgpack_encode(content): +def msgpack_encode(content) -> bytes: ret = msgpack.packb(content, use_bin_type=True) assert ret is not None return ret -def msgpack_decode(content): +def msgpack_decode(content: bytes): return msgpack.unpackb(content, raw=False) -def b64encode(value): +def b64encode(value: bytes): return base64.urlsafe_b64encode(value).decode("ascii").strip("=") -def b64decode(data): +def b64decode(data: str): data += "=" * ((4 - len(data) % 4) % 4) return base64.urlsafe_b64decode(data)