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