@@ -12,37 +12,37 @@ def test_md5_vectors(self):
12
12
# Test the HMAC module against test vectors from the RFC.
13
13
14
14
def md5test (key , data , digest ):
15
- h = hmac .HMAC (key , data )
15
+ h = hmac .HMAC (key , data , digestmod = hashlib . sha1 )
16
16
self .assertEqual (h .hexdigest ().upper (), digest .upper ())
17
17
18
18
md5test (chr (0x0b ) * 16 ,
19
19
"Hi There" ,
20
- "9294727A3638BB1C13F48EF8158BFC9D " )
20
+ "675B0B3A1B4DDF4E124872DA6C2F632BFED957E9 " )
21
21
22
22
md5test ("Jefe" ,
23
23
"what do ya want for nothing?" ,
24
- "750c783e6ab0b503eaa86e310a5db738 " )
24
+ "EFFCDF6AE5EB2FA2D27416D5F184DF9C259A7C79 " )
25
25
26
26
md5test (chr (0xAA )* 16 ,
27
27
chr (0xDD )* 50 ,
28
- "56be34521d144c88dbb8c733f0e8b3f6 " )
28
+ "D730594D167E35D5956FD8003D0DB3D3F46DC7BB " )
29
29
30
30
md5test ("" .join ([chr (i ) for i in range (1 , 26 )]),
31
31
chr (0xCD ) * 50 ,
32
- "697eaf0aca3a3aea3a75164746ffaa79 " )
32
+ "4C9007F4026250C6BC8414F9BF50C86C2D7235DA " )
33
33
34
34
md5test (chr (0x0C ) * 16 ,
35
35
"Test With Truncation" ,
36
- "56461ef2342edc00f9bab995690efd4c " )
36
+ "37268B7E21E84DA5720C53C4BA03AD1104039FA7 " )
37
37
38
38
md5test (chr (0xAA ) * 80 ,
39
39
"Test Using Larger Than Block-Size Key - Hash Key First" ,
40
- "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd " )
40
+ "AA4AE5E15272D00E95705637CE8A3B55ED402112 " )
41
41
42
42
md5test (chr (0xAA ) * 80 ,
43
43
("Test Using Larger Than Block-Size Key "
44
44
"and Larger Than One Block-Size Data" ),
45
- "6f630fad67cda0ee1fb1f562db3aa53e " )
45
+ "E8E99D0F45237D786D6BBAA7965C7808BBFF1A91 " )
46
46
47
47
def test_sha_vectors (self ):
48
48
def shatest (key , data , digest ):
@@ -232,14 +232,14 @@ def test_normal(self):
232
232
# Standard constructor call.
233
233
failed = 0
234
234
try :
235
- h = hmac .HMAC ("key" )
235
+ h = hmac .HMAC ("key" , digestmod = hashlib . sha1 )
236
236
except :
237
237
self .fail ("Standard constructor call raised exception." )
238
238
239
239
def test_withtext (self ):
240
240
# Constructor call with text.
241
241
try :
242
- h = hmac .HMAC ("key" , "hash this!" )
242
+ h = hmac .HMAC ("key" , "hash this!" , digestmod = hashlib . sha1 )
243
243
except :
244
244
self .fail ("Constructor call with text argument raised exception." )
245
245
@@ -250,6 +250,11 @@ def test_withmodule(self):
250
250
except :
251
251
self .fail ("Constructor call with hashlib.sha1 raised exception." )
252
252
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
+
253
258
class SanityTestCase (unittest .TestCase ):
254
259
255
260
def test_default_is_md5 (self ):
@@ -262,7 +267,7 @@ def test_exercise_all_methods(self):
262
267
# Exercising all methods once.
263
268
# This must not raise any exceptions
264
269
try :
265
- h = hmac .HMAC ("my secret key" )
270
+ h = hmac .HMAC ("my secret key" , digestmod = hashlib . sha1 )
266
271
h .update ("compute the hash of this text!" )
267
272
dig = h .digest ()
268
273
dig = h .hexdigest ()
@@ -274,7 +279,7 @@ class CopyTestCase(unittest.TestCase):
274
279
275
280
def test_attributes (self ):
276
281
# Testing if attributes are of same type.
277
- h1 = hmac .HMAC ("key" )
282
+ h1 = hmac .HMAC ("key" , digestmod = hashlib . sha1 )
278
283
h2 = h1 .copy ()
279
284
self .assertTrue (h1 .digest_cons == h2 .digest_cons ,
280
285
"digest constructors don't match." )
@@ -285,7 +290,7 @@ def test_attributes(self):
285
290
286
291
def test_realcopy (self ):
287
292
# Testing if the copy method created a real copy.
288
- h1 = hmac .HMAC ("key" )
293
+ h1 = hmac .HMAC ("key" , digestmod = hashlib . sha1 )
289
294
h2 = h1 .copy ()
290
295
# Using id() in case somebody has overridden __cmp__.
291
296
self .assertTrue (id (h1 ) != id (h2 ), "No real copy of the HMAC instance." )
@@ -296,7 +301,7 @@ def test_realcopy(self):
296
301
297
302
def test_equality (self ):
298
303
# Testing if the copy has the same digests.
299
- h1 = hmac .HMAC ("key" )
304
+ h1 = hmac .HMAC ("key" , digestmod = hashlib . sha1 )
300
305
h1 .update ("some random text" )
301
306
h2 = h1 .copy ()
302
307
self .assertTrue (h1 .digest () == h2 .digest (),
0 commit comments