diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2020-10-06 15:15:19 -0400 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2020-10-06 15:15:19 -0400 |
commit | 6ff2625d8f297b2e28aa53183734a00e61d93c09 (patch) | |
tree | 58aa1cdf8f9fc0d43d7a8be7ef3a6c7abc586613 | |
parent | ea6e35700e799777d24295dd9d9af2d66f6ec8fc (diff) | |
download | passlib-6ff2625d8f297b2e28aa53183734a00e61d93c09.tar.gz |
cleanup old python compat -- removed uascii_to_str() wrapper
-rw-r--r-- | passlib/handlers/argon2.py | 4 | ||||
-rw-r--r-- | passlib/handlers/bcrypt.py | 8 | ||||
-rw-r--r-- | passlib/handlers/cisco.py | 5 | ||||
-rw-r--r-- | passlib/handlers/des_crypt.py | 10 | ||||
-rw-r--r-- | passlib/handlers/django.py | 4 | ||||
-rw-r--r-- | passlib/handlers/ldap_digests.py | 3 | ||||
-rw-r--r-- | passlib/handlers/oracle.py | 4 | ||||
-rw-r--r-- | passlib/handlers/pbkdf2.py | 4 | ||||
-rw-r--r-- | passlib/handlers/phpass.py | 3 | ||||
-rw-r--r-- | passlib/handlers/sha2_crypt.py | 4 | ||||
-rw-r--r-- | passlib/handlers/sun_md5_crypt.py | 4 | ||||
-rw-r--r-- | passlib/tests/test_utils_handlers.py | 5 | ||||
-rw-r--r-- | passlib/utils/compat/__init__.py | 6 | ||||
-rw-r--r-- | passlib/utils/handlers.py | 10 |
14 files changed, 33 insertions, 41 deletions
diff --git a/passlib/handlers/argon2.py b/passlib/handlers/argon2.py index dba5b17..fb8f90a 100644 --- a/passlib/handlers/argon2.py +++ b/passlib/handlers/argon2.py @@ -29,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 bascii_to_str, uascii_to_str +from passlib.utils.compat import bascii_to_str import passlib.utils.handlers as uh # local __all__ = [ @@ -433,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, diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py index cc0dd1f..0a277e1 100644 --- a/passlib/handlers/bcrypt.py +++ b/passlib/handlers/bcrypt.py @@ -29,7 +29,7 @@ from passlib.utils import safe_crypt, repeat_string, to_bytes, parse_version, \ rng, getrandstr, test_crypt, to_unicode, \ utf8_truncate, utf8_repeat_string, crypt_accepts_bytes from passlib.utils.binary import bcrypt64 -from passlib.utils.compat import uascii_to_str, str_to_uascii +from passlib.utils.compat import str_to_uascii import passlib.utils.handlers as uh # local @@ -183,14 +183,14 @@ class _BcryptCommon(uh.SubclassBackendMixin, uh.TruncateMixin, uh.HasManyIdents, def to_string(self): hash = u"%s%02d$%s%s" % (self.ident, self.rounds, self.salt, self.checksum) - return uascii_to_str(hash) + return hash # NOTE: this should be kept separate from to_string() # so that bcrypt_sha256() can still use it, while overriding to_string() def _get_config(self, ident): """internal helper to prepare config string for backends""" config = u"%s%02d$%s" % (ident, self.rounds, self.salt) - return uascii_to_str(config) + return config #=================================================================== # migration @@ -1155,7 +1155,7 @@ class bcrypt_sha256(_wrapped_bcrypt): else: template = self._v2_template hash = template % (self.ident.strip(_UDOLLAR), self.rounds, self.salt, self.checksum) - return uascii_to_str(hash) + return hash #=================================================================== # init diff --git a/passlib/handlers/cisco.py b/passlib/handlers/cisco.py index a8e8870..07feeb9 100644 --- a/passlib/handlers/cisco.py +++ b/passlib/handlers/cisco.py @@ -13,8 +13,7 @@ from warnings import warn # pkg from passlib.utils import right_pad_string, to_unicode, repeat_string, to_bytes from passlib.utils.binary import h64 -from passlib.utils.compat import join_byte_values, \ - join_byte_elems, iter_byte_values, uascii_to_str +from passlib.utils.compat import join_byte_values, join_byte_elems, iter_byte_values import passlib.utils.handlers as uh # local __all__ = [ @@ -400,7 +399,7 @@ class cisco_type7(uh.GenericHandler): return uh.rng.randint(0, 15) def to_string(self): - return "%02d%s" % (self.salt, uascii_to_str(self.checksum)) + return "%02d%s" % (self.salt, self.checksum) def _calc_checksum(self, secret): # XXX: no idea what unicode policy is, but all examples are diff --git a/passlib/handlers/des_crypt.py b/passlib/handlers/des_crypt.py index d4dc3dc..ec13ceb 100644 --- a/passlib/handlers/des_crypt.py +++ b/passlib/handlers/des_crypt.py @@ -10,7 +10,7 @@ from warnings import warn # pkg from passlib.utils import safe_crypt, test_crypt, to_unicode from passlib.utils.binary import h64, h64big -from passlib.utils.compat import byte_elem_value, uascii_to_str +from passlib.utils.compat import byte_elem_value from passlib.crypto.des import des_encrypt_int_block import passlib.utils.handlers as uh # local @@ -185,7 +185,7 @@ class des_crypt(uh.TruncateMixin, uh.HasManyBackends, uh.HasSalt, uh.GenericHand def to_string(self): hash = u"%s%s" % (self.salt, self.checksum) - return uascii_to_str(hash) + return hash #=================================================================== # digest calculation @@ -321,7 +321,7 @@ class bsdi_crypt(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, uh.GenericHandler def to_string(self): hash = u"_%s%s%s" % (h64.encode_int24(self.rounds).decode("ascii"), self.salt, self.checksum) - return uascii_to_str(hash) + return hash #=================================================================== # validation @@ -459,7 +459,7 @@ class bigcrypt(uh.HasSalt, uh.GenericHandler): def to_string(self): hash = u"%s%s" % (self.salt, self.checksum) - return uascii_to_str(hash) + return hash def _norm_checksum(self, checksum, relaxed=False): checksum = super(bigcrypt, self)._norm_checksum(checksum, relaxed=relaxed) @@ -563,7 +563,7 @@ class crypt16(uh.TruncateMixin, uh.HasSalt, uh.GenericHandler): def to_string(self): hash = u"%s%s" % (self.salt, self.checksum) - return uascii_to_str(hash) + return hash #=================================================================== # backend diff --git a/passlib/handlers/django.py b/passlib/handlers/django.py index 889ada0..e8cc0ba 100644 --- a/passlib/handlers/django.py +++ b/passlib/handlers/django.py @@ -13,7 +13,7 @@ from passlib.handlers.bcrypt import _wrapped_bcrypt from passlib.hash import argon2, bcrypt, pbkdf2_sha1, pbkdf2_sha256 from passlib.utils import to_unicode, rng, getrandstr from passlib.utils.binary import BASE64_CHARS -from passlib.utils.compat import str_to_uascii, uascii_to_str +from passlib.utils.compat import str_to_uascii from passlib.crypto.digest import pbkdf2_hmac import passlib.utils.handlers as uh # local @@ -230,7 +230,7 @@ class django_bcrypt_sha256(_wrapped_bcrypt): def to_string(self): bhash = super(django_bcrypt_sha256, self).to_string() - return uascii_to_str(self.django_prefix) + bhash + return self.django_prefix + bhash def _calc_checksum(self, secret): if isinstance(secret, str): diff --git a/passlib/handlers/ldap_digests.py b/passlib/handlers/ldap_digests.py index 499ca6e..f4d0c7e 100644 --- a/passlib/handlers/ldap_digests.py +++ b/passlib/handlers/ldap_digests.py @@ -12,7 +12,6 @@ import re # pkg from passlib.handlers.misc import plaintext from passlib.utils import unix_crypt_schemes, to_unicode -from passlib.utils.compat import uascii_to_str from passlib.utils.decor import classproperty import passlib.utils.handlers as uh # local @@ -92,7 +91,7 @@ class _SaltedBase64DigestHelper(uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHand def to_string(self): data = self.checksum + self.salt hash = self.ident + b64encode(data).decode("ascii") - return uascii_to_str(hash) + return hash def _calc_checksum(self, secret): if isinstance(secret, str): diff --git a/passlib/handlers/oracle.py b/passlib/handlers/oracle.py index a17f370..8cd01e4 100644 --- a/passlib/handlers/oracle.py +++ b/passlib/handlers/oracle.py @@ -10,7 +10,7 @@ import logging; log = logging.getLogger(__name__) # site # pkg from passlib.utils import to_unicode, xor_bytes -from passlib.utils.compat import uascii_to_str, str_to_uascii +from passlib.utils.compat import str_to_uascii from passlib.crypto.des import des_encrypt_block import passlib.utils.handlers as uh # local @@ -154,7 +154,7 @@ class oracle11(uh.HasSalt, uh.GenericHandler): def to_string(self): chk = self.checksum hash = u"S:%s%s" % (chk.upper(), self.salt.upper()) - return uascii_to_str(hash) + return hash def _calc_checksum(self, secret): if isinstance(secret, str): diff --git a/passlib/handlers/pbkdf2.py b/passlib/handlers/pbkdf2.py index 723e458..407c2b3 100644 --- a/passlib/handlers/pbkdf2.py +++ b/passlib/handlers/pbkdf2.py @@ -10,7 +10,7 @@ import logging; log = logging.getLogger(__name__) # pkg from passlib.utils import to_unicode from passlib.utils.binary import ab64_decode, ab64_encode -from passlib.utils.compat import str_to_bascii, uascii_to_str +from passlib.utils.compat import str_to_bascii from passlib.crypto.digest import pbkdf2_hmac import passlib.utils.handlers as uh # local @@ -389,7 +389,7 @@ class atlassian_pbkdf2_sha1(uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler) def to_string(self): data = self.salt + self.checksum hash = self.ident + b64encode(data).decode("ascii") - return uascii_to_str(hash) + return hash def _calc_checksum(self, secret): # TODO: find out what crowd's policy is re: unicode diff --git a/passlib/handlers/phpass.py b/passlib/handlers/phpass.py index 6428bf2..102f9de 100644 --- a/passlib/handlers/phpass.py +++ b/passlib/handlers/phpass.py @@ -14,7 +14,6 @@ import logging; log = logging.getLogger(__name__) # site # pkg from passlib.utils.binary import h64 -from passlib.utils.compat import uascii_to_str import passlib.utils.handlers as uh # local __all__ = [ @@ -109,7 +108,7 @@ class phpass(uh.HasManyIdents, uh.HasRounds, uh.HasSalt, uh.GenericHandler): h64.encode_int6(self.rounds).decode("ascii"), self.salt, self.checksum or u'') - return uascii_to_str(hash) + return hash #=================================================================== # backend diff --git a/passlib/handlers/sha2_crypt.py b/passlib/handlers/sha2_crypt.py index 0b3eead..89baa3c 100644 --- a/passlib/handlers/sha2_crypt.py +++ b/passlib/handlers/sha2_crypt.py @@ -10,7 +10,7 @@ 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, uascii_to_str +from passlib.utils.compat import byte_elem_value import passlib.utils.handlers as uh # local __all__ = [ @@ -343,7 +343,7 @@ class _SHA2_Common(uh.HasManyBackends, uh.HasRounds, uh.HasSalt, else: hash = u"%srounds=%d$%s$%s" % (self.ident, self.rounds, self.salt, self.checksum or u'') - return uascii_to_str(hash) + return hash #=================================================================== # backends diff --git a/passlib/handlers/sun_md5_crypt.py b/passlib/handlers/sun_md5_crypt.py index 394a573..a030b5b 100644 --- a/passlib/handlers/sun_md5_crypt.py +++ b/passlib/handlers/sun_md5_crypt.py @@ -19,7 +19,7 @@ from warnings import warn # pkg from passlib.utils import to_unicode from passlib.utils.binary import h64 -from passlib.utils.compat import byte_elem_value, uascii_to_str, str_to_bascii +from passlib.utils.compat import byte_elem_value, str_to_bascii import passlib.utils.handlers as uh # local __all__ = [ @@ -336,7 +336,7 @@ class sun_md5_crypt(uh.HasRounds, uh.HasSalt, uh.GenericHandler): if _withchk: chk = self.checksum hash = u"%s$%s" % (hash, chk) - return uascii_to_str(hash) + return hash #=================================================================== # primary interface diff --git a/passlib/tests/test_utils_handlers.py b/passlib/tests/test_utils_handlers.py index 8527304..422c87d 100644 --- a/passlib/tests/test_utils_handlers.py +++ b/passlib/tests/test_utils_handlers.py @@ -11,8 +11,7 @@ import warnings # pkg from passlib.hash import ldap_md5, sha256_crypt from passlib.exc import MissingBackendError, PasslibHashWarning -from passlib.utils.compat import str_to_uascii, \ - uascii_to_str +from passlib.utils.compat import str_to_uascii import passlib.utils.handlers as uh from passlib.tests.utils import HandlerCase, TestCase # module @@ -773,7 +772,7 @@ class SaltedHash(uh.HasSalt, uh.GenericHandler): def to_string(self): hash = u"@salt%s%s" % (self.salt, self.checksum) - return uascii_to_str(hash) + return hash def _calc_checksum(self, secret): if isinstance(secret, str): diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py index 0996377..a4d344f 100644 --- a/passlib/utils/compat/__init__.py +++ b/passlib/utils/compat/__init__.py @@ -42,7 +42,7 @@ __all__ = [ 'unicode_or_bytes', # unicode/bytes types & helpers - 'uascii_to_str', 'bascii_to_str', + 'bascii_to_str', 'str_to_uascii', 'str_to_bascii', 'join_unicode', 'join_bytes', 'join_byte_values', 'join_byte_elems', @@ -77,9 +77,6 @@ join_unicode = u''.join join_bytes = b''.join if True: # legacy PY3 indent - def uascii_to_str(s): - assert isinstance(s, str) - return s def bascii_to_str(s): assert isinstance(s, bytes) @@ -109,7 +106,6 @@ if True: # legacy PY3 indent return (bytes([c]) for c in s) # TODO: move docstrings to funcs... -add_doc(uascii_to_str, "helper to convert ascii unicode -> native str") add_doc(bascii_to_str, "helper to convert ascii bytes -> native str") add_doc(str_to_uascii, "helper to convert ascii native str -> unicode") add_doc(str_to_bascii, "helper to convert ascii native str -> bytes") diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py index c5b0bf9..6ea222a 100644 --- a/passlib/utils/handlers.py +++ b/passlib/utils/handlers.py @@ -27,7 +27,7 @@ from passlib.utils.binary import ( ALL_BYTE_VALUES, ) from passlib.utils.compat import join_byte_values, \ - uascii_to_str, join_unicode, str_to_uascii, \ + join_unicode, str_to_uascii, \ join_unicode, unicode_or_bytes, int_types from passlib.utils.decor import classproperty, deprecated_method # local @@ -283,7 +283,7 @@ def render_mc2(ident, salt, checksum, sep=u"$"): parts = [ident, salt, sep, checksum] else: parts = [ident, salt] - return uascii_to_str(join_unicode(parts)) + return join_unicode(parts) def render_mc3(ident, rounds, salt, checksum, sep=u"$", rounds_base=10): """format hash using 3-part modular crypt format; inverse of parse_mc3() @@ -312,7 +312,7 @@ def render_mc3(ident, rounds, salt, checksum, sep=u"$", rounds_base=10): parts = [ident, rounds, sep, salt, sep, checksum] else: parts = [ident, rounds, sep, salt] - return uascii_to_str(join_unicode(parts)) + return join_unicode(parts) def mask_value(value, show=4, pct=0.125, char=u"*"): @@ -964,7 +964,7 @@ class StaticHandler(GenericHandler): return hash def to_string(self): - return uascii_to_str(self._hash_prefix + self.checksum) + return self._hash_prefix + self.checksum #============================================================================= # GenericHandler mixin classes @@ -2611,7 +2611,7 @@ class PrefixWrapper(object): if not hash.startswith(orig_prefix): raise exc.InvalidHashError(self.wrapped) wrapped = self.prefix + hash[len(orig_prefix):] - return uascii_to_str(wrapped) + return wrapped #: set by _using(), helper for test harness' handler_derived_from() _derived_from = None |