From 3af16f1cbc516e55cfc31af5dee0bc367a9ecbae Mon Sep 17 00:00:00 2001 From: Victor Wagner Date: Sat, 20 Dec 2014 10:13:29 +0300 Subject: [PATCH] Fixed syntax of exceptions to python3 compatibility --- ctypescrypto/cipher.py | 14 +++++++------- ctypescrypto/digest.py | 12 ++++++------ ctypescrypto/rand.py | 8 ++++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ctypescrypto/cipher.py b/ctypescrypto/cipher.py index c2053e9..367f2b9 100644 --- a/ctypescrypto/cipher.py +++ b/ctypescrypto/cipher.py @@ -42,7 +42,7 @@ class CipherType: """ self.cipher = libcrypto.EVP_get_cipherbyname(cipher_name) if self.cipher is None: - raise CipherError, "Unknown cipher: %s" % cipher_name + raise CipherError("Unknown cipher: %s" % cipher_name) def __del__(self): pass @@ -113,7 +113,7 @@ class Cipher: iv_ptr = c_char_p(iv) self.ctx = libcrypto.EVP_CIPHER_CTX_new() if self.ctx == 0: - raise CipherError, "Unable to create cipher context" + raise CipherError("Unable to create cipher context") self.encrypt = encrypt if encrypt: enc = 1 @@ -137,7 +137,7 @@ class Cipher: result = libcrypto.EVP_CipherInit_ex(self.ctx, cipher_type.cipher, None, key_ptr, iv_ptr, c_int(enc)) if result == 0: self._clean_ctx() - raise CipherError, "Unable to initialize cipher" + raise CipherError("Unable to initialize cipher") self.cipher_type = cipher_type self.block_size = self.cipher_type.block_size() self.cipher_finalized = False @@ -168,9 +168,9 @@ class Cipher: called """ if self.cipher_finalized : - raise CipherError, "No updates allowed" + raise CipherError("No updates allowed") if type(data) != type(""): - raise TypeError, "A string is expected" + raise TypeError("A string is expected") if len(data) <= 0: return "" outbuf=create_string_buffer(self.block_size+len(data)) @@ -190,14 +190,14 @@ class Cipher: state, they would be processed and returned. """ if self.cipher_finalized : - raise CipherError, "Cipher operation is already completed" + raise CipherError("Cipher operation is already completed") outbuf=create_string_buffer(self.block_size) self.cipher_finalized = True outlen=c_int(0) result = libcrypto.EVP_CipherFinal_ex(self.ctx,outbuf , byref(outlen)) if result == 0: self._clean_ctx() - raise CipherError, "Unable to finalize cipher" + raise CipherError("Unable to finalize cipher") if outlen.value>0: return outbuf.raw[:outlen.value] else: diff --git a/ctypescrypto/digest.py b/ctypescrypto/digest.py index 0098ab4..5eeeaee 100644 --- a/ctypescrypto/digest.py +++ b/ctypescrypto/digest.py @@ -45,7 +45,7 @@ class DigestType: self.digest_name = digest_name self.digest = libcrypto.EVP_get_digestbyname(self.digest_name) if self.digest is None: - raise DigestError, "Unknown digest: %s" % self.digest_name + raise DigestError("Unknown digest: %s" % self.digest_name) def __del__(self): pass @@ -69,11 +69,11 @@ class Digest: self._clean_ctx() self.ctx = libcrypto.EVP_MD_CTX_create() if self.ctx == 0: - raise DigestError, "Unable to create digest context" + raise DigestError("Unable to create digest context") result = libcrypto.EVP_DigestInit_ex(self.ctx, digest_type.digest, None) if result == 0: self._clean_ctx() - raise DigestError, "Unable to initialize digest" + raise DigestError("Unable to initialize digest") self.digest_type = digest_type self.digest_size = self.digest_type.digest_size() self.block_size = self.digest_type.block_size() @@ -90,9 +90,9 @@ class Digest: otherwise only first length bytes """ if self.digest_finalized: - raise DigestError, "No updates allowed" + raise DigestError("No updates allowed") if type(data) != type(""): - raise TypeError, "A string is expected" + raise TypeError("A string is expected") if length is None: length=len(data) elif length> len(data): @@ -114,7 +114,7 @@ class Digest: length = c_long(0) result = libcrypto.EVP_DigestFinal_ex(self.ctx, self.digest_out, byref(length)) if result != 1 : - raise DigestError, "Unable to finalize digest" + raise DigestError("Unable to finalize digest") self.digest_finalized = True return self.digest_out.raw[:self.digest_size] def copy(self): diff --git a/ctypescrypto/rand.py b/ctypescrypto/rand.py index 5d51eed..f14c6f7 100644 --- a/ctypescrypto/rand.py +++ b/ctypescrypto/rand.py @@ -17,11 +17,11 @@ def bytes( num, check_result=False): """ if num <= 0 : - raise ValueError, "'num' should be > 0" + raise ValueError("'num' should be > 0") buffer = create_string_buffer(num) result = libcrypto.RAND_bytes(buffer, num) if check_result and result == 0: - raise RandError, "Random Number Generator not seeded sufficiently" + raise RandError("Random Number Generator not seeded sufficiently") return buffer.raw[:num] def pseudo_bytes(num): @@ -34,7 +34,7 @@ def pseudo_bytes(num): not for key generation etc. """ if num <= 0 : - raise ValueError, "'num' should be > 0" + raise ValueError("'num' should be > 0") buffer = create_string_buffer(num) libcrypto.RAND_pseudo_bytes(buffer, num) return buffer.raw[:num] @@ -46,7 +46,7 @@ def seed(data, entropy=None): value estimating amount of entropy in the data (in bytes). """ if type(data) != type(""): - raise TypeError, "A string is expected" + raise TypeError("A string is expected") ptr = c_char_p(data) size = len(data) if entropy is None: -- 2.39.2