| 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 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 var keyData = hexStringToUint8Array(testCase.key); | 80 var keyData = hexStringToUint8Array(testCase.key); |
| 81 var usages = ['sign', 'verify']; | 81 var usages = ['sign', 'verify']; |
| 82 var extractable = false; | 82 var extractable = false; |
| 83 | 83 |
| 84 // (1) Import the key | 84 // (1) Import the key |
| 85 return crypto.subtle.importKey('raw', keyData, importAlgorithm, extractable,
usages).then(function(result) { | 85 return crypto.subtle.importKey('raw', keyData, importAlgorithm, extractable,
usages).then(function(result) { |
| 86 key = result; | 86 key = result; |
| 87 | 87 |
| 88 // shouldBe() can only resolve variables in global context. | 88 // shouldBe() can only resolve variables in global context. |
| 89 tmpKey = key; | 89 tmpKey = key; |
| 90 shouldEvaluateAs("tmpKey.type", "secret") | 90 shouldEvaluateAs("tmpKey.type", "secret"); |
| 91 shouldEvaluateAs("tmpKey.extractable", false) | 91 shouldEvaluateAs("tmpKey.extractable", false); |
| 92 shouldEvaluateAs("tmpKey.algorithm.name", "HMAC") | 92 shouldEvaluateAs("tmpKey.algorithm.name", "HMAC"); |
| 93 shouldEvaluateAs("tmpKey.algorithm.hash.name", testCase.hash) | 93 shouldEvaluateAs("tmpKey.algorithm.hash.name", testCase.hash); |
| 94 shouldEvaluateAs("tmpKey.algorithm.length", keyData.length * 8); | 94 shouldEvaluateAs("tmpKey.algorithm.length", keyData.length * 8); |
| 95 shouldEvaluateAs("tmpKey.usages.join(',')", "sign,verify") | 95 shouldEvaluateAs("tmpKey.usages.join(',')", "sign,verify"); |
| 96 | 96 |
| 97 // (2) Sign. | 97 // (2) Sign. |
| 98 return crypto.subtle.sign(algorithm, key, hexStringToUint8Array(testCase
.message)); | 98 return crypto.subtle.sign(algorithm, key, hexStringToUint8Array(testCase
.message)); |
| 99 }).then(function(result) { | 99 }).then(function(result) { |
| 100 bytesShouldMatchHexString("Mac", testCase.mac, result); | 100 bytesShouldMatchHexString("Mac", testCase.mac, result); |
| 101 | 101 |
| 102 // (3) Verify | 102 // (3) Verify |
| 103 return crypto.subtle.verify(algorithm, key, hexStringToUint8Array(testCa
se.mac), hexStringToUint8Array(testCase.message)); | 103 return crypto.subtle.verify(algorithm, key, hexStringToUint8Array(testCa
se.mac), hexStringToUint8Array(testCase.message)); |
| 104 }).then(function(result) { | 104 }).then(function(result) { |
| 105 verifyResult = result; | 105 verifyResult = result; |
| 106 shouldBe("verifyResult", "true") | 106 shouldBe("verifyResult", "true"); |
| 107 | 107 |
| 108 // (4) Verify truncated mac (by stripping 1 byte off of it). | 108 // (4) Verify truncated mac (by stripping 1 byte off of it). |
| 109 var expectedMac = hexStringToUint8Array(testCase.mac); | 109 var expectedMac = hexStringToUint8Array(testCase.mac); |
| 110 return crypto.subtle.verify(algorithm, key, expectedMac.subarray(0, expe
ctedMac.byteLength - 1), hexStringToUint8Array(testCase.message)); | 110 return crypto.subtle.verify(algorithm, key, expectedMac.subarray(0, expe
ctedMac.byteLength - 1), hexStringToUint8Array(testCase.message)); |
| 111 }).then(function(result) { | 111 }).then(function(result) { |
| 112 verifyResult = result; | 112 verifyResult = result; |
| 113 shouldBe("verifyResult", "false") | 113 shouldBe("verifyResult", "false"); |
| 114 }); | 114 }); |
| 115 } | 115 } |
| 116 | 116 |
| 117 var lastPromise = Promise.resolve(null); | 117 var lastPromise = Promise.resolve(null); |
| 118 | 118 |
| 119 kHmacTestVectors.forEach(function(testCase) { | 119 kHmacTestVectors.forEach(function(testCase) { |
| 120 lastPromise = lastPromise.then(runTest.bind(null, testCase)); | 120 lastPromise = lastPromise.then(runTest.bind(null, testCase)); |
| 121 }); | 121 }); |
| 122 | 122 |
| 123 lastPromise.then(finishJSTest, failAndFinishJSTest); | 123 lastPromise.then(finishJSTest, failAndFinishJSTest); |
| 124 | 124 |
| 125 </script> | 125 </script> |
| 126 | 126 |
| 127 </body> | 127 </body> |
| 128 </html> | 128 </html> |
| OLD | NEW |