summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2020-10-06 15:17:58 -0400
committerEli Collins <elic@assurancetechnologies.com>2020-10-06 15:17:58 -0400
commitb4bdc30c6309a107d0457d39c215f9000c03c052 (patch)
tree8d4f7ef4b80e93b113b963093065b02e6c15a2d0
parent6ff2625d8f297b2e28aa53183734a00e61d93c09 (diff)
downloadpasslib-b4bdc30c6309a107d0457d39c215f9000c03c052.tar.gz
cleanup old python compat -- removed str_to_usascii() wrapper
-rw-r--r--passlib/handlers/bcrypt.py5
-rw-r--r--passlib/handlers/digests.py3
-rw-r--r--passlib/handlers/django.py5
-rw-r--r--passlib/handlers/mysql.py5
-rw-r--r--passlib/handlers/oracle.py3
-rw-r--r--passlib/handlers/postgres.py3
-rw-r--r--passlib/tests/test_context.py5
-rw-r--r--passlib/tests/test_utils_handlers.py7
-rw-r--r--passlib/utils/compat/__init__.py7
-rw-r--r--passlib/utils/handlers.py2
10 files changed, 17 insertions, 28 deletions
diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py
index 0a277e1..1c51924 100644
--- a/passlib/handlers/bcrypt.py
+++ b/passlib/handlers/bcrypt.py
@@ -29,7 +29,6 @@ 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 str_to_uascii
import passlib.utils.handlers as uh
# local
@@ -688,7 +687,7 @@ class _BcryptorBackend(_BcryptCommon):
hash = _bcryptor.engine.Engine(False).hash_key(secret, config)
if not hash.startswith(config) or len(hash) != len(config) + 31:
raise uh.exc.CryptBackendError(self, config, hash, source="bcryptor library")
- return str_to_uascii(hash[-31:])
+ return hash[-31:]
#-----------------------------------------------------------------------
# pybcrypt backend
@@ -756,7 +755,7 @@ class _PyBcryptBackend(_BcryptCommon):
hash = _pybcrypt.hashpw(secret, config)
if not hash.startswith(config) or len(hash) != len(config) + 31:
raise uh.exc.CryptBackendError(self, config, hash, source="pybcrypt library")
- return str_to_uascii(hash[-31:])
+ return hash[-31:]
_calc_checksum = _calc_checksum_raw
diff --git a/passlib/handlers/digests.py b/passlib/handlers/digests.py
index a7add53..d9bf283 100644
--- a/passlib/handlers/digests.py
+++ b/passlib/handlers/digests.py
@@ -9,7 +9,6 @@ import logging; log = logging.getLogger(__name__)
# site
# pkg
from passlib.utils import to_native_str, to_bytes, render_bytes, consteq
-from passlib.utils.compat import str_to_uascii
import passlib.utils.handlers as uh
from passlib.crypto.digest import lookup_hash
# local
@@ -47,7 +46,7 @@ class HexDigestHash(uh.StaticHandler):
def _calc_checksum(self, secret):
if isinstance(secret, str):
secret = secret.encode("utf-8")
- return str_to_uascii(self._hash_func(secret).hexdigest())
+ return self._hash_func(secret).hexdigest()
#===================================================================
# eoc
diff --git a/passlib/handlers/django.py b/passlib/handlers/django.py
index e8cc0ba..95d1a13 100644
--- a/passlib/handlers/django.py
+++ b/passlib/handlers/django.py
@@ -13,7 +13,6 @@ 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
from passlib.crypto.digest import pbkdf2_hmac
import passlib.utils.handlers as uh
# local
@@ -121,7 +120,7 @@ class django_salted_sha1(DjangoSaltedHash):
def _calc_checksum(self, secret):
if isinstance(secret, str):
secret = secret.encode("utf-8")
- return str_to_uascii(sha1(self.salt.encode("ascii") + secret).hexdigest())
+ return sha1(self.salt.encode("ascii") + secret).hexdigest()
class django_salted_md5(DjangoSaltedHash):
"""This class implements Django's Salted MD5 hash, and follows the :ref:`password-hash-api`.
@@ -159,7 +158,7 @@ class django_salted_md5(DjangoSaltedHash):
def _calc_checksum(self, secret):
if isinstance(secret, str):
secret = secret.encode("utf-8")
- return str_to_uascii(md5(self.salt.encode("ascii") + secret).hexdigest())
+ return md5(self.salt.encode("ascii") + secret).hexdigest()
#=============================================================================
# BCrypt
diff --git a/passlib/handlers/mysql.py b/passlib/handlers/mysql.py
index e8aa4ef..61c23dc 100644
--- a/passlib/handlers/mysql.py
+++ b/passlib/handlers/mysql.py
@@ -30,8 +30,7 @@ from warnings import warn
# site
# pkg
from passlib.utils import to_native_str
-from passlib.utils.compat import bascii_to_str, \
- byte_elem_value, str_to_uascii
+from passlib.utils.compat import byte_elem_value
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -117,7 +116,7 @@ class mysql41(uh.StaticHandler):
# FIXME: no idea if mysql has a policy about handling unicode passwords
if isinstance(secret, str):
secret = secret.encode("utf-8")
- return str_to_uascii(sha1(sha1(secret).digest()).hexdigest()).upper()
+ return sha1(sha1(secret).digest()).hexdigest().upper()
#===================================================================
# eoc
diff --git a/passlib/handlers/oracle.py b/passlib/handlers/oracle.py
index 8cd01e4..92f1767 100644
--- a/passlib/handlers/oracle.py
+++ b/passlib/handlers/oracle.py
@@ -10,7 +10,6 @@ import logging; log = logging.getLogger(__name__)
# site
# pkg
from passlib.utils import to_unicode, xor_bytes
-from passlib.utils.compat import str_to_uascii
from passlib.crypto.des import des_encrypt_block
import passlib.utils.handlers as uh
# local
@@ -160,7 +159,7 @@ class oracle11(uh.HasSalt, uh.GenericHandler):
if isinstance(secret, str):
secret = secret.encode("utf-8")
chk = sha1(secret + unhexlify(self.salt.encode("ascii"))).hexdigest()
- return str_to_uascii(chk).upper()
+ return chk.upper()
#===================================================================
# eoc
diff --git a/passlib/handlers/postgres.py b/passlib/handlers/postgres.py
index aead4c1..abe7663 100644
--- a/passlib/handlers/postgres.py
+++ b/passlib/handlers/postgres.py
@@ -8,7 +8,6 @@ import logging; log = logging.getLogger(__name__)
# site
# pkg
from passlib.utils import to_bytes
-from passlib.utils.compat import str_to_uascii
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -44,7 +43,7 @@ class postgres_md5(uh.HasUserContext, uh.StaticHandler):
if isinstance(secret, str):
secret = secret.encode("utf-8")
user = to_bytes(self.user, "utf-8", param="user")
- return str_to_uascii(md5(secret + user).hexdigest())
+ return md5(secret + user).hexdigest()
#===================================================================
# eoc
diff --git a/passlib/tests/test_context.py b/passlib/tests/test_context.py
index f323080..8bb4e3e 100644
--- a/passlib/tests/test_context.py
+++ b/passlib/tests/test_context.py
@@ -15,7 +15,6 @@ from passlib import hash
from passlib.context import CryptContext, LazyCryptContext
from passlib.exc import PasslibConfigWarning, PasslibHashWarning
from passlib.utils import tick, to_unicode
-from passlib.utils.compat import str_to_uascii
import passlib.utils.handlers as uh
from passlib.tests.utils import (TestCase, set_file, TICK_RESOLUTION,
quicksleep, time_call, handler_derived_from)
@@ -1155,7 +1154,7 @@ sha512_crypt__min_rounds = 45000
from hashlib import md5
if isinstance(secret, str):
secret = secret.encode("utf-8")
- return str_to_uascii(md5(secret).hexdigest())
+ return md5(secret).hexdigest()
# calling needs_update should query callback
ctx = CryptContext([dummy])
@@ -1710,7 +1709,7 @@ class DelayHash(uh.StaticHandler):
time.sleep(self.delay)
if isinstance(secret, str):
secret = secret.encode("utf-8")
- return str_to_uascii(hashlib.sha1(b"prefix" + secret).hexdigest())
+ return hashlib.sha1(b"prefix" + secret).hexdigest()
#=============================================================================
# LazyCryptContext
diff --git a/passlib/tests/test_utils_handlers.py b/passlib/tests/test_utils_handlers.py
index 422c87d..a9c3b05 100644
--- a/passlib/tests/test_utils_handlers.py
+++ b/passlib/tests/test_utils_handlers.py
@@ -11,7 +11,6 @@ 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
import passlib.utils.handlers as uh
from passlib.tests.utils import HandlerCase, TestCase
# module
@@ -748,7 +747,8 @@ class UnsaltedHash(uh.StaticHandler):
if isinstance(secret, str):
secret = secret.encode("utf-8")
data = b"boblious" + secret
- return str_to_uascii(hashlib.sha1(data).hexdigest())
+ return hashlib.sha1(data).hexdigest()
+
class SaltedHash(uh.HasSalt, uh.GenericHandler):
"""test algorithm with a salt"""
@@ -778,7 +778,8 @@ class SaltedHash(uh.HasSalt, uh.GenericHandler):
if isinstance(secret, str):
secret = secret.encode("utf-8")
data = self.salt.encode("ascii") + secret + self.salt.encode("ascii")
- return str_to_uascii(hashlib.sha1(data).hexdigest())
+ return hashlib.sha1(data).hexdigest()
+
#=============================================================================
# test sample algorithms - really a self-test of HandlerCase
diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py
index a4d344f..de69419 100644
--- a/passlib/utils/compat/__init__.py
+++ b/passlib/utils/compat/__init__.py
@@ -43,7 +43,7 @@ __all__ = [
# unicode/bytes types & helpers
'bascii_to_str',
- 'str_to_uascii', 'str_to_bascii',
+ 'str_to_bascii',
'join_unicode', 'join_bytes',
'join_byte_values', 'join_byte_elems',
'byte_elem_value',
@@ -82,10 +82,6 @@ if True: # legacy PY3 indent
assert isinstance(s, bytes)
return s.decode("ascii")
- def str_to_uascii(s):
- assert isinstance(s, str)
- return s
-
def str_to_bascii(s):
assert isinstance(s, str)
return s.encode("ascii")
@@ -107,7 +103,6 @@ if True: # legacy PY3 indent
# TODO: move docstrings to funcs...
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")
# join_byte_values -- function to convert list of ordinal integers to byte string.
diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py
index 6ea222a..d16b7e5 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, \
- join_unicode, str_to_uascii, \
+ join_unicode, \
join_unicode, unicode_or_bytes, int_types
from passlib.utils.decor import classproperty, deprecated_method
# local