summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwayne Litzenberger <dlitz@dlitz.net>2013-09-29 01:06:12 -0400
committerDwayne Litzenberger <dlitz@dlitz.net>2013-10-20 13:30:22 -0700
commit0ae375d573ab5e2186664e08f9da179dbe078552 (patch)
tree310c5aba33939e7a13b599e826efc133a7beffc7
parent3e706bfc6a65efe71ea592decda651e5fd452b70 (diff)
downloadpycrypto-0ae375d573ab5e2186664e08f9da179dbe078552.tar.gz
CMAC: raise TypeError instead of ValueError when ciphermod is missing or unusable
This makes the CMAC module behave more like most Python functions do when a required argument is missing, and reserves ValueError for a MAC failure.
-rw-r--r--lib/Crypto/Hash/CMAC.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/Crypto/Hash/CMAC.py b/lib/Crypto/Hash/CMAC.py
index ac86729..107db96 100644
--- a/lib/Crypto/Hash/CMAC.py
+++ b/lib/Crypto/Hash/CMAC.py
@@ -184,7 +184,7 @@ class CMAC(_SmoothMAC):
"""
if ciphermod is None:
- raise ValueError("ciphermod must be specified (try AES)")
+ raise TypeError("ciphermod must be specified (try AES)")
_SmoothMAC.__init__(self, ciphermod.block_size, msg, 1)
@@ -197,7 +197,8 @@ class CMAC(_SmoothMAC):
elif ciphermod.block_size==16:
const_Rb = 0x87
else:
- raise ValueError("For CMAC, block length of the selected cipher must be 8 or 16 bytes")
+ raise TypeError("CMAC requires a cipher with a block size of 8 or 16 bytes, not %d" %
+ (ciphermod.block_size,))
self.digest_size = ciphermod.block_size
# Compute sub-keys