File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 5
5
# http://www.itl.nist.gov/div897/pubs/fip180-1.htm
6
6
7
7
import sha
8
- import test_support
9
8
import unittest
9
+ from test import test_support
10
10
11
11
12
12
class SHATestCase (unittest .TestCase ):
13
13
def check (self , data , digest ):
14
- computed = sha .new (data ).hexdigest ()
14
+ # Check digest matches the expected value
15
+ obj = sha .new (data )
16
+ computed = obj .hexdigest ()
15
17
self .assert_ (computed == digest )
16
18
19
+ # Verify that the value doesn't change between two consecutive
20
+ # digest operations.
21
+ computed_again = obj .hexdigest ()
22
+ self .assert_ (computed == computed_again )
23
+
24
+ # Check hexdigest() output matches digest()'s output
25
+ digest = obj .digest ()
26
+ hexd = ""
27
+ for c in digest :
28
+ hexd += '%02x' % ord (c )
29
+ self .assert_ (computed == hexd )
30
+
17
31
def test_case_1 (self ):
18
32
self .check ("abc" ,
19
33
"a9993e364706816aba3e25717850c26c9cd0d89d" )
@@ -26,6 +40,9 @@ def test_case_3(self):
26
40
self .check ("a" * 1000000 ,
27
41
"34aa973cd4c4daa4f61eeb2bdbad27316534016f" )
28
42
43
+ def test_case_4 (self ):
44
+ self .check (chr (0xAA ) * 80 ,
45
+ '4ca0ef38f1794b28a8f8ee110ee79d48ce13be25' )
29
46
30
47
def test_main ():
31
48
test_support .run_unittest (SHATestCase )
You can’t perform that action at this time.
0 commit comments