diff options
Diffstat (limited to 'passlib/handlers/fshp.py')
-rw-r--r-- | passlib/handlers/fshp.py | 77 |
1 files changed, 38 insertions, 39 deletions
diff --git a/passlib/handlers/fshp.py b/passlib/handlers/fshp.py index fe82415..3ecb7b6 100644 --- a/passlib/handlers/fshp.py +++ b/passlib/handlers/fshp.py @@ -1,29 +1,28 @@ """passlib.handlers.fshp """ -#========================================================= -#imports -#========================================================= -#core +#============================================================================= +# imports +#============================================================================= +# core from base64 import b64encode, b64decode import re import logging; log = logging.getLogger(__name__) from warnings import warn -#site -#libs +# site +# pkg from passlib.utils import to_unicode import passlib.utils.handlers as uh from passlib.utils.compat import b, bytes, bascii_to_str, iteritems, u,\ unicode from passlib.utils.pbkdf2 import pbkdf1 -#pkg -#local +# local __all__ = [ 'fshp', ] -#========================================================= -#sha1-crypt -#========================================================= +#============================================================================= +# sha1-crypt +#============================================================================= class fshp(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler): """This class implements the FSHP password hash, and follows the :ref:`password-hash-api`. @@ -62,9 +61,9 @@ class fshp(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler): .. versionadded:: 1.6 """ - #========================================================= - #class attrs - #========================================================= + #=================================================================== + # class attrs + #=================================================================== #--GenericHandler-- name = "fshp" setting_kwds = ("salt", "salt_size", "rounds", "variant") @@ -73,22 +72,22 @@ class fshp(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler): # checksum_size is property() that depends on variant #--HasRawSalt-- - default_salt_size = 16 #current passlib default, FSHP uses 8 + default_salt_size = 16 # current passlib default, FSHP uses 8 min_salt_size = 0 max_salt_size = None #--HasRounds-- # FIXME: should probably use different default rounds # based on the variant. setting for default variant (sha256) for now. - default_rounds = 50000 #current passlib default, FSHP uses 4096 - min_rounds = 1 #set by FSHP + default_rounds = 50000 # current passlib default, FSHP uses 4096 + min_rounds = 1 # set by FSHP max_rounds = 4294967295 # 32-bit integer limit - not set by FSHP rounds_cost = "linear" #--variants-- default_variant = 1 _variant_info = { - #variant: (hash name, digest size) + # variant: (hash name, digest size) 0: ("sha1", 20), 1: ("sha256", 32), 2: ("sha384", 48), @@ -99,14 +98,14 @@ class fshp(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler): [(v[0],k) for k,v in iteritems(_variant_info)] ) - #========================================================= - #instance attrs - #========================================================= + #=================================================================== + # instance attrs + #=================================================================== variant = None - #========================================================= - #init - #========================================================= + #=================================================================== + # init + #=================================================================== def __init__(self, variant=None, **kwds): # NOTE: variant must be set first, since it controls checksum size, etc. self.use_defaults = kwds.get("use_defaults") # load this early @@ -139,9 +138,9 @@ class fshp(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler): def checksum_size(self): return self._variant_info[self.variant][1] - #========================================================= - #formatting - #========================================================= + #=================================================================== + # formatting + #=================================================================== _hash_regex = re.compile(u(r""" ^ @@ -180,16 +179,16 @@ class fshp(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler): data = bascii_to_str(b64encode(salt+chk)) return "{FSHP%d|%d|%d}%s" % (self.variant, len(salt), self.rounds, data) - #========================================================= - #backend - #========================================================= + #=================================================================== + # backend + #=================================================================== def _calc_checksum(self, secret): if isinstance(secret, unicode): secret = secret.encode("utf-8") - #NOTE: for some reason, FSHP uses pbkdf1 with password & salt reversed. - # this has only a minimal impact on security, - # but it is worth noting this deviation. + # NOTE: for some reason, FSHP uses pbkdf1 with password & salt reversed. + # this has only a minimal impact on security, + # but it is worth noting this deviation. return pbkdf1( secret=self.salt, salt=secret, @@ -198,10 +197,10 @@ class fshp(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler): hash=self.checksum_alg, ) - #========================================================= - #eoc - #========================================================= + #=================================================================== + # eoc + #=================================================================== -#========================================================= -#eof -#========================================================= +#============================================================================= +# eof +#============================================================================= |