Skip to content

Commit

Permalink
More ValueError -> TypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
dlitz committed Oct 20, 2013
1 parent 0ae375d commit acbd4de
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/Crypto/Cipher/blockalgo.py
Expand Up @@ -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

Expand Down Expand Up @@ -363,7 +363,7 @@ def __init__(self, factory, key, *args, **kwargs):

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):
Expand Down Expand Up @@ -404,11 +404,11 @@ def __init__(self, factory, key, *args, **kwargs):
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):
Expand Down Expand Up @@ -486,7 +486,7 @@ def _start_eax(self, factory, key, *args, **kwargs):

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,
Expand Down Expand Up @@ -641,7 +641,7 @@ def update(self, assoc_data):
"""

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")
Expand Down
2 changes: 1 addition & 1 deletion lib/Crypto/Protocol/KDF.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion lib/Crypto/Signature/PKCS1_v1_5.py
Expand Up @@ -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<len(digestInfo)+11:
raise ValueError("Selected hash algorith has a too long digest (%d bytes)." % len(digest))
raise TypeError("Selected hash algorith has a too long digest (%d bytes)." % len(digest))
PS = bchr(0xFF) * (emLen - len(digestInfo) - 3)
return b("\x00\x01") + PS + bchr(0x00) + digestInfo

Expand Down

0 comments on commit acbd4de

Please sign in to comment.