ยปCore Development>Code coverage>Lib/test/test_sha.py

Python code coverage for Lib/test/test_sha.py

#countcontent
1n/a# Testing sha module (NIST's Secure Hash Algorithm)
2n/a
3n/a# use the three examples from Federal Information Processing Standards
4n/a# Publication 180-1, Secure Hash Standard, 1995 April 17
5n/a# http://www.itl.nist.gov/div897/pubs/fip180-1.htm
6n/a
71import warnings
81warnings.filterwarnings("ignore", "the sha module is deprecated.*",
91 DeprecationWarning)
10n/a
111import sha
121import unittest
131from test import test_support
14n/a
15n/a
162class SHATestCase(unittest.TestCase):
171 def check(self, data, digest):
18n/a # Check digest matches the expected value
194 obj = sha.new(data)
204 computed = obj.hexdigest()
214 self.assertTrue(computed == digest)
22n/a
23n/a # Verify that the value doesn't change between two consecutive
24n/a # digest operations.
254 computed_again = obj.hexdigest()
264 self.assertTrue(computed == computed_again)
27n/a
28n/a # Check hexdigest() output matches digest()'s output
294 digest = obj.digest()
304 hexd = ""
3184 for c in digest:
3280 hexd += '%02x' % ord(c)
334 self.assertTrue(computed == hexd)
34n/a
351 def test_case_1(self):
361 self.check("abc",
371 "a9993e364706816aba3e25717850c26c9cd0d89d")
38n/a
391 def test_case_2(self):
401 self.check("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
411 "84983e441c3bd26ebaae4aa1f95129e5e54670f1")
42n/a
431 def test_case_3(self):
441 self.check("a" * 1000000,
451 "34aa973cd4c4daa4f61eeb2bdbad27316534016f")
46n/a
471 def test_case_4(self):
481 self.check(chr(0xAA) * 80,
491 '4ca0ef38f1794b28a8f8ee110ee79d48ce13be25')
50n/a
511def test_main():
521 test_support.run_unittest(SHATestCase)
53n/a
54n/a
551if __name__ == "__main__":
560 test_main()