diff options
author | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-02-16 11:27:24 -0800 |
---|---|---|
committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-02-16 11:54:33 -0800 |
commit | 6e3d2bdcc0e2a97f56f69c77b8acd1fbd80eaa45 (patch) | |
tree | b6508889a8fbc44c6661640663684fe4658cc6d5 | |
parent | db52ac71e804e85ace3edd772d2e78055972ac2c (diff) | |
download | pycrypto-6e3d2bdcc0e2a97f56f69c77b8acd1fbd80eaa45.tar.gz |
Fix RSA object serialization: Python 3 compatibility
-rw-r--r-- | lib/Crypto/SelfTest/PublicKey/test_RSA.py | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/Crypto/SelfTest/PublicKey/test_RSA.py b/lib/Crypto/SelfTest/PublicKey/test_RSA.py index e0d1c0a..2884317 100644 --- a/lib/Crypto/SelfTest/PublicKey/test_RSA.py +++ b/lib/Crypto/SelfTest/PublicKey/test_RSA.py @@ -209,13 +209,15 @@ class RSATest(unittest.TestCase): ciphertext2 = rsaObj.encrypt(plaintext, b("")) self.assertEqual(ciphertext1, ciphertext2) - def test_serialization_compat(self): - """RSA (default implementation) backward compatibility serialization""" - rsaObj = pickle.loads(self.pickled_key_2_3) - plaintext = a2b_hex(self.plaintext) - ciphertext = a2b_hex(self.ciphertext) - ciphertext_result = rsaObj.encrypt(plaintext, b(""))[0] - self.assertEqual(ciphertext_result, ciphertext) + if not (3, 0) <= sys.version_info < (3, 1, 2, 'final', 0): + # Unpickling is broken in Python 3 before 3.1.2 due to http://bugs.python.org/issue6137 + def test_serialization_compat(self): + """RSA (default implementation) backward compatibility serialization""" + rsaObj = pickle.loads(b(self.pickled_key_2_3)) + plaintext = a2b_hex(self.plaintext) + ciphertext = a2b_hex(self.ciphertext) + ciphertext_result = rsaObj.encrypt(plaintext, b(""))[0] + self.assertEqual(ciphertext_result, ciphertext) def _check_private_key(self, rsaObj): # Check capabilities @@ -397,10 +399,12 @@ class RSAFastMathTest(RSATest): """ RSATest.test_serialization(self) - def test_serialization_compat(self): - """RSA (_fastmath implementation) backward compatibility serialization - """ - RSATest.test_serialization_compat(self) + if not (3, 0) <= sys.version_info < (3, 1, 2, 'final', 0): + # Unpickling is broken in Python 3 before 3.1.2 due to http://bugs.python.org/issue6137 + def test_serialization_compat(self): + """RSA (_fastmath implementation) backward compatibility serialization + """ + RSATest.test_serialization_compat(self) class RSASlowMathTest(RSATest): @@ -443,10 +447,12 @@ class RSASlowMathTest(RSATest): """RSA (_slowmath implementation) serialize/unserialize key""" RSATest.test_serialization(self) - def test_serialization_compat(self): - """RSA (_slowmath implementation) backward compatibility serialization - """ - RSATest.test_serialization_compat(self) + if not (3, 0) <= sys.version_info < (3, 1, 2, 'final', 0): + # Unpickling is broken in Python 3 before 3.1.2 due to http://bugs.python.org/issue6137 + def test_serialization_compat(self): + """RSA (_slowmath implementation) backward compatibility serialization + """ + RSATest.test_serialization_compat(self) def get_tests(config={}): tests = [] |