From acbd4dedc88325c4799d5f4df8a2f8bc0a040479 Mon Sep 17 00:00:00 2001 From: Dwayne Litzenberger Date: Sun, 29 Sep 2013 03:01:28 -0700 Subject: More ValueError -> TypeError --- lib/Crypto/Cipher/blockalgo.py | 12 ++++++------ lib/Crypto/Protocol/KDF.py | 2 +- lib/Crypto/Signature/PKCS1_v1_5.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Crypto/Cipher/blockalgo.py b/lib/Crypto/Cipher/blockalgo.py index f065749..ba8cfdc 100644 --- a/lib/Crypto/Cipher/blockalgo.py +++ b/lib/Crypto/Cipher/blockalgo.py @@ -289,7 +289,7 @@ def _getParameter(name, index, args, kwargs, default=None): param = kwargs.get(name) if len(args) > index: if param: - raise ValueError("Parameter '%s' is specified twice" % name) + raise TypeError("Parameter '%s' is specified twice" % name) param = args[index] return param or default @@ -363,7 +363,7 @@ class BlockAlgo: if self.mode == MODE_CCM: if self.block_size != 16: - raise ValueError("CCM mode is only available for ciphers that operate on 128 bits blocks") + raise TypeError("CCM mode is only available for ciphers that operate on 128 bits blocks") self._mac_len = kwargs.get('mac_len', 16) # t if self._mac_len not in (4, 6, 8, 10, 12, 14, 16): @@ -404,11 +404,11 @@ class BlockAlgo: def _start_gcm(self, factory, key, *args, **kwargs): if self.block_size != 16: - raise ValueError("GCM mode is only available for ciphers that operate on 128 bits blocks") + raise TypeError("GCM mode is only available for ciphers that operate on 128 bits blocks") self.nonce = _getParameter('nonce', 1, args, kwargs) if not self.nonce: - raise ValueError("MODE_GCM requires a nonce") + raise TypeError("MODE_GCM requires a nonce") self._mac_len = kwargs.get('mac_len', 16) if not (self._mac_len and 4 <= self._mac_len <= 16): @@ -486,7 +486,7 @@ class BlockAlgo: self.nonce = _getParameter('nonce', 1, args, kwargs) if not self.nonce: - raise ValueError("MODE_EAX requires a nonce") + raise TypeError("MODE_EAX requires a nonce") # Allowed transitions after initialization self._next = [self.update, self.encrypt, self.decrypt, @@ -641,7 +641,7 @@ class BlockAlgo: """ if self.mode not in (MODE_CCM, MODE_EAX, MODE_SIV, MODE_GCM): - raise ValueError("update() not supported by this mode of operation") + raise TypeError("update() not supported by this mode of operation") if self.update not in self._next: raise TypeError("update() can only be called immediately after initialization") diff --git a/lib/Crypto/Protocol/KDF.py b/lib/Crypto/Protocol/KDF.py index 0a92c15..127be0c 100644 --- a/lib/Crypto/Protocol/KDF.py +++ b/lib/Crypto/Protocol/KDF.py @@ -81,7 +81,7 @@ def PBKDF1(password, salt, dkLen, count=1000, hashAlgo=None): pHash = hashAlgo.new(password+salt) digest = pHash.digest_size if dkLen>digest: - raise ValueError("Selected hash algorithm has a too short digest (%d bytes)." % digest) + raise TypeError("Selected hash algorithm has a too short digest (%d bytes)." % digest) if len(salt)!=8: raise ValueError("Salt is not 8 bytes long.") for i in xrange(count-1): diff --git a/lib/Crypto/Signature/PKCS1_v1_5.py b/lib/Crypto/Signature/PKCS1_v1_5.py index 4ea1224..6a2e0d0 100644 --- a/lib/Crypto/Signature/PKCS1_v1_5.py +++ b/lib/Crypto/Signature/PKCS1_v1_5.py @@ -238,7 +238,7 @@ def EMSA_PKCS1_V1_5_ENCODE(hash, emLen, with_hash_parameters=True): # We need at least 11 bytes for the remaining data: 3 fixed bytes and # at least 8 bytes of padding). if emLen