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('