Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / crypto / subtle / hmac / legacy-empty-key.html
blobd71daf55a69cdde26da4ea38a9607041201067c6
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>
11 <script>
12 description("Tests structured de-cloning of empty HMAC keys");
14 jsTestIsAsync = true;
16 // It used to be possible to import empty HMAC keys, so it is possible that
17 // such keys were persisted to storage. This test verifies that such keys can
18 // still be successfully de-serialized and used.
20 // The version number of the serialized format used is 7.
22 function deserializeTestKeys()
24 function createKeyFromSerialized(serializedBytesHex)
26 return internals.deserializeBuffer(hexStringToUint8Array(serializedBytesHex).buffer);
29 debug("\nDeserializing empty HMAC SHA-1 key...");
30 var sha1Key = createKeyFromSerialized("ff073f004b0200051900");
32 key = sha1Key;
33 shouldEvaluateAs("key.type", "secret");
34 shouldEvaluateAs("key.extractable", true);
35 shouldEvaluateAs("key.algorithm.name", "HMAC");
36 shouldEvaluateAs("key.algorithm.length", 0);
37 shouldEvaluateAs("key.algorithm.hash.name", "SHA-1");
38 shouldBe("key.usages", '["sign", "verify"]');
40 debug("\nDeserializing empty HMAC SHA-256 key...");
41 var sha256Key = createKeyFromSerialized("ff073f004b0200061900");
43 key = sha256Key;
44 shouldEvaluateAs("key.type", "secret");
45 shouldEvaluateAs("key.extractable", true);
46 shouldEvaluateAs("key.algorithm.name", "HMAC");
47 shouldEvaluateAs("key.algorithm.length", 0);
48 shouldEvaluateAs("key.algorithm.hash.name", "SHA-256");
49 shouldBe("key.usages", '["sign", "verify"]');
51 return {
52 sha1: sha1Key,
53 sha256: sha256Key
58 Promise.resolve(deserializeTestKeys()).then(function(result) {
59 keys = result;
61 debug("\ncalling verify() with a valid signature (SHA-1) ...");
62 return crypto.subtle.verify("HMAC", keys.sha1, hexStringToUint8Array("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d"), hexStringToUint8Array(""));
63 }).then(function(result) {
64 verifyResult = result;
65 shouldEvaluateAs("verifyResult", true);
67 debug("\ncalling verify() with an invalid signature (SHA-1) ...");
68 return crypto.subtle.verify("HMAC", keys.sha1, hexStringToUint8Array("fbdb1d1b18aa6c08324b7d64b71fb76370690e1e"), hexStringToUint8Array(""));
69 }).then(function(result) {
70 verifyResult = result;
71 shouldEvaluateAs("verifyResult", false);
73 debug("\ncalling sign() (SHA-1) over empty input...");
74 return crypto.subtle.sign("HMAC", keys.sha1, hexStringToUint8Array(""));
75 }).then(function(result) {
76 bytesShouldMatchHexString("signature", "fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", result);
78 debug("\ncalling verify() with a valid signature (SHA-256) ...");
79 return crypto.subtle.verify("HMAC", keys.sha256, hexStringToUint8Array("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad"), hexStringToUint8Array(""));
80 }).then(function(result) {
81 verifyResult = result;
82 shouldEvaluateAs("verifyResult", true);
84 debug("\ncalling verify() with an invalid signature (SHA-256) ...");
85 return crypto.subtle.verify("HMAC", keys.sha256, hexStringToUint8Array("0000"), hexStringToUint8Array(""));
86 }).then(function(result) {
87 verifyResult = result;
88 shouldEvaluateAs("verifyResult", false);
90 debug("\ncalling sign() (SHA-256) over empty input...");
91 return crypto.subtle.sign("HMAC", keys.sha256, hexStringToUint8Array(""));
92 }).then(function(result) {
93 bytesShouldMatchHexString("signature", "b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", result);
94 }).then(finishJSTest, failAndFinishJSTest);
96 </script>
98 </body>
99 </html>