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 calling cypto.subtle.sign and crypto.subtle.verify with incorrect inputs");
16 function importHmacKey()
18 var importAlgorithm
= {name
: 'HMAC', hash
: {name
: 'sha-1'}};
19 var keyData
= new Uint8Array(16);
20 var extractable
= true;
21 var usages
= ['sign', 'verify'];
23 return crypto
.subtle
.importKey('raw', keyData
, importAlgorithm
, extractable
, usages
);
26 data
= asciiToUint8Array("hello");
27 hmac
= {name
: 'HMAC', hash
: {name
: 'sha-1'}};
29 importHmacKey().then(function(result
) {
32 // Pass invalid signature parameters to verify()
33 return crypto
.subtle
.verify(hmac
, key
, null, data
);
34 }).then(failAndFinishJSTest
, function(result
) {
37 // Pass invalid signature parameters to verify()
38 return crypto
.subtle
.verify(hmac
, key
, 'a', data
);
39 }).then(failAndFinishJSTest
, function(result
) {
42 // Pass invalid signature parameters to verify()
43 return crypto
.subtle
.verify(hmac
, key
, [], data
);
44 }).then(failAndFinishJSTest
, function(result
) {
47 // Operation does not support signing.
48 return crypto
.subtle
.sign({name
: 'sha-1'}, key
, data
);
49 }).then(failAndFinishJSTest
, function(result
) {
52 // Operation doesn't support signing (also given an invalid key, but the
53 // first failure takes priority)
54 return crypto
.subtle
.sign({name
: 'AES-CBC'}, key
, data
);
55 }).then(failAndFinishJSTest
, function(result
) {
57 }).then(finishJSTest
, failAndFinishJSTest
);