From 0719e80fbd3a37abb8c85da551772589e3d0b742 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Fri, 31 Oct 2014 22:08:51 +0800 Subject: [PATCH] fix python 3.* --- shadowsocks/crypto/ctypes_openssl.py | 14 ++++++++------ shadowsocks/utils.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/shadowsocks/crypto/ctypes_openssl.py b/shadowsocks/crypto/ctypes_openssl.py index 7707639..7c9254a 100644 --- a/shadowsocks/crypto/ctypes_openssl.py +++ b/shadowsocks/crypto/ctypes_openssl.py @@ -68,7 +68,9 @@ def load_openssl(): def load_cipher(cipher_name): - func_name = 'EVP_' + cipher_name.replace('-', '_') + func_name = b'EVP_' + cipher_name.replace(b'-', b'_') + if bytes != str: + func_name = str(func_name, 'utf-8') cipher = getattr(libcrypto, func_name, None) if cipher: cipher.restype = c_void_p @@ -163,14 +165,14 @@ def test(): # decipher = M2Crypto.EVP.Cipher('aes_128_cfb', 'k' * 32, 'i' * 16, 0, # key_as_bytes=0, d='md5', salt=None, i=1, # padding=1) - cipher = CtypesCrypto('aes-128-cfb', b'k' * 32, b'i' * 16, 1) - decipher = CtypesCrypto('aes-128-cfb', b'k' * 32, b'i' * 16, 0) + cipher = CtypesCrypto(b'aes-128-cfb', b'k' * 32, b'i' * 16, 1) + decipher = CtypesCrypto(b'aes-128-cfb', b'k' * 32, b'i' * 16, 0) # cipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1) # decipher = Salsa20Cipher('salsa20-ctr', 'k' * 32, 'i' * 8, 1) results = [] pos = 0 - print('salsa20 test start') + print('openssl test start') start = time.time() while pos < len(plain): l = random.randint(100, 32768) @@ -178,7 +180,7 @@ def test(): results.append(c) pos += l pos = 0 - c = ''.join(results) + c = b''.join(results) results = [] while pos < len(plain): l = random.randint(100, 32768) @@ -186,7 +188,7 @@ def test(): pos += l end = time.time() print('speed: %d bytes/s' % (BLOCK_SIZE * rounds / (end - start))) - assert ''.join(results) == plain + assert b''.join(results) == plain if __name__ == '__main__': diff --git a/shadowsocks/utils.py b/shadowsocks/utils.py index 87b2c92..88b7f5b 100644 --- a/shadowsocks/utils.py +++ b/shadowsocks/utils.py @@ -87,7 +87,7 @@ def check_config(config): def get_config(is_local): logging.basicConfig(level=logging.INFO, - format='%(levelname)-s: %(message)s', filemode='a+') + format='%(levelname)-s: %(message)s') if is_local: shortopts = 'hs:b:p:k:l:m:c:t:vq' longopts = ['fast-open']