From 497524b3136498b41800024d0e1c65afe0bda0bd Mon Sep 17 00:00:00 2001 From: clowwindy Date: Fri, 31 Oct 2014 19:08:00 +0800 Subject: [PATCH] drop table on Python 3 --- shadowsocks/encrypt.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/shadowsocks/encrypt.py b/shadowsocks/encrypt.py index 4997a6e..91f7439 100644 --- a/shadowsocks/encrypt.py +++ b/shadowsocks/encrypt.py @@ -34,20 +34,25 @@ from shadowsocks.crypto import m2, rc4_md5, salsa20_ctr, ctypes_openssl method_supported = {} - method_supported.update(rc4_md5.ciphers) method_supported.update(salsa20_ctr.ciphers) method_supported.update(ctypes_openssl.ciphers) # let M2Crypto override ctypes_openssl method_supported.update(m2.ciphers) +if hasattr(string, 'maketrans'): + maketrans = string.maketrans + translate = string.translate +else: + maketrans = bytes.maketrans + translate = bytes.translate + def random_string(length): try: import M2Crypto.Rand return M2Crypto.Rand.rand_bytes(length) except ImportError: - # TODO really strong enough on Linux? return os.urandom(length) @@ -60,7 +65,7 @@ def get_table(key): m.update(key) s = m.digest() (a, b) = struct.unpack('