Ticket #9: aes-exception.diff
File aes-exception.diff, 2.0 KB (added by warner, at 2009-02-09T21:20:46Z) |
---|
-
pycryptopp/cipher/aesmodule.cpp
old new 116 116 } catch (CryptoPP::InvalidKeyLength le) { 117 117 PyErr_Format(aes_error, "Precondition violation: you are required to pass a valid key size. Crypto++ gave this exception: %s", le.what()); 118 118 return -1; 119 } catch (const std::exception& e) { 120 PyErr_Format(aes_error, "Crypto++ exception: %s", e.what()); 121 return -1; 119 122 } 120 123 if (!reinterpret_cast<AES*>(self)->e) { 121 124 PyErr_NoMemory(); -
pycryptopp/test/test_aes.py
old new 54 54 ct = cryptor.process("\x00"*16) 55 55 self.failUnlessEqual(self.enc0, b2a_hex(ct)) 56 56 57 def failUnlessRaises2(self, excClass, callableObj, *args, **kwargs): 58 # like TestCase.failUnlessRaises, but return the exception object 59 try: 60 callableObj(*args, **kwargs) 61 except excClass, e: 62 return e 63 else: 64 if hasattr(excClass,'__name__'): excName = excClass.__name__ 65 else: excName = str(excClass) 66 raise self.failureException, "%s not raised" % excName 67 57 68 def test_init_type_check(self): 58 self.failUnlessRaises(TypeError, aes.AES, None) 59 self.failUnlessRaises(aes.Error, aes.AES, "a") # too short 69 e = self.failUnlessRaises2(TypeError, aes.AES, None) 70 self.failUnless("AES.__init__() argument 1 must be string or read-only character buffer, not None" in str(e), str(e)) 71 e = self.failUnlessRaises2(aes.Error, aes.AES, "a") # too short 72 self.failUnless("Crypto++ exception: AES/CTR: 1 is not a valid key length" in str(e), str(e)) 60 73 61 74 def test_encrypt_zeroes_in_two_parts(self): 62 75 cryptor = aes.AES(key="\x00"*16)