From 0ae375d573ab5e2186664e08f9da179dbe078552 Mon Sep 17 00:00:00 2001 From: Dwayne Litzenberger Date: Sun, 29 Sep 2013 01:06:12 -0400 Subject: 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. --- lib/Crypto/Hash/CMAC.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') 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 -- cgit v1.2.1