diff options
Diffstat (limited to 'passlib/handlers/sha2_crypt.py')
-rw-r--r-- | passlib/handlers/sha2_crypt.py | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/passlib/handlers/sha2_crypt.py b/passlib/handlers/sha2_crypt.py index e6060c5..d539472 100644 --- a/passlib/handlers/sha2_crypt.py +++ b/passlib/handlers/sha2_crypt.py @@ -10,8 +10,6 @@ import logging; log = logging.getLogger(__name__) from passlib.utils import safe_crypt, test_crypt, \ repeat_string, to_unicode from passlib.utils.binary import h64 -from passlib.utils.compat import byte_elem_value, u, \ - uascii_to_str, unicode import passlib.utils.handlers as uh # local __all__ = [ @@ -86,7 +84,7 @@ def _raw_sha2_crypt(pwd, salt, rounds, use_512=False): # for details). # validate secret - if isinstance(pwd, unicode): + if isinstance(pwd, str): # XXX: not sure what official unicode policy is, using this as default pwd = pwd.encode("utf-8") assert isinstance(pwd, bytes) @@ -101,7 +99,7 @@ def _raw_sha2_crypt(pwd, salt, rounds, use_512=False): # by the handler class. # validate salt - assert isinstance(salt, unicode), "salt not unicode" + assert isinstance(salt, str), "salt not str" salt = salt.encode("ascii") salt_len = len(salt) assert salt_len < 17, "salt too large" @@ -163,7 +161,7 @@ def _raw_sha2_crypt(pwd, salt, rounds, use_512=False): #=================================================================== # digest S - used instead of salt itself when calculating digest C #=================================================================== - ds = hash_const(salt * (16 + byte_elem_value(da[0]))).digest()[:salt_len] + ds = hash_const(salt * (16 + da[0])).digest()[:salt_len] assert len(ds) == salt_len, "salt_len somehow > hash_len!" #=================================================================== @@ -246,9 +244,9 @@ def _raw_sha2_crypt(pwd, salt, rounds, use_512=False): #============================================================================= # handlers #============================================================================= -_UROUNDS = u("rounds=") -_UDOLLAR = u("$") -_UZERO = u("0") +_UROUNDS = u"rounds=" +_UDOLLAR = u"$" +_UZERO = u"0" class _SHA2_Common(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandler): @@ -278,7 +276,7 @@ class _SHA2_Common(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, implicit_rounds = False def __init__(self, implicit_rounds=None, **kwds): - super(_SHA2_Common, self).__init__(**kwds) + super().__init__(**kwds) # if user calls hash() w/ 5000 rounds, default to compact form. if implicit_rounds is None: implicit_rounds = (self.use_defaults and self.rounds == 5000) @@ -339,12 +337,12 @@ class _SHA2_Common(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, def to_string(self): if self.rounds == 5000 and self.implicit_rounds: - hash = u("%s%s$%s") % (self.ident, self.salt, - self.checksum or u('')) + hash = u"%s%s$%s" % (self.ident, self.salt, + self.checksum or u'') else: - hash = u("%srounds=%d$%s$%s") % (self.ident, self.rounds, - self.salt, self.checksum or u('')) - return uascii_to_str(hash) + hash = u"%srounds=%d$%s$%s" % (self.ident, self.rounds, + self.salt, self.checksum or u'') + return hash #=================================================================== # backends @@ -444,7 +442,7 @@ class sha256_crypt(_SHA2_Common): # class attrs #=================================================================== name = "sha256_crypt" - ident = u("$5$") + ident = u"$5$" checksum_size = 43 # NOTE: using 25/75 weighting of builtin & os_crypt backends default_rounds = 535000 @@ -511,7 +509,7 @@ class sha512_crypt(_SHA2_Common): # class attrs #=================================================================== name = "sha512_crypt" - ident = u("$6$") + ident = u"$6$" checksum_size = 86 _cdb_use_512 = True # NOTE: using 25/75 weighting of builtin & os_crypt backends |