4 <script src=
"../../resources/js-test.js"></script>
5 <script src=
"resources/common.js"></script>
8 <p id=
"description"></p>
9 <div id=
"console"></div>
12 description("Tests importing an AES key from raw with wrong length");
16 // -------------------------------------------------
18 // -------------------------------------------------
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
27 var kAesAlgorithms
= [
28 "AES-CBC", "AES-GCM", "AES-KW"
31 function testInvalidKeyImport(algorithmName
, keyLengthBytes
)
33 var algorithm
= {name
: algorithmName
};
34 var keyData
= new Uint8Array(keyLengthBytes
);
36 var usages
= ['encrypt', 'decrypt'];
37 var extractable
= false;
39 return crypto
.subtle
.importKey('raw', keyData
, algorithm
, extractable
, usages
).then(function(result
) {
40 debug("FAIL: Successfully imported " + algorithmName
+ " key of length " + keyData
.byteLength
+ " bytes");
42 debug("PASS: Failed to import " + algorithmName
+ " key of length " + keyData
.byteLength
+ " bytes");
46 var lastPromise
= Promise
.resolve(null);
48 kAesAlgorithms
.forEach(function(algorithmName
) {
49 kUnsupportedKeyLengths
.forEach(function(keyLengthBytes
) {
50 lastPromise
= lastPromise
.then(testInvalidKeyImport
.bind(null, algorithmName
, keyLengthBytes
));
54 lastPromise
.then(finishJSTest
, failAndFinishJSTest
);