From 4ce6b8d7f1c070687f0144736dd9a14b4b603b7d Mon Sep 17 00:00:00 2001 From: Legrandin Date: Fri, 11 May 2012 22:57:49 +0200 Subject: Fixes to make test suite pass for Python 2.1 and Python 3 --- lib/Crypto/Cipher/AES.py | 2 +- lib/Crypto/Cipher/DES3.py | 2 +- lib/Crypto/Protocol/AllOrNothing.py | 10 ++++++++-- lib/Crypto/SelfTest/PublicKey/test_ElGamal.py | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/Crypto/Cipher/AES.py b/lib/Crypto/Cipher/AES.py index 83ae7c5..6b31686 100644 --- a/lib/Crypto/Cipher/AES.py +++ b/lib/Crypto/Cipher/AES.py @@ -92,5 +92,5 @@ MODE_CTR = 6 #: Size of a data block (in bytes) block_size = 16 #: Size of a key (in bytes) -key_size = { 16, 24, 32 } +key_size = ( 16, 24, 32 ) diff --git a/lib/Crypto/Cipher/DES3.py b/lib/Crypto/Cipher/DES3.py index fcbe2b8..5015152 100644 --- a/lib/Crypto/Cipher/DES3.py +++ b/lib/Crypto/Cipher/DES3.py @@ -108,4 +108,4 @@ MODE_CTR = 6 #: Size of a data block (in bytes) block_size = 8 #: Size of a key (in bytes) -key_size = { 16, 24 } +key_size = ( 16, 24 ) diff --git a/lib/Crypto/Protocol/AllOrNothing.py b/lib/Crypto/Protocol/AllOrNothing.py index 4ece960..acc92d5 100644 --- a/lib/Crypto/Protocol/AllOrNothing.py +++ b/lib/Crypto/Protocol/AllOrNothing.py @@ -49,7 +49,13 @@ import sys from Crypto.Util.number import bytes_to_long, long_to_bytes from Crypto.Util.py3compat import * - +def isInt(x): + test = 0 + try: + test += x + except TypeError: + return 0 + return 1 class AllOrNothing: """Class implementing the All-or-Nothing package transform. @@ -81,7 +87,7 @@ class AllOrNothing: self.__mode = mode self.__IV = IV self.__key_size = ciphermodule.key_size - if self.__key_size == 0: + if not isInt(self.__key_size) or self.__key_size==0: self.__key_size = 16 __K0digit = bchr(0x69) diff --git a/lib/Crypto/SelfTest/PublicKey/test_ElGamal.py b/lib/Crypto/SelfTest/PublicKey/test_ElGamal.py index d199fee..cdee8cf 100644 --- a/lib/Crypto/SelfTest/PublicKey/test_ElGamal.py +++ b/lib/Crypto/SelfTest/PublicKey/test_ElGamal.py @@ -132,10 +132,10 @@ class ElGamalTest(unittest.TestCase): key = ElGamal.construct(d['key']) # Positive test res = key.verify( d['h'], (d['sig1'],d['sig2']) ) - self.assertTrue(res) + self.failUnless(res) # Negative test res = key.verify( d['h'], (d['sig1']+1,d['sig2']) ) - self.assertFalse(res) + self.failIf(res) def convert_tv(self, tv, as_longs=0): """Convert a test vector from textual form (hexadecimal ascii -- cgit v1.2.1