| OLD | NEW | 
 | (Empty) | 
|   1 <!DOCTYPE html> |  | 
|   2 <html> |  | 
|   3 <head> |  | 
|   4 <script src="../resources/js-test.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 importing an AES key from raw with wrong length"); |  | 
|  13  |  | 
|  14 jsTestIsAsync = true; |  | 
|  15  |  | 
|  16 // ------------------------------------------------- |  | 
|  17 // Failed key import. |  | 
|  18 // ------------------------------------------------- |  | 
|  19  |  | 
|  20 // Supported key lengths are 16 (128-bit), 32 (256-bit), 24 (192-bit), |  | 
|  21 // Try key lengths that are off by 1 from the supported ones. |  | 
|  22 var kUnsupportedKeyLengths = [ |  | 
|  23     0, 1, 15, 17, 31, 33, 23, 25, 64 |  | 
|  24 ]; |  | 
|  25  |  | 
|  26 // Not exhaustive |  | 
|  27 var kAesAlgorithms = [ |  | 
|  28   "AES-CBC", "AES-GCM", "AES-KW" |  | 
|  29 ]; |  | 
|  30  |  | 
|  31 function testInvalidKeyImport(algorithmName, keyLengthBytes) |  | 
|  32 { |  | 
|  33     var algorithm = {name: algorithmName}; |  | 
|  34     var keyData = new Uint8Array(keyLengthBytes); |  | 
|  35  |  | 
|  36     var usages = ['encrypt', 'decrypt']; |  | 
|  37     var extractable = false; |  | 
|  38  |  | 
|  39     return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usage
    s).then(function(result) { |  | 
|  40         debug("FAIL: Successfully imported " + algorithmName + " key of length "
     + keyData.byteLength + " bytes"); |  | 
|  41     }, function(result) { |  | 
|  42         debug("PASS: Failed to import " + algorithmName + " key of length " + ke
    yData.byteLength + " bytes"); |  | 
|  43     }); |  | 
|  44 } |  | 
|  45  |  | 
|  46 var lastPromise = Promise.resolve(null); |  | 
|  47  |  | 
|  48 kAesAlgorithms.forEach(function(algorithmName) { |  | 
|  49     kUnsupportedKeyLengths.forEach(function(keyLengthBytes) { |  | 
|  50         lastPromise = lastPromise.then(testInvalidKeyImport.bind(null, algorithm
    Name, keyLengthBytes)); |  | 
|  51     }); |  | 
|  52 }); |  | 
|  53  |  | 
|  54 lastPromise.then(finishJSTest, failAndFinishJSTest); |  | 
|  55  |  | 
|  56 </script> |  | 
|  57  |  | 
|  58 </body> |  | 
|  59 </html> |  | 
| OLD | NEW |