diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2011-06-22 17:40:49 -0400 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2011-06-22 17:40:49 -0400 |
| commit | 4d57bdffd00d8870a186f38fca83a5d2fcbd7fc5 (patch) | |
| tree | 3a79929a7e482bd03f31d5e1be6beab1ff4c4e8c /passlib/utils | |
| parent | b1a5216d2e9cbf46f5f4500c0a8f9489f3b6d24e (diff) | |
| download | passlib-4d57bdffd00d8870a186f38fca83a5d2fcbd7fc5.tar.gz | |
StaticHandler now provides internal _norm_hash() method for subclasses to override
* enhanced StaticHandler.verify method to normalize hash unicode/bytes better
* changed various StaticHandler-derived classes to use _norm_hash() instead of re-implementing verify()
* oracle, postgres hashes now derive from StaticHandler instead of object.
Diffstat (limited to 'passlib/utils')
| -rw-r--r-- | passlib/utils/handlers.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py index d8a9c3a..cfa9381 100644 --- a/passlib/utils/handlers.py +++ b/passlib/utils/handlers.py @@ -199,16 +199,27 @@ class StaticHandler(object): raise NotImplementedError("%s subclass must implement genhash()" % (cls,)) @classmethod - def encrypt(cls, secret, **context): + def encrypt(cls, secret, *cargs, **context): + #NOTE: subclasses generally won't need to override this. config = cls.genconfig() - return cls.genhash(secret, config, **context) + return cls.genhash(secret, config, *cargs, **context) @classmethod - def verify(cls, secret, hash, **context): + def verify(cls, secret, hash, *cargs, **context): + #NOTE: subclasses generally won't need to override this. if hash is None: raise ValueError("no hash specified") - hash = to_hash_str(hash) #so equality works - return cls.genhash(secret, hash, **context) == hash + hash = cls._norm_hash(hash) + result = cls.genhash(secret, hash, *cargs, **context) + return cls._norm_hash(result) == hash + + @classmethod + def _norm_hash(cls, hash): + """[helper for verify] normalize hash for comparsion purposes""" + #NOTE: this is mainly provided for case-insenstive subclasses to override. + if isinstance(hash, bytes): + hash = hash.decode("ascii") + return hash #===================================================== #eoc |
