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("Test exporting an AES key.");
16 var extractable
= true;
17 var nonExtractable
= false;
21 k
: "jnOw99oOZFLIEPMrgJB55WL46tJSLGt7jnOw99oOZFI"
24 Promise
.resolve(null).then(function(result
) {
25 return crypto
.subtle
.exportKey("raw");
26 }).then(failAndFinishJSTest
, function(result
) {
28 return crypto
.subtle
.exportKey("raw", null)
29 }).then(failAndFinishJSTest
, function(result
) {
31 return crypto
.subtle
.exportKey("raw", undefined);
32 }).then(failAndFinishJSTest
, function(result
) {
34 return crypto
.subtle
.exportKey("raw", {});
35 }).then(failAndFinishJSTest
, function(result
) {
37 return crypto
.subtle
.exportKey("raw", 1);
38 }).then(failAndFinishJSTest
, function(result
) {
40 debug("\nImporting a JWK key...");
42 return crypto
.subtle
.importKey("jwk", jwkKey
, {name
: "AES-CBC"}, extractable
, ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey']);
43 }).then(function(result
) {
46 return crypto
.subtle
.exportKey(null, key
);
47 }).then(failAndFinishJSTest
, function(result
) {
49 return crypto
.subtle
.exportKey(undefined, key
);
50 }).then(failAndFinishJSTest
, function(result
) {
52 return crypto
.subtle
.exportKey({}, key
);
53 }).then(failAndFinishJSTest
, function(result
) {
55 return crypto
.subtle
.exportKey("", key
);
56 }).then(failAndFinishJSTest
, function(result
) {
58 return crypto
.subtle
.exportKey("foobar", key
);
59 }).then(failAndFinishJSTest
, function(result
) {
62 debug("\nExporting the key as raw data...");
63 return crypto
.subtle
.exportKey("raw", key
);
64 }).then(function(result
) {
65 exportedData
= result
;
66 shouldBe("bytesToHexString(new Uint8Array(exportedData))", "'8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b8e73b0f7da0e6452'");
68 debug("Exporting the key as JWK...");
69 return crypto
.subtle
.exportKey("jwk", key
);
70 }).then(function(result
) {
72 shouldBe("exportedJWK.kty", "'oct'");
73 shouldBe("exportedJWK.k", "'jnOw99oOZFLIEPMrgJB55WL46tJSLGt7jnOw99oOZFI'");
74 shouldBe("exportedJWK.alg", "'A256CBC'");
75 shouldBe("exportedJWK.ext", "true");
76 shouldBe("exportedJWK.use", "undefined");
77 shouldBe("exportedJWK.key_ops", "['encrypt', 'decrypt', 'wrapKey', 'unwrapKey']");
79 debug("\nImporting a key that's not extractable...");
80 return crypto
.subtle
.importKey("jwk", jwkKey
, {name
: "AES-CBC"}, nonExtractable
, ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'])
81 }).then(function(result
) {
84 debug("\nTrying to export as raw...");
85 return crypto
.subtle
.exportKey("raw", key
);
86 }, failAndFinishJSTest
).then(function(result
) {
87 testFailed("Promise wasn't rejected");
90 testPassed("Rejected, as expected");
93 debug("Trying to export as jwk...");
94 return crypto
.subtle
.exportKey("jwk", key
);
95 }).then(function(result
) {
96 testFailed("Promise wasn't rejected");
99 testPassed("Rejected, as expected");