summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2020-10-06 15:21:10 -0400
committerEli Collins <elic@assurancetechnologies.com>2020-10-06 15:21:10 -0400
commitd212a5f864ac6bfae00f07ad0986fddacef78a98 (patch)
treea5f5264c82f7ba583196b0c5a4b6e003e9905f0f
parentb4bdc30c6309a107d0457d39c215f9000c03c052 (diff)
downloadpasslib-d212a5f864ac6bfae00f07ad0986fddacef78a98.tar.gz
cleanup old python compat -- removed byte_elem_value() wrapper
-rw-r--r--passlib/crypto/des.py2
-rw-r--r--passlib/handlers/des_crypt.py5
-rw-r--r--passlib/handlers/mysql.py3
-rw-r--r--passlib/handlers/sha2_crypt.py3
-rw-r--r--passlib/handlers/sun_md5_crypt.py4
-rw-r--r--passlib/totp.py5
-rw-r--r--passlib/utils/__init__.py4
-rw-r--r--passlib/utils/compat/__init__.py5
8 files changed, 12 insertions, 19 deletions
diff --git a/passlib/crypto/des.py b/passlib/crypto/des.py
index 32fbf91..8f9d2f8 100644
--- a/passlib/crypto/des.py
+++ b/passlib/crypto/des.py
@@ -47,7 +47,7 @@ The netbsd des-crypt implementation has some nice notes on how this all works -
import struct
# pkg
from passlib import exc
-from passlib.utils.compat import join_byte_values, byte_elem_value, int_types
+from passlib.utils.compat import join_byte_values, int_types
# local
__all__ = [
"expand_des_key",
diff --git a/passlib/handlers/des_crypt.py b/passlib/handlers/des_crypt.py
index ec13ceb..2f90e72 100644
--- a/passlib/handlers/des_crypt.py
+++ b/passlib/handlers/des_crypt.py
@@ -10,7 +10,6 @@ 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
from passlib.crypto.des import des_encrypt_int_block
import passlib.utils.handlers as uh
# local
@@ -37,8 +36,8 @@ def _crypt_secret_to_key(secret):
# but des_encrypt_int_block() would just ignore them...
##return sum(expand_7bit(byte_elem_value(c) & 0x7f) << (56-i*8)
## for i, c in enumerate(secret[:8]))
- return sum((byte_elem_value(c) & 0x7f) << (57-i*8)
- for i, c in enumerate(secret[:8]))
+ return sum((c & 0x7f) << (57-i*8) for i, c in enumerate(secret[:8]))
+
def _raw_des_crypt(secret, salt):
"""pure-python backed for des_crypt"""
diff --git a/passlib/handlers/mysql.py b/passlib/handlers/mysql.py
index 61c23dc..0958c46 100644
--- a/passlib/handlers/mysql.py
+++ b/passlib/handlers/mysql.py
@@ -30,7 +30,6 @@ from warnings import warn
# site
# pkg
from passlib.utils import to_native_str
-from passlib.utils.compat import byte_elem_value
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -77,7 +76,7 @@ class mysql323(uh.StaticHandler):
for c in secret:
if c in WHITE:
continue
- tmp = byte_elem_value(c)
+ tmp = c
nr1 ^= ((((nr1 & 63)+add)*tmp) + (nr1 << 8)) & MASK_32
nr2 = (nr2+((nr2 << 8) ^ nr1)) & MASK_32
add = (add+tmp) & MASK_32
diff --git a/passlib/handlers/sha2_crypt.py b/passlib/handlers/sha2_crypt.py
index 89baa3c..d5b89a3 100644
--- a/passlib/handlers/sha2_crypt.py
+++ b/passlib/handlers/sha2_crypt.py
@@ -10,7 +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
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -162,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!"
#===================================================================
diff --git a/passlib/handlers/sun_md5_crypt.py b/passlib/handlers/sun_md5_crypt.py
index a030b5b..b472c2e 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, str_to_bascii
+from passlib.utils.compat import str_to_bascii
import passlib.utils.handlers as uh
# local
__all__ = [
@@ -123,7 +123,7 @@ def raw_sun_md5_crypt(secret, rounds, salt):
round = 0
while round < real_rounds:
# convert last result byte string to list of byte-ints for easy access
- rval = [ byte_elem_value(c) for c in result ].__getitem__
+ rval = [c for c in result].__getitem__
# build up X bit by bit
x = 0
diff --git a/passlib/totp.py b/passlib/totp.py
index 9149503..faea4c0 100644
--- a/passlib/totp.py
+++ b/passlib/totp.py
@@ -31,7 +31,7 @@ from passlib.exc import TokenError, MalformedTokenError, InvalidTokenError, Used
from passlib.utils import (to_unicode, to_bytes, consteq,
getrandbytes, rng, SequenceMixin, xor_bytes, getrandstr)
from passlib.utils.binary import BASE64_CHARS, b32encode, b32decode
-from passlib.utils.compat import bascii_to_str, int_types, num_types, byte_elem_value
+from passlib.utils.compat import bascii_to_str, int_types, num_types
from passlib.utils.decor import hybrid_method, memoized_property
from passlib.crypto.digest import lookup_hash, compile_hmac, pbkdf2_hmac
from passlib.hash import pbkdf2_sha256
@@ -1099,8 +1099,9 @@ class TOTP(object):
assert len(digest) == digest_size, "digest_size: sanity check failed"
# derive 31-bit token value
+ # assert isinstance(digest, bytes)
assert digest_size >= 20, "digest_size: sanity check 2 failed" # otherwise 0xF+4 will run off end of hash.
- offset = byte_elem_value(digest[-1]) & 0xF
+ offset = digest[-1] & 0xF
value = _unpack_uint32(digest[offset:offset+4])[0] & 0x7fffffff
# render to decimal string, return last <digits> chars
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py
index e5ff515..aede331 100644
--- a/passlib/utils/__init__.py
+++ b/passlib/utils/__init__.py
@@ -63,7 +63,7 @@ from passlib.utils.decor import (
from passlib.exc import ExpectedStringError, ExpectedTypeError
from passlib.utils.compat import (add_doc, join_bytes, join_byte_values,
join_byte_elems,
- join_unicode, byte_elem_value,
+ join_unicode,
unicode_or_bytes,
get_method_function, PYPY)
# local
@@ -629,7 +629,7 @@ def utf8_truncate(source, index):
# loop until we find non-continuation byte
while index < end:
- if byte_elem_value(source[index]) & 0xC0 != 0x80:
+ if source[index] & 0xC0 != 0x80:
# found single-char byte, or start-char byte.
break
# else: found continuation byte.
diff --git a/passlib/utils/compat/__init__.py b/passlib/utils/compat/__init__.py
index de69419..7852ea9 100644
--- a/passlib/utils/compat/__init__.py
+++ b/passlib/utils/compat/__init__.py
@@ -46,7 +46,6 @@ __all__ = [
'str_to_bascii',
'join_unicode', 'join_bytes',
'join_byte_values', 'join_byte_elems',
- 'byte_elem_value',
'iter_byte_values',
# context helpers
@@ -88,10 +87,6 @@ if True: # legacy PY3 indent
join_byte_values = join_byte_elems = bytes
- def byte_elem_value(elem):
- assert isinstance(elem, int)
- return elem
-
def iter_byte_values(s):
assert isinstance(s, bytes)
return s