diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2011-12-06 16:32:48 -0500 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2011-12-06 16:32:48 -0500 |
commit | a0f6c8902dca04de87deaebd8c042690275d1484 (patch) | |
tree | 621fb9f1c3753d8e6e3511f12257ebb597d8129a /passlib/handlers/pbkdf2.py | |
parent | c5ec1f9c49522a357075c9a0353b028f930e04ad (diff) | |
download | passlib-a0f6c8902dca04de87deaebd8c042690275d1484.tar.gz |
ran a custom 2to3 fixer to replace all u"" with u() and add an import from compat.u
Diffstat (limited to 'passlib/handlers/pbkdf2.py')
-rw-r--r-- | passlib/handlers/pbkdf2.py | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/passlib/handlers/pbkdf2.py b/passlib/handlers/pbkdf2.py index b957141..c893913 100644 --- a/passlib/handlers/pbkdf2.py +++ b/passlib/handlers/pbkdf2.py @@ -14,6 +14,7 @@ from passlib.utils import adapted_b64_encode, adapted_b64_decode, \ handlers as uh, to_hash_str, to_unicode, bytes, b from passlib.utils.compat import unicode from passlib.utils.pbkdf2 import pbkdf2 +from passlib.utils.compat import u #pkg #local __all__ = [ @@ -84,9 +85,9 @@ class Pbkdf2DigestHandler(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.Gen salt = adapted_b64_encode(self.salt).decode("ascii") if withchk and self.checksum: chk = adapted_b64_encode(self.checksum).decode("ascii") - hash = u'%s%d$%s$%s' % (self.ident, self.rounds, salt, chk) + hash = u('%s%d$%s$%s') % (self.ident, self.rounds, salt, chk) else: - hash = u'%s%d$%s' % (self.ident, self.rounds, salt) + hash = u('%s%d$%s') % (self.ident, self.rounds, salt) return to_hash_str(hash) def calc_checksum(self, secret): @@ -98,7 +99,7 @@ def create_pbkdf2_hash(hash_name, digest_size, ident=None): "create new Pbkdf2DigestHandler subclass for a specific hash" name = 'pbkdf2_' + hash_name if ident is None: - ident = u"$pbkdf2-%s$" % (hash_name,) + ident = u("$pbkdf2-%s$") % (hash_name,) prf = "hmac-%s" % (hash_name,) base = Pbkdf2DigestHandler return type(name, (base,), dict( @@ -131,7 +132,7 @@ def create_pbkdf2_hash(hash_name, digest_size, ident=None): #--------------------------------------------------------- #derived handlers #--------------------------------------------------------- -pbkdf2_sha1 = create_pbkdf2_hash("sha1", 20, ident=u"$pbkdf2$") +pbkdf2_sha1 = create_pbkdf2_hash("sha1", 20, ident=u("$pbkdf2$")) pbkdf2_sha256 = create_pbkdf2_hash("sha256", 32) pbkdf2_sha512 = create_pbkdf2_hash("sha512", 64) @@ -173,7 +174,7 @@ class cta_pbkdf2_sha1(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.Generic #--GenericHandler-- name = "cta_pbkdf2_sha1" setting_kwds = ("salt", "salt_size", "rounds") - ident = u"$p5k2$" + ident = u("$p5k2$") #NOTE: max_salt_size and max_rounds are arbitrarily chosen to provide sanity check. # underlying algorithm (and reference implementation) allow effectively unbounded values for both of these. @@ -221,10 +222,10 @@ class cta_pbkdf2_sha1(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.Generic ) def to_string(self, withchk=True): - out = u'$p5k2$%x$%s' % (self.rounds, + out = u('$p5k2$%x$%s') % (self.rounds, b64encode(self.salt, CTA_ALTCHARS).decode("ascii")) if withchk and self.checksum: - out = u"%s$%s" % (out, + out = u("%s$%s") % (out, b64encode(self.checksum, CTA_ALTCHARS).decode("ascii")) return to_hash_str(out) @@ -270,7 +271,7 @@ class dlitz_pbkdf2_sha1(uh.HasRounds, uh.HasSalt, uh.GenericHandler): #--GenericHandler-- name = "dlitz_pbkdf2_sha1" setting_kwds = ("salt", "salt_size", "rounds") - ident = u"$p5k2$" + ident = u("$p5k2$") #NOTE: max_salt_size and max_rounds are arbitrarily chosen to provide sanity check. # underlying algorithm (and reference implementation) allow effectively unbounded values for both of these. @@ -315,11 +316,11 @@ class dlitz_pbkdf2_sha1(uh.HasRounds, uh.HasSalt, uh.GenericHandler): def to_string(self, withchk=True, native=True): if self.rounds == 400: - out = u'$p5k2$$%s' % (self.salt,) + out = u('$p5k2$$%s') % (self.salt,) else: - out = u'$p5k2$%x$%s' % (self.rounds, self.salt) + out = u('$p5k2$%x$%s') % (self.rounds, self.salt) if withchk and self.checksum: - out = u"%s$%s" % (out,self.checksum) + out = u("%s$%s") % (out,self.checksum) return to_hash_str(out) if native else out #========================================================= @@ -354,7 +355,7 @@ class atlassian_pbkdf2_sha1(uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler) #--GenericHandler-- name = "atlassian_pbkdf2_sha1" setting_kwds =("salt",) - ident = u"{PKCS5S2}" + ident = u("{PKCS5S2}") checksum_size = 32 _stub_checksum = b("\x00") * 32 @@ -413,7 +414,7 @@ class grub_pbkdf2_sha512(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.Gene name = "grub_pbkdf2_sha512" setting_kwds = ("salt", "salt_size", "rounds") - ident = u"grub.pbkdf2.sha512." + ident = u("grub.pbkdf2.sha512.") #NOTE: max_salt_size and max_rounds are arbitrarily chosen to provide sanity check. # the underlying pbkdf2 specifies no bounds for either, @@ -432,7 +433,7 @@ class grub_pbkdf2_sha512(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.Gene def from_string(cls, hash): if not hash: raise ValueError("no hash specified") - rounds, salt, chk = uh.parse_mc3(hash, cls.ident, cls.name, sep=u".") + rounds, salt, chk = uh.parse_mc3(hash, cls.ident, cls.name, sep=u(".")) int_rounds = int(rounds) if rounds != str(int_rounds): #forbid zero padding, etc. raise ValueError("invalid %s hash" % (cls.name,)) @@ -449,9 +450,9 @@ class grub_pbkdf2_sha512(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.Gene salt = hexlify(self.salt).decode("ascii").upper() if withchk and self.checksum: chk = hexlify(self.checksum).decode("ascii").upper() - hash = u'%s%d.%s.%s' % (self.ident, self.rounds, salt, chk) + hash = u('%s%d.%s.%s') % (self.ident, self.rounds, salt, chk) else: - hash = u'%s%d.%s' % (self.ident, self.rounds, salt) + hash = u('%s%d.%s') % (self.ident, self.rounds, salt) return to_hash_str(hash) def calc_checksum(self, secret): |