Skip to content

Commit 885fe06

Browse files
committed
Add extra SHA tests
1 parent 8cca0b7 commit 885fe06

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Lib/test/test_sha.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,29 @@
55
# http://www.itl.nist.gov/div897/pubs/fip180-1.htm
66

77
import sha
8-
import test_support
98
import unittest
9+
from test import test_support
1010

1111

1212
class SHATestCase(unittest.TestCase):
1313
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()
1517
self.assert_(computed == digest)
1618

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+
1731
def test_case_1(self):
1832
self.check("abc",
1933
"a9993e364706816aba3e25717850c26c9cd0d89d")
@@ -26,6 +40,9 @@ def test_case_3(self):
2640
self.check("a" * 1000000,
2741
"34aa973cd4c4daa4f61eeb2bdbad27316534016f")
2842

43+
def test_case_4(self):
44+
self.check(chr(0xAA) * 80,
45+
'4ca0ef38f1794b28a8f8ee110ee79d48ce13be25')
2946

3047
def test_main():
3148
test_support.run_unittest(SHATestCase)

0 commit comments

Comments
 (0)