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("Make sure that the usages of an AES key are respected");
16 var data
= asciiToUint8Array("hello");
17 var iv
= new Uint8Array(16);
19 function importKeyExcludingUsage(usage
)
21 var algorithm
= {name
: 'aes-cbc'};
22 var extractable
= false;
23 var keyData
= hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c");
25 var usages
= ["encrypt", "decrypt", "wrapKey", "unwrapKey"];
26 for (var i
in usages
) {
27 if (usages
[i
] == usage
) {
33 return crypto
.subtle
.importKey('raw', keyData
, algorithm
, extractable
, usages
);
36 function testEncrypt()
38 return importKeyExcludingUsage("encrypt").then(function(key
) {
39 return crypto
.subtle
.encrypt({name
: 'AES-CBC', iv
: iv
}, key
, data
);
40 }).then(failAndFinishJSTest
, function(result
) {
45 function testDecrypt()
47 return importKeyExcludingUsage("decrypt").then(function(key
) {
48 return crypto
.subtle
.decrypt({name
: 'AES-CBC', iv
: iv
}, key
, data
);
49 }).then(failAndFinishJSTest
, function(result
) {
54 // FIXME: Add wrapKey() and unwrapKey()
56 testEncrypt().then(testDecrypt
).then(finishJSTest
, failAndFinishJSTest
);