diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2012-04-11 17:49:09 -0400 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2012-04-11 17:49:09 -0400 |
commit | 5bd6deb8144cb24caa51e82c7682f706ecc09a6c (patch) | |
tree | 0eca5ec7a8a145cb3e166a9a75b95b393e9d417d /passlib/handlers/postgres.py | |
parent | 157d4806512b2586c1a0fd5ee57e8c167e506f3e (diff) | |
download | passlib-5bd6deb8144cb24caa51e82c7682f706ecc09a6c.tar.gz |
clarify behavior for secret=None and hash=None
* passing a non-string secret or non-string hash to any
CryptContext or handler method will now reliably result
in a TypeError.
previously, passing hash=None to many handler identify() and verify()
methods would return False, while others would raise a TypeError.
other handler methods would alternately throw ValueError or TypeError
when passed a value that wasn't unicode or bytes.
the various CryptContext methods also behaved inconsistently,
depending on the behavior of the underlying handler.
all of these behaviors are gone, they should all raise the same TypeError.
* redid many of the from_string() methods to verify the hash type.
* moved secret type & size validation to GenericHandler's encrypt/genhash/verify methods.
this cheaply made the secret validation global to all hashes, and lets
_calc_digest() implementations trust that the secret is valid.
* updated the CryptContext and handler unittests to verify the above behavior is adhered to.
Diffstat (limited to 'passlib/handlers/postgres.py')
-rw-r--r-- | passlib/handlers/postgres.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/passlib/handlers/postgres.py b/passlib/handlers/postgres.py index 63e7ddd..c794c19 100644 --- a/passlib/handlers/postgres.py +++ b/passlib/handlers/postgres.py @@ -45,7 +45,8 @@ class postgres_md5(uh.HasUserContext, uh.StaticHandler): # primary interface #========================================================= def _calc_checksum(self, secret): - secret = to_bytes(secret, "utf-8", errname="secret") + if isinstance(secret, unicode): + secret = secret.encode("utf-8") user = to_bytes(self.user, "utf-8", errname="user") return str_to_uascii(md5(secret + user).hexdigest()) |