| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../resources/js-test-pre.js"></script> |
| <script src="../resources/common.js"></script> |
| </head> |
| <body> |
| <p id="description"></p> |
| <div id="console"></div> |
| |
| <script> |
| description("Test encrypting with malformed parameters"); |
| |
| jsTestIsAsync = true; |
| |
| var extractable = false; |
| var plainText = asciiToUint8Array("Hello, World!"); |
| var aesCbcParams = { |
| name: "aes-cbc", |
| iv: asciiToUint8Array("jnOw99oOZFLIEPMr"), |
| } |
| var fakedKey = { |
| type: "secret", |
| extractable: true, |
| algorithm: {name: "AES-CBC", length: 128}, |
| usages: ["encrypt", "decrypt"] |
| } |
| var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr"); |
| |
| // Not enough arguments. |
| shouldReject('crypto.subtle.encrypt()'); |
| shouldReject('crypto.subtle.encrypt(1)'); |
| shouldReject('crypto.subtle.encrypt(1, 2)'); |
| // Wrong CryptoKey. |
| shouldReject('crypto.subtle.encrypt(aesCbcParams, fakedKey, plainText)'); |
| |
| crypto.subtle.importKey("raw", rawKey, "aes-kw", extractable, ["wrapKey", "unwrapKey"]).then(function(result) { |
| wrongKey = result; |
| // Wrong algorithm identifier. |
| shouldReject('crypto.subtle.encrypt(aesCbcParams, wrongKey, plainText)'); |
| |
| return crypto.subtle.importKey("raw", rawKey, "aes-cbc", extractable, ["wrapKey", "unwrapKey"]); |
| }).then(function(result) { |
| wrongKey = result; |
| // Wrong usage. |
| return shouldReject('crypto.subtle.encrypt(aesCbcParams, wrongKey, plainText)'); |
| }).then(finishJSTest); |
| |
| </script> |
| |
| <script src="../../resources/js-test-post.js"></script> |
| </body> |
| </html> |