diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2012-01-18 15:57:29 -0500 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2012-01-18 15:57:29 -0500 |
| commit | 973913724910776e1691bee7bf4df0cfd3e3dbfd (patch) | |
| tree | d595c2f6baa47c7ae1e033cec53937b1d983460e /passlib | |
| parent | fd39528bcd8cd93e40bc42b1b798b2bf063d0ad8 (diff) | |
| download | passlib-973913724910776e1691bee7bf4df0cfd3e3dbfd.tar.gz | |
deprecated unused int<->bytes utils
Diffstat (limited to 'passlib')
| -rw-r--r-- | passlib/utils/__init__.py | 37 | ||||
| -rw-r--r-- | passlib/utils/des.py | 18 |
2 files changed, 13 insertions, 42 deletions
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. |
