summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--docs/lib/passlib.utils.rst2
-rw-r--r--passlib/utils/__init__.py37
-rw-r--r--passlib/utils/des.py18
4 files changed, 16 insertions, 44 deletions
diff --git a/CHANGES b/CHANGES
index 4958ebe..0534894 100644
--- a/CHANGES
+++ b/CHANGES
@@ -56,6 +56,9 @@ Release History
imported under the same name, and has (mostly) the same interface;
but should be faster, more flexible, and better unit-tested.
+ * deprecated some unused functions in :mod:`!passlib.utils`,
+ they will be removed in release 1.7.
+
Other
* Passlib is now source-compatible with Python 2.5+ and Python 3,
diff --git a/docs/lib/passlib.utils.rst b/docs/lib/passlib.utils.rst
index b052f5a..4aa97f2 100644
--- a/docs/lib/passlib.utils.rst
+++ b/docs/lib/passlib.utils.rst
@@ -45,8 +45,6 @@ Decorators
Bytes Manipulation
==================
-.. autofunction:: bytes_to_int
-.. autofunction:: int_to_bytes
.. autofunction:: xor_bytes
.. autofunction:: consteq
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py
index 0553e5d..63b87af 100644
--- a/passlib/utils/__init__.py
+++ b/passlib/utils/__init__.py
@@ -757,41 +757,9 @@ def render_bytes(source, *args):
#numeric helpers
#=================================================================================
-##def int_to_bytes(value, count=None, order="big"):
-## """encode a integer into a string of bytes
-##
-## :arg value: the integer
-## :arg count: optional number of bytes to expose, uses minimum needed if count not specified
-## :param order: the byte ordering; "big" (the default), "little", or "native"
-##
-## :raises ValueError:
-## * if count specified and integer too large to fit.
-## * if integer is negative
-##
-## :returns:
-## bytes encoding integer
-## """
-##
-##
-##def bytes_to_int(value, order="big"):
-## """decode a byte string into an integer representation of it's binary value.
-##
-## :arg value: the string to decode.
-## :param order: the byte ordering; "big" (the default), "little", or "native"
-##
-## :returns: the decoded positive integer.
-## """
-## if not value:
-## return 0
-## if order == "native":
-## order = sys.byteorder
-## if order == "little":
-## value = reversed(value)
-## out = 0
-## for v in value:
-## out = (out<<8) | ord(v)
-## return out
+# NOTE: deprecating bytes<->int in favor of just using struct module.
+@deprecated_function(deprecated="1.6", removed="1.8")
def bytes_to_int(value):
"decode string of bytes as single big-endian integer"
out = 0
@@ -799,6 +767,7 @@ def bytes_to_int(value):
out = (out<<8) | bord(v)
return out
+@deprecated_function(deprecated="1.6", removed="1.8")
def int_to_bytes(value, count):
"encodes integer into single big-endian byte string"
assert value < (1<<(8*count)), "value too large for %d bytes: %d" % (count, value)
diff --git a/passlib/utils/des.py b/passlib/utils/des.py
index c57c0e1..ea01048 100644
--- a/passlib/utils/des.py
+++ b/passlib/utils/des.py
@@ -42,10 +42,12 @@ which has some nice notes on how this all works -
#=========================================================
#imports
#=========================================================
-#pkg
-from passlib.utils import bytes_to_int, int_to_bytes, bytes, bord, bjoin_ints
+# core
+import struct
+# pkg
+from passlib.utils import bytes, bord, bjoin_ints
from passlib.utils.compat import trange, irange
-#local
+# local
__all__ = [
"expand_des_key",
"des_encrypt_block",
@@ -69,6 +71,8 @@ INT_24_MAX = 0xffffff
INT_64_MAX = 0xffffffff
INT_64_MAX = 0xffffffffffffffff
+uint64_struct = struct.Struct(">Q")
+
#=========================================================
# static tables for des
#=========================================================
@@ -616,14 +620,12 @@ def des_encrypt_block(key, input):
raise TypeError("key must be bytes, not %s" % (type(key),))
if len(key) == 7:
key = expand_des_key(key)
- assert len(key) == 8
if not isinstance(input, bytes):
raise TypeError("input must be bytes, not %s" % (type(input),))
- assert len(input) == 8
- input = bytes_to_int(input)
- key = bytes_to_int(key)
+ input = uint64_struct.unpack(input)[0]
+ key = uint64_struct.unpack(key)[0]
out = mdes_encrypt_int_block(key, input, 0, 1)
- return int_to_bytes(out, 8)
+ return uint64_struct.pack(out)
def mdes_encrypt_int_block(key, input, salt=0, rounds=1):
"""do modified multi-round DES encryption of single DES block.