]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Lib/test/test_sha.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / test / test_sha.py
CommitLineData
4710c53d 1# Testing sha module (NIST's Secure Hash Algorithm)\r
2\r
3# use the three examples from Federal Information Processing Standards\r
4# Publication 180-1, Secure Hash Standard, 1995 April 17\r
5# http://www.itl.nist.gov/div897/pubs/fip180-1.htm\r
6\r
7import warnings\r
8warnings.filterwarnings("ignore", "the sha module is deprecated.*",\r
9 DeprecationWarning)\r
10\r
11import sha\r
12import unittest\r
13from test import test_support\r
14\r
15\r
16class SHATestCase(unittest.TestCase):\r
17 def check(self, data, digest):\r
18 # Check digest matches the expected value\r
19 obj = sha.new(data)\r
20 computed = obj.hexdigest()\r
21 self.assertTrue(computed == digest)\r
22\r
23 # Verify that the value doesn't change between two consecutive\r
24 # digest operations.\r
25 computed_again = obj.hexdigest()\r
26 self.assertTrue(computed == computed_again)\r
27\r
28 # Check hexdigest() output matches digest()'s output\r
29 digest = obj.digest()\r
30 hexd = ""\r
31 for c in digest:\r
32 hexd += '%02x' % ord(c)\r
33 self.assertTrue(computed == hexd)\r
34\r
35 def test_case_1(self):\r
36 self.check("abc",\r
37 "a9993e364706816aba3e25717850c26c9cd0d89d")\r
38\r
39 def test_case_2(self):\r
40 self.check("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",\r
41 "84983e441c3bd26ebaae4aa1f95129e5e54670f1")\r
42\r
43 def test_case_3(self):\r
44 self.check("a" * 1000000,\r
45 "34aa973cd4c4daa4f61eeb2bdbad27316534016f")\r
46\r
47 def test_case_4(self):\r
48 self.check(chr(0xAA) * 80,\r
49 '4ca0ef38f1794b28a8f8ee110ee79d48ce13be25')\r
50\r
51def test_main():\r
52 test_support.run_unittest(SHATestCase)\r
53\r
54\r
55if __name__ == "__main__":\r
56 test_main()\r