OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/js-test.js"></script> |
5 <script src="resources/common.js"></script> | 5 <script src="resources/common.js"></script> |
6 </head> | 6 </head> |
7 <body> | 7 <body> |
8 <p id="description"></p> | 8 <p id="description"></p> |
9 <div id="console"></div> | 9 <div id="console"></div> |
10 | 10 |
11 <script> | 11 <script> |
12 description("Tests cypto.subtle.digest."); | 12 description("Tests the digest() operation for SHA-*"); |
13 | 13 |
14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
15 | 15 |
16 // These SHA-* test vectors were taking from: | 16 // These SHA-* test vectors were taking from: |
17 // http://csrc.nist.gov/groups/STM/cavp/documents/shs/shabytetestvectors.zip | 17 // http://csrc.nist.gov/groups/STM/cavp/documents/shs/shabytetestvectors.zip |
18 // | 18 // |
19 // This is not intended to be an exhaustive test, but rather give basic | 19 // This is not intended to be an exhaustive test, but rather give basic |
20 // confidence that things work. | 20 // confidence that things work. |
21 // | 21 // |
22 // Both inputs and outputs are written as a hex-encoded string. | 22 // Both inputs and outputs are written as a hex-encoded string. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 input: "000102030405", | 76 input: "000102030405", |
77 output: "79f4738706fce9650ac60266675c3cd07298b09923850d525604d040e6e448adc7d
c22780d7e1b95bfeaa86a678e4552" | 77 output: "79f4738706fce9650ac60266675c3cd07298b09923850d525604d040e6e448adc7d
c22780d7e1b95bfeaa86a678e4552" |
78 }, | 78 }, |
79 { | 79 { |
80 algorithm: "SHA-512", | 80 algorithm: "SHA-512", |
81 input: "000102030405", | 81 input: "000102030405", |
82 output: "2f3831bccc94cf061bcfa5f8c23c1429d26e3bc6b76edad93d9025cb91c903af6cf
9c935dc37193c04c2c66e7d9de17c358284418218afea2160147aaa912f4c" | 82 output: "2f3831bccc94cf061bcfa5f8c23c1429d26e3bc6b76edad93d9025cb91c903af6cf
9c935dc37193c04c2c66e7d9de17c358284418218afea2160147aaa912f4c" |
83 }, | 83 }, |
84 ]; | 84 ]; |
85 | 85 |
86 // Run each test. | 86 function runTest(testCase) |
87 for (var i = 0; i < kDigestTestVectors.length; ++i) { | |
88 addTask(runTestCase(kDigestTestVectors[i])); | |
89 } | |
90 | |
91 function runTestCase(testCase) | |
92 { | 87 { |
93 return crypto.subtle.digest({name: testCase.algorithm}, hexStringToUint8Arra
y(testCase.input)).then(function(result) { | 88 return crypto.subtle.digest({name: testCase.algorithm}, hexStringToUint8Arra
y(testCase.input)).then(function(result) { |
94 var testDescription = testCase.algorithm + " of [" + testCase.input + "]
"; | 89 var testDescription = testCase.algorithm + " of [" + testCase.input + "]
"; |
95 bytesShouldMatchHexString(testDescription, testCase.output, result); | 90 bytesShouldMatchHexString(testDescription, testCase.output, result); |
96 }); | 91 }); |
97 } | 92 } |
98 | 93 |
99 // Pass invalid data to digest() | 94 var lastPromise = Promise.resolve(null); |
100 shouldThrow("crypto.subtle.digest({name: 'sha-1'})"); | |
101 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, null)"); | |
102 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, 10)"); | |
103 | 95 |
104 // Pass invalid algorithmIdentifiers to digest() | 96 kDigestTestVectors.forEach(function(test) { |
105 data = new Uint8Array([0]); | 97 lastPromise = lastPromise.then(runTest.bind(null, test)); |
106 shouldRejectPromiseWithNull("crypto.subtle.digest({name: 'sha'}, data)"); | 98 }); |
107 shouldThrow("crypto.subtle.digest(null, data)"); | |
108 shouldRejectPromiseWithNull("crypto.subtle.digest({}, data)"); | |
109 | 99 |
110 completeTestWhenAllTasksDone(); | 100 lastPromise.then(finishJSTest, failAndFinishJSTest); |
111 | 101 |
112 </script> | 102 </script> |
113 | 103 |
114 </body> | 104 </body> |
115 </html> | 105 </html> |
OLD | NEW |