@@ -12,37 +12,37 @@ def test_md5_vectors(self):
1212 # Test the HMAC module against test vectors from the RFC.
1313
1414 def md5test (key , data , digest ):
15- h = hmac .HMAC (key , data )
15+ h = hmac .HMAC (key , data , digestmod = hashlib . sha1 )
1616 self .assertEqual (h .hexdigest ().upper (), digest .upper ())
1717
1818 md5test (chr (0x0b ) * 16 ,
1919 "Hi There" ,
20- "9294727A3638BB1C13F48EF8158BFC9D " )
20+ "675B0B3A1B4DDF4E124872DA6C2F632BFED957E9 " )
2121
2222 md5test ("Jefe" ,
2323 "what do ya want for nothing?" ,
24- "750c783e6ab0b503eaa86e310a5db738 " )
24+ "EFFCDF6AE5EB2FA2D27416D5F184DF9C259A7C79 " )
2525
2626 md5test (chr (0xAA )* 16 ,
2727 chr (0xDD )* 50 ,
28- "56be34521d144c88dbb8c733f0e8b3f6 " )
28+ "D730594D167E35D5956FD8003D0DB3D3F46DC7BB " )
2929
3030 md5test ("" .join ([chr (i ) for i in range (1 , 26 )]),
3131 chr (0xCD ) * 50 ,
32- "697eaf0aca3a3aea3a75164746ffaa79 " )
32+ "4C9007F4026250C6BC8414F9BF50C86C2D7235DA " )
3333
3434 md5test (chr (0x0C ) * 16 ,
3535 "Test With Truncation" ,
36- "56461ef2342edc00f9bab995690efd4c " )
36+ "37268B7E21E84DA5720C53C4BA03AD1104039FA7 " )
3737
3838 md5test (chr (0xAA ) * 80 ,
3939 "Test Using Larger Than Block-Size Key - Hash Key First" ,
40- "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd " )
40+ "AA4AE5E15272D00E95705637CE8A3B55ED402112 " )
4141
4242 md5test (chr (0xAA ) * 80 ,
4343 ("Test Using Larger Than Block-Size Key "
4444 "and Larger Than One Block-Size Data" ),
45- "6f630fad67cda0ee1fb1f562db3aa53e " )
45+ "E8E99D0F45237D786D6BBAA7965C7808BBFF1A91 " )
4646
4747 def test_sha_vectors (self ):
4848 def shatest (key , data , digest ):
@@ -232,14 +232,14 @@ def test_normal(self):
232232 # Standard constructor call.
233233 failed = 0
234234 try :
235- h = hmac .HMAC ("key" )
235+ h = hmac .HMAC ("key" , digestmod = hashlib . sha1 )
236236 except :
237237 self .fail ("Standard constructor call raised exception." )
238238
239239 def test_withtext (self ):
240240 # Constructor call with text.
241241 try :
242- h = hmac .HMAC ("key" , "hash this!" )
242+ h = hmac .HMAC ("key" , "hash this!" , digestmod = hashlib . sha1 )
243243 except :
244244 self .fail ("Constructor call with text argument raised exception." )
245245
@@ -250,6 +250,11 @@ def test_withmodule(self):
250250 except :
251251 self .fail ("Constructor call with hashlib.sha1 raised exception." )
252252
253+ def test_3k_no_digest (self ):
254+ with test_support .check_py3k_warnings (("the digestmod paramemer is required in 3.x; generate a digest with hashlib module" ,
255+ DeprecationWarning )):
256+ h = hmac .HMAC ("key" , "" , hashlib .sha1 )
257+
253258class SanityTestCase (unittest .TestCase ):
254259
255260 def test_default_is_md5 (self ):
@@ -262,7 +267,7 @@ def test_exercise_all_methods(self):
262267 # Exercising all methods once.
263268 # This must not raise any exceptions
264269 try :
265- h = hmac .HMAC ("my secret key" )
270+ h = hmac .HMAC ("my secret key" , digestmod = hashlib . sha1 )
266271 h .update ("compute the hash of this text!" )
267272 dig = h .digest ()
268273 dig = h .hexdigest ()
@@ -274,7 +279,7 @@ class CopyTestCase(unittest.TestCase):
274279
275280 def test_attributes (self ):
276281 # Testing if attributes are of same type.
277- h1 = hmac .HMAC ("key" )
282+ h1 = hmac .HMAC ("key" , digestmod = hashlib . sha1 )
278283 h2 = h1 .copy ()
279284 self .assertTrue (h1 .digest_cons == h2 .digest_cons ,
280285 "digest constructors don't match." )
@@ -285,7 +290,7 @@ def test_attributes(self):
285290
286291 def test_realcopy (self ):
287292 # Testing if the copy method created a real copy.
288- h1 = hmac .HMAC ("key" )
293+ h1 = hmac .HMAC ("key" , digestmod = hashlib . sha1 )
289294 h2 = h1 .copy ()
290295 # Using id() in case somebody has overridden __cmp__.
291296 self .assertTrue (id (h1 ) != id (h2 ), "No real copy of the HMAC instance." )
@@ -296,7 +301,7 @@ def test_realcopy(self):
296301
297302 def test_equality (self ):
298303 # Testing if the copy has the same digests.
299- h1 = hmac .HMAC ("key" )
304+ h1 = hmac .HMAC ("key" , digestmod = hashlib . sha1 )
300305 h1 .update ("some random text" )
301306 h2 = h1 .copy ()
302307 self .assertTrue (h1 .digest () == h2 .digest (),
0 commit comments