Refactors Cryptographer to remove logs and avoid multi return types

Cryptographer now uses exceptions to report errors and does not use the log anymore
This commit is contained in:
Sergi Delgado Segura
2020-04-09 17:57:40 +02:00
parent b4ea005f55
commit 08701f0fee
12 changed files with 98 additions and 181 deletions

View File

@@ -1,5 +1,6 @@
from common.tools import is_compressed_pk
from common.cryptographer import Cryptographer
from common.exceptions import InvalidParameter, InvalidKey, SignatureError
class NotEnoughSlots(ValueError):
@@ -71,7 +72,7 @@ class Gatekeeper:
:obj:`IdentificationFailure`: if the user cannot be identified.
"""
if isinstance(message, bytes) and isinstance(signature, str):
try:
rpk = Cryptographer.recover_pk(message, signature)
compressed_pk = Cryptographer.get_compressed_pk(rpk)
@@ -80,7 +81,7 @@ class Gatekeeper:
else:
raise IdentificationFailure("User not found.")
else:
except (InvalidParameter, InvalidKey, SignatureError):
raise IdentificationFailure("Wrong message or signature.")
def fill_slots(self, user_pk, n):