| 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.exportKey."); | 12 description("Call encrypt using the wrong AES key"); |
| 13 | 13 |
| 14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
| 15 | 15 |
| 16 addTask(importTestKeys().then(function(result) { | 16 var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c"); |
| 17 keys = result; | 17 var data = asciiToUint8Array("hello"); |
| 18 var aesCbcKey = null; |
| 18 | 19 |
| 19 // Invalid export formats. | 20 Promise.resolve(null).then(function(result) { |
| 20 shouldRejectPromiseWithNull("crypto.subtle.exportKey(3, keys.aesCbcJustDecry
pt)"); | 21 var usages = ['encrypt', 'decrypt']; |
| 21 shouldRejectPromiseWithNull("crypto.subtle.exportKey(null, keys.aesCbcJustDe
crypt)"); | 22 var extractable = false; |
| 22 shouldRejectPromiseWithNull("crypto.subtle.exportKey('invalid', keys.aesCbcJ
ustDecrypt)"); | 23 var algorithm = {name: 'aes-gcm'}; |
| 23 | 24 |
| 24 // Invalid keys | 25 return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage
s); |
| 25 shouldThrow("crypto.subtle.exportKey('raw', null)"); | 26 }).then(function(result) { |
| 26 shouldThrow("crypto.subtle.exportKey('raw', 3)"); | 27 key = result; |
| 28 shouldEvaluateAs("key.algorithm.name", "AES-GCM"); |
| 27 | 29 |
| 28 shouldBe("keys.aesCbcJustDecrypt.extractable", "false") | 30 // Can't use an AES-KW key for AES-CBC (even though both are AES keys). |
| 29 shouldRejectPromiseWithNull("crypto.subtle.exportKey('raw', keys.aesCbcJustD
ecrypt)"); | 31 return crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array(16)}, key,
data); |
| 30 | 32 }).then(failAndFinishJSTest, function(result) { |
| 31 return crypto.subtle.exportKey('raw', keys.aesCbc); | 33 error = result; |
| 32 }).then(function(result) { | 34 shouldBeNull("error"); |
| 33 bytesShouldMatchHexString("Key bytes", "3136206279746573206f66206b657921", r
esult); | 35 }).then(finishJSTest, failAndFinishJSTest); |
| 34 | |
| 35 return crypto.subtle.exportKey('spki', keys.rsaSsaSha1Public); | |
| 36 }).then(function(result) { | |
| 37 bytesShouldMatchHexString("Key bytes", kPublicKeySpkiDerHex, result); | |
| 38 })); | |
| 39 | |
| 40 completeTestWhenAllTasksDone(); | |
| 41 | 36 |
| 42 </script> | 37 </script> |
| 43 | 38 |
| 44 </body> | 39 </body> |
| 45 </html> | 40 </html> |
| OLD | NEW |