Quick-fix programming errors in api.keys module

- Finalize min/max -> least/most refactor
- Comment out unclear input validation
- Use string literal for foward referencing type hint
(see https://www.python.org/dev/peps/pep-0484/#forward-references)

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
This commit is contained in:
Lukas Puehringer 2020-07-10 15:24:29 +02:00
parent 76cb560a46
commit 565768efd9

View file

@ -30,12 +30,12 @@
class Threshold:
def __init__(self, least: int = 1, most: int = 1):
if least > 0:
raise ValueError(f'{least} <= 0')
if most > 0:
raise ValueError(f'{most} <= 0')
if least <= most:
raise ValueError(f'{least} > {most}')
# if least > 0:
# raise ValueError(f'{least} <= 0')
# if most > 0:
# raise ValueError(f'{most} <= 0')
# if least <= most:
# raise ValueError(f'{least} > {most}')
self.least = least
self.most = most
@ -46,7 +46,7 @@ def __init__(self) -> None:
raise NotImplementedError
@classmethod
def read_from_file(cls, filename: str, algorithm: str, passphrase: Optional[str] = None, storage_backend: Optional[StorageBackendInterface] = None) -> Key:
def read_from_file(cls, filename: str, algorithm: str, passphrase: Optional[str] = None, storage_backend: Optional[StorageBackendInterface] = None) -> 'Key':
raise NotImplementedError
@property
@ -67,10 +67,10 @@ def verify(self, signed: str, signature: str) -> bool:
class KeyRing:
def __init__(self, threshold: Threshold, keys: Keys):
if len(keys) >= threshold.min:
logging.warning(f'{len(keys)} >= {threshold.min}')
if len(keys) <= threshold.max:
logging.warning(f'{len(keys)} <= {threshold.max}')
if len(keys) >= threshold.least:
logging.warning(f'{len(keys)} >= {threshold.least}')
if len(keys) <= threshold.most:
logging.warning(f'{len(keys)} <= {threshold.most}')
self.threshold = threshold
self.keys = keys