summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorScott Maxwell <scott@codecobblers.com>2013-11-01 00:51:00 -0700
committerScott Maxwell <scott@codecobblers.com>2013-11-01 00:51:00 -0700
commitfee18142a58dce099dd7a9bcb93d124a539cc55c (patch)
treef2345b9f8d93211dafe3175a16aac40f4103e7df
parent8a7267beeb3435fa16c06d22c201650e1e593d89 (diff)
Fixes for Python 2.5 and Python 3.2 support
-rw-r--r--paramiko/pkey.py2
-rw-r--r--paramiko/rsakey.py2
-rw-r--r--tests/test_auth.py6
-rw-r--r--tests/test_message.py8
-rw-r--r--tests/test_packetizer.py4
-rw-r--r--tests/test_pkey.py4
-rwxr-xr-xtests/test_sftp.py5
-rw-r--r--tests/test_transport.py2
8 files changed, 14 insertions, 19 deletions
diff --git a/paramiko/pkey.py b/paramiko/pkey.py
index 4cead1c2..53361d02 100644
--- a/paramiko/pkey.py
+++ b/paramiko/pkey.py
@@ -330,7 +330,7 @@ class PKey (object):
cipher = self._CIPHER_TABLE[encryption_type]['cipher']
keysize = self._CIPHER_TABLE[encryption_type]['keysize']
mode = self._CIPHER_TABLE[encryption_type]['mode']
- salt = unhexlify(saltstr)
+ salt = unhexlify(b(saltstr))
key = util.generate_key_bytes(MD5, salt, password, keysize)
return cipher.new(key, mode, salt).decrypt(data)
diff --git a/paramiko/rsakey.py b/paramiko/rsakey.py
index 4bc94e0b..b4222a35 100644
--- a/paramiko/rsakey.py
+++ b/paramiko/rsakey.py
@@ -158,7 +158,7 @@ class RSAKey (PKey):
turn a 20-byte SHA1 hash into a blob of data as large as the key's N,
using PKCS1's \"emsa-pkcs1-v1_5\" encoding. totally bizarre.
"""
- SHA1_DIGESTINFO = unhexlify('3021300906052b0e03021a05000414')
+ SHA1_DIGESTINFO = unhexlify(b('3021300906052b0e03021a05000414'))
size = len(util.deflate_long(self.n, 0))
filler = max_byte * (size - len(SHA1_DIGESTINFO) - len(data) - 3)
return zero_byte + one_byte + filler + zero_byte + SHA1_DIGESTINFO + data
diff --git a/tests/test_auth.py b/tests/test_auth.py
index 5fd0bf5d..586289ba 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -29,13 +29,11 @@ from paramiko import Transport, ServerInterface, RSAKey, DSSKey, \
AuthenticationException
from paramiko import AUTH_FAILED, AUTH_PARTIALLY_SUCCESSFUL, AUTH_SUCCESSFUL
from paramiko import OPEN_SUCCEEDED, OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED
+from paramiko.py3compat import u
from tests.loop import LoopSocket
from tests.util import test_path
-try:
- _pwd = u'\u2022'
-except Exception:
- _pwd = '\u2022'
+_pwd = u('\u2022')
class NullServer (ServerInterface):
diff --git a/tests/test_message.py b/tests/test_message.py
index dde694f7..0aed88c2 100644
--- a/tests/test_message.py
+++ b/tests/test_message.py
@@ -28,10 +28,10 @@ from paramiko.common import *
class MessageTest (unittest.TestCase):
- __a = unhexlify('000000170760e09000000001710000000568656c6c6f000003e8') + (b('x') * 1000)
- __b = unhexlify('0100f3003f00000010687565792c64657765792c6c6f756965')
- __c = unhexlify('00000005ff0000000700f5e4d3c2b10900000001110000000700f5e4d3c2b109000000069a1b2c3d4ef7')
- __d = unhexlify('00000005ff000000051122334455ff0000000a00f00000000000000000010000000363617400000003612c62')
+ __a = unhexlify(b('000000170760e09000000001710000000568656c6c6f000003e8')) + (b('x') * 1000)
+ __b = unhexlify(b('0100f3003f00000010687565792c64657765792c6c6f756965'))
+ __c = unhexlify(b('00000005ff0000000700f5e4d3c2b10900000001110000000700f5e4d3c2b109000000069a1b2c3d4ef7'))
+ __d = unhexlify(b('00000005ff000000051122334455ff0000000a00f00000000000000000010000000363617400000003612c62'))
def test_1_encode(self):
msg = Message()
diff --git a/tests/test_packetizer.py b/tests/test_packetizer.py
index b0e8fd42..a4ada72f 100644
--- a/tests/test_packetizer.py
+++ b/tests/test_packetizer.py
@@ -55,7 +55,7 @@ class PacketizerTest (unittest.TestCase):
data = rsock.recv(100)
# 32 + 12 bytes of MAC = 44
self.assertEquals(44, len(data))
- self.assertEquals(unhexlify('439197bd5b50ac2587c2c46bc7e938c0'), data[:16])
+ self.assertEquals(unhexlify(b('439197bd5b50ac2587c2c46bc7e938c0')), data[:16])
def test_2_read (self):
rsock = LoopSocket()
@@ -66,7 +66,7 @@ class PacketizerTest (unittest.TestCase):
p.set_hexdump(True)
cipher = AES.new(zero_byte * 16, AES.MODE_CBC, x55 * 16)
p.set_inbound_cipher(cipher, 16, SHA, 12, x1f * 20)
- wsock.send(unhexlify('439197bd5b50ac2587c2c46bc7e938c090d216560d717361387c4c3dfb977de26e03b1a0c21cd641414cb459'))
+ wsock.send(unhexlify(b('439197bd5b50ac2587c2c46bc7e938c090d216560d717361387c4c3dfb977de26e03b1a0c21cd641414cb459')))
cmd, m = p.read_message()
self.assertEquals(100, cmd)
self.assertEquals(100, m.get_int())
diff --git a/tests/test_pkey.py b/tests/test_pkey.py
index 00001600..8ab21a3a 100644
--- a/tests/test_pkey.py
+++ b/tests/test_pkey.py
@@ -77,7 +77,7 @@ ADRvOqQ5R98Sxst765CAqXmRtz8vwoD96g==
-----END EC PRIVATE KEY-----
"""
-x1234 = unhexlify('01020304')
+x1234 = unhexlify(b('01020304'))
class KeyTest (unittest.TestCase):
@@ -91,7 +91,7 @@ class KeyTest (unittest.TestCase):
def test_1_generate_key_bytes(self):
from Crypto.Hash import MD5
key = util.generate_key_bytes(MD5, x1234, 'happy birthday', 30)
- exp = unhexlify('61E1F272F4C1C4561586BD322498C0E924672780F47BB37DDA7D54019E64')
+ exp = unhexlify(b('61E1F272F4C1C4561586BD322498C0E924672780F47BB37DDA7D54019E64'))
self.assertEquals(exp, key)
def test_2_load_rsa(self):
diff --git a/tests/test_sftp.py b/tests/test_sftp.py
index 64c727a6..2b434f8e 100755
--- a/tests/test_sftp.py
+++ b/tests/test_sftp.py
@@ -72,10 +72,7 @@ FOLDER = os.environ.get('TEST_FOLDER', 'temp-testing000')
sftp = None
tc = None
g_big_file_test = True
-try:
- unicode_folder = u'\u00fcnic\u00f8de'
-except SyntaxError:
- unicode_folder = '\u00fcnic\u00f8de'
+unicode_folder = u('\u00fcnic\u00f8de')
def get_sftp():
global sftp
diff --git a/tests/test_transport.py b/tests/test_transport.py
index f60c2949..22a02a8e 100644
--- a/tests/test_transport.py
+++ b/tests/test_transport.py
@@ -159,7 +159,7 @@ class TransportTest(ParamikoTest):
def test_2_compute_key(self):
self.tc.K = 123281095979686581523377256114209720774539068973101330872763622971399429481072519713536292772709507296759612401802191955568143056534122385270077606457721553469730659233569339356140085284052436697480759510519672848743794433460113118986816826624865291116513647975790797391795651716378444844877749505443714557929
- self.tc.H = unhexlify('0C8307CDE6856FF30BA93684EB0F04C2520E9ED3')
+ self.tc.H = unhexlify(b('0C8307CDE6856FF30BA93684EB0F04C2520E9ED3'))
self.tc.session_id = self.tc.H
key = self.tc._compute_key('C', 32)
self.assertEquals(b('207E66594CA87C44ECCBA3B3CD39FDDB378E6FDB0F97C54B2AA0CFBF900CD995'),