1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
import typing
class PwdlibError(Exception):
"""
Base pwdlib error.
"""
def __init__(self, message: str) -> None:
"""
Args:
message:
The error message.
"""
self.message = message
super().__init__(message)
class HasherNotAvailable(PwdlibError):
"""
Error raised when an unavailable hash algorithm was installed.
"""
def __init__(self, hasher: str) -> None:
"""
Args:
hasher:
The unavailable hash algorithm.
"""
self.hasher = hasher
message = (
f"The {hasher} hash algorithm is not available. "
"Are you sure it's installed? "
f"Try to run `pip install pwdlib[{hasher}]`."
)
super().__init__(message)
class UnknownHashError(PwdlibError):
"""
Error raised when the hash can't be identified from the list of provided hashers.
"""
def __init__(self, hash: typing.Union[str, bytes]) -> None:
"""
Args:
hash:
The hash we failed to identify.
"""
self.hash = hash
message = (
"This hash can't be identified. "
"Make sure it's valid and that its corresponding hasher is enabled."
)
super().__init__(message)
|