Skip to content

xtr_password_hasher.exception

Every error this library raises, all deriving from :class:PasswordHasherError.

InvalidArgumentError

InvalidArgumentError(reason: str)

Bases: PasswordHasherError, ValueError

A hasher or a config was configured with a value it cannot use.

Raised where the value is given — a bcrypt cost outside 4 to 31, a PBKDF2 iteration count below a safe floor, a hash algorithm the platform does not provide, an algorithm no hasher implements, rather than on the first hash.

Also a :class:ValueError, so code that already guards its configuration with except ValueError keeps working without learning a new exception.

Attributes:

  • reason (str) –

    What is wrong with the argument.

Record what is wrong with the argument.

InvalidPasswordError

InvalidPasswordError(length: int, max_length: int)

Bases: PasswordHasherError, ValueError

A plaintext password exceeded the length a hasher accepts.

Raised by :meth:hash when the input is longer than MAX_PASSWORD_LENGTH. Refusing an unbounded input keeps a hasher from spending unbounded work on it — a denial-of-service guard, not a policy on how long a password may be. Verifying an over-long input never raises: it simply cannot match a hash made from a bounded one, so :meth:verify returns False.

Also a :class:ValueError, so code that already guards its input with except ValueError keeps working without learning a new exception.

Attributes:

  • length (int) –

    The UTF-8 byte length of the input that was refused.

  • max_length (int) –

    The greatest UTF-8 byte length a hasher accepts.

Record the refused UTF-8 byte length and the limit it crossed.

PasswordHasherError

Bases: Exception

Base class for every error raised by this library.

Catch this to handle anything hashing can go wrong with; catch a subclass to handle one cause. Every subclass carries the data a caller needs as typed attributes and composes its own message from them.

UnknownPasswordHasherError

UnknownPasswordHasherError(looked_up: str)

Bases: PasswordHasherError, LookupError

The factory holds no hasher for the user, class or name asked for.

Raised by :meth:~xtr_password_hasher.PasswordHasherFactoryInterface.get_password_hasher when nothing in its mapping matches — no entry for the class or any of its bases, no entry for the name the user declares, and no entry for the string key given. The message names what was looked up so the fix is to add that key to the factory's mapping.

Also a :class:LookupError, so a caller may catch either this type or the built-in.

Attributes:

  • looked_up (str) –

    What was searched for — a class's qualified name, or the string key given.

Record what had no hasher, and how to fix it.