diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2011-01-19 01:35:47 +0000 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2011-01-19 01:35:47 +0000 |
| commit | 7790935a93c8d86629d65e205af4e45d6ef59897 (patch) | |
| tree | 1944dd0eb321e752e6105288870856cb17741ad0 /passlib/handler.py | |
| parent | d9f3faff01a7dc10f1d7d324ffc0868a1547cab3 (diff) | |
| download | passlib-7790935a93c8d86629d65e205af4e45d6ef59897.tar.gz | |
added CryptHandlerHelper._norm_salt
Diffstat (limited to 'passlib/handler.py')
| -rw-r--r-- | passlib/handler.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/passlib/handler.py b/passlib/handler.py index 33fbbc1..f6b4710 100644 --- a/passlib/handler.py +++ b/passlib/handler.py @@ -12,7 +12,7 @@ import time import os #site #libs -from passlib.utils import abstract_class_method, classproperty +from passlib.utils import abstract_class_method, classproperty, H64_CHARS, generate_h64_salt #pkg #local __all__ = [ @@ -322,6 +322,8 @@ class CryptHandler(object): class CryptHandlerHelper(CryptHandler): "class providing some helpful methods for implementing a crypt algorithm" + salt_chars = None #fill in with minimum number of salt chars required, and _norm_salt() will handle truncating etc + @classproperty def setting_kwds(cls): "auto-calculates setting_kwds for the 3 most common cases, autodetecting via other informational attributes" @@ -351,6 +353,23 @@ class CryptHandlerHelper(CryptHandler): rounds = mn return rounds + @classmethod + def _norm_salt(cls, salt): + count = cls.salt_chars + assert count, "cls.salt_chars not set" + if not salt: + return generate_h64_salt(count) + for c in salt: + if c not in H64_CHARS: + raise ValueError, "invalid character in %s salt: %r" % (cls.name, c) + if len(salt) < count: + raise ValueError, "%s salt must be at least %d chars" % (cls.name, count) + elif len(salt) > count: + #automatically clip things to specified number of chars + return salt[:count] + else: + return salt + #========================================================= # eof #========================================================= |
