diff options
Diffstat (limited to 'passlib/handlers/argon2.py')
-rw-r--r-- | passlib/handlers/argon2.py | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/passlib/handlers/argon2.py b/passlib/handlers/argon2.py index 4a5691b..f0c2881 100644 --- a/passlib/handlers/argon2.py +++ b/passlib/handlers/argon2.py @@ -15,7 +15,6 @@ References #============================================================================= # imports #============================================================================= -from __future__ import with_statement, absolute_import # core import logging log = logging.getLogger(__name__) @@ -30,7 +29,7 @@ from passlib import exc from passlib.crypto.digest import MAX_UINT32 from passlib.utils import classproperty, to_bytes, render_bytes from passlib.utils.binary import b64s_encode, b64s_decode -from passlib.utils.compat import u, unicode, bascii_to_str, uascii_to_str, PY2 +from passlib.utils.compat import bascii_to_str import passlib.utils.handlers as uh # local __all__ = [ @@ -49,9 +48,9 @@ __all__ = [ #: argon2 type constants -- subclasses handle mapping these to backend-specific type constants. #: (should be lowercase, to match representation in hash string) -TYPE_I = u("i") -TYPE_D = u("d") -TYPE_ID = u("id") # new 2016-10-29; passlib 1.7.2 requires backends new enough for support +TYPE_I = u"i" +TYPE_D = u"d" +TYPE_ID = u"id" # new 2016-10-29; passlib 1.7.2 requires backends new enough for support #: list of all known types; first (supported) type will be used as default. ALL_TYPES = (TYPE_ID, TYPE_I, TYPE_D) @@ -284,7 +283,7 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin, digest_size = checksum_size # create variant - subcls = super(_Argon2Common, cls).using(**kwds) + subcls = super().using(**kwds) # set type if type is not None: @@ -293,7 +292,7 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin, # set checksum size relaxed = kwds.get("relaxed") if digest_size is not None: - if isinstance(digest_size, uh.native_string_types): + if isinstance(digest_size, str): digest_size = int(digest_size) # NOTE: this isn't *really* digest size minimum, but want to enforce secure minimum. subcls.checksum_size = uh.norm_integer(subcls, digest_size, min=16, max=MAX_UINT32, @@ -301,7 +300,7 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin, # set memory cost if memory_cost is not None: - if isinstance(memory_cost, uh.native_string_types): + if isinstance(memory_cost, str): memory_cost = int(memory_cost) subcls.memory_cost = subcls._norm_memory_cost(memory_cost, relaxed=relaxed) @@ -310,7 +309,7 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin, # set max threads if max_threads is not None: - if isinstance(max_threads, uh.native_string_types): + if isinstance(max_threads, str): max_threads = int(max_threads) if max_threads < 1 and max_threads != -1: raise ValueError("max_threads (%d) must be -1 (unlimited), or at least 1." % @@ -394,9 +393,9 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin, @classmethod def from_string(cls, hash): - # NOTE: assuming hash will be unicode, or use ascii-compatible encoding. - # TODO: switch to working w/ str or unicode - if isinstance(hash, unicode): + # NOTE: assuming hash will be str, or use ascii-compatible encoding. + # TODO: switch to working w/ str + if isinstance(hash, str): hash = hash.encode("utf-8") if not isinstance(hash, bytes): raise exc.ExpectedStringError(hash, "hash") @@ -434,7 +433,7 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin, # NOTE: 'keyid' param currently not supported return "$argon2%s$%sm=%d,t=%d,p=%d%s$%s$%s" % ( - uascii_to_str(self.type), + self.type, vstr, self.memory_cost, self.rounds, @@ -463,7 +462,7 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin, self.checksum_size = len(checksum) # call parent - super(_Argon2Common, self).__init__(**kwds) + super().__init__(**kwds) # init type if type is None: @@ -500,11 +499,8 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin, @classmethod def _norm_type(cls, value): # type check - if not isinstance(value, unicode): - if PY2 and isinstance(value, bytes): - value = value.decode('ascii') - else: - raise uh.exc.ExpectedTypeError(value, "str", "type") + if not isinstance(value, str): + raise uh.exc.ExpectedTypeError(value, "str", "type") # check if type is valid if value in ALL_TYPES_SET: @@ -520,7 +516,7 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin, @classmethod def _norm_version(cls, version): - if not isinstance(version, uh.int_types): + if not isinstance(version, int): raise uh.exc.ExpectedTypeError(version, "integer", "version") # minimum valid version @@ -578,7 +574,7 @@ class _Argon2Common(uh.SubclassBackendMixin, uh.ParallelismMixin, return True if self.checksum_size != cls.checksum_size: return True - return super(_Argon2Common, self)._calc_needs_update(**kwds) + return super()._calc_needs_update(**kwds) #=================================================================== # backend loading @@ -684,7 +680,7 @@ class _NoBackend(_Argon2Common): self._stub_requires_backend() # NOTE: have to use super() here so that we don't recursively # call subclass's wrapped _calc_checksum - return super(argon2, self)._calc_checksum(secret) + return super()._calc_checksum(secret) #=================================================================== # eoc |