OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../fast/js/resources/js-test-pre.js"></script> | 4 <script src="../fast/js/resources/js-test-pre.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.sign and crypto.subtle.verify"); | 12 description("Tests cypto.subtle.sign and crypto.subtle.verify"); |
13 | 13 |
14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
15 | 15 |
16 importHmacSha1Key().then(function(key) { | 16 importHmacSha1Key().then(function(key) { |
17 hmacSha1Key = key; | 17 hmacSha1Key = key; |
18 hmacSha1 = {name: 'hmac', hash: {name: 'Sha-1'}}; | 18 hmacSha1 = {name: 'hmac', hash: {name: 'Sha-1'}}; |
19 | 19 |
20 // Pass invalid signature parameters to verify() | 20 data = asciiToArrayBuffer("hello"); |
21 shouldThrow("crypto.subtle.verify(hmacSha1, hmacSha1Key, null)"); | |
22 shouldThrow("crypto.subtle.verify(hmacSha1, hmacSha1Key, 'a')"); | |
23 shouldThrow("crypto.subtle.verify(hmacSha1, hmacSha1Key, [])"); | |
24 | |
25 var data = asciiToArrayBuffer("hello"); | |
26 var expectedSignature = asciiToArrayBuffer("signed HMAC:hello"); | 21 var expectedSignature = asciiToArrayBuffer("signed HMAC:hello"); |
27 | 22 |
28 var signPromise = crypto.subtle.sign(hmacSha1, hmacSha1Key).process(data).fi
nish(); | 23 // Pass invalid signature parameters to verify() |
29 var verifyPromise = crypto.subtle.verify(hmacSha1, hmacSha1Key, expectedSign
ature).process(data).finish(); | 24 shouldThrow("crypto.subtle.verify(hmacSha1, hmacSha1Key, null, data)"); |
30 var badVerifyPromise = crypto.subtle.verify(hmacSha1, hmacSha1Key, asciiToAr
rayBuffer("badsignature")).process(data).finish(); | 25 shouldThrow("crypto.subtle.verify(hmacSha1, hmacSha1Key, 'a', data)"); |
| 26 shouldThrow("crypto.subtle.verify(hmacSha1, hmacSha1Key, [], data)"); |
| 27 |
| 28 var signPromise = crypto.subtle.sign(hmacSha1, hmacSha1Key, data); |
| 29 var verifyPromise = crypto.subtle.verify(hmacSha1, hmacSha1Key, expectedSign
ature, data); |
| 30 var badVerifyPromise = crypto.subtle.verify(hmacSha1, hmacSha1Key, asciiToAr
rayBuffer("badsignature"), data); |
31 | 31 |
32 Promise.every(signPromise, verifyPromise, badVerifyPromise).then(function(re
sults) | 32 Promise.every(signPromise, verifyPromise, badVerifyPromise).then(function(re
sults) |
33 { | 33 { |
34 signResult = results[0]; | 34 signResult = results[0]; |
35 verifyResult1 = results[1]; | 35 verifyResult1 = results[1]; |
36 verifyResult2 = results[2]; | 36 verifyResult2 = results[2]; |
37 | 37 |
38 shouldBe("signResult.byteLength", "17"); | 38 shouldBe("signResult.byteLength", "17"); |
39 shouldBe("verifyResult1", "true"); | 39 shouldBe("verifyResult1", "true"); |
40 shouldBe("verifyResult2", "false"); | 40 shouldBe("verifyResult2", "false"); |
41 | 41 |
42 finishJSTest(); | 42 finishJSTest(); |
43 }); | 43 }); |
44 }); | 44 }); |
45 | 45 |
46 </script> | 46 </script> |
47 | 47 |
48 <script src="../fast/js/resources/js-test-post.js"></script> | 48 <script src="../fast/js/resources/js-test-post.js"></script> |
49 </body> | 49 </body> |
OLD | NEW |