Skip to content

Commit

Permalink
Replace assert statements with AssertionError.
Browse files Browse the repository at this point in the history
Closes #124
  • Loading branch information
aholmes committed Sep 26, 2024
1 parent 42ee6e7 commit 782c3c8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/web/Ligare/web/encryption/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def decrypt_flask_cookie(secret_key: str, cookie_str: str) -> Dict[str, Any]:

serializer = _get_serializer(secret_key)
data: Any = serializer.loads(cookie_str)
assert type(data) is dict

if type(data) is not dict:
raise AssertionError(
f"Deserialized session data is not a dictionary. It is a `{type(data)}`."
)

return data # pyright: ignore[reportUnknownVariableType]


Expand All @@ -56,5 +61,10 @@ def encrypt_flask_cookie(secret_key: str, data: Dict[str, Any] | SessionMixin) -

serializer = _get_serializer(secret_key)
cookie_str = serializer.dumps(data)
assert type(cookie_str) is str

if type(cookie_str) is not str:
raise AssertionError(
f"Serialized cookie data is not a str. It is a `{type(cookie_str)}`."
)

return cookie_str

0 comments on commit 782c3c8

Please sign in to comment.