Update SubtleCrypto::digest to match the latest spec
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Dec 2016 00:28:04 +0000 (00:28 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Dec 2016 00:28:04 +0000 (00:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=164742
<rdar://problem/29258037>

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* WebCryptoAPI/digest/test_digest-expected.txt:
* WebCryptoAPI/idlharness-expected.txt:

Source/WebCore:

This patch updates the SubtleCrypto::digest method to match the latest spec:
https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-digest.
It also refers to the latest Editor's Draft to a certain degree:
https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-digest.
Currently supported digest algorithms are SHA-1, SHA-224, SHA-256, SHA-384,
and SHA-512.

Tests: crypto/subtle/digest-malformed-parameters.html
       crypto/subtle/sha1-digest.html
       crypto/subtle/sha224-digest.html
       crypto/subtle/sha256-digest.html
       crypto/subtle/sha384-digest.html
       crypto/subtle/sha512-digest.html
       crypto/workers/subtle/sha1-digest.html
       crypto/workers/subtle/sha224-digest.html
       crypto/workers/subtle/sha256-digest.html
       crypto/workers/subtle/sha384-digest.html
       crypto/workers/subtle/sha512-digest.html

* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::jsSubtleCryptoFunctionDigestPromise):
(WebCore::JSSubtleCrypto::digest):
* crypto/CryptoAlgorithm.cpp:
(WebCore::CryptoAlgorithm::digest):
* crypto/CryptoAlgorithm.h:
* crypto/SubtleCrypto.idl:
* crypto/algorithms/CryptoAlgorithmSHA1.cpp:
(WebCore::CryptoAlgorithmSHA1::digest):
* crypto/algorithms/CryptoAlgorithmSHA1.h:
* crypto/algorithms/CryptoAlgorithmSHA224.cpp:
(WebCore::CryptoAlgorithmSHA224::digest):
* crypto/algorithms/CryptoAlgorithmSHA224.h:
* crypto/algorithms/CryptoAlgorithmSHA256.cpp:
(WebCore::CryptoAlgorithmSHA256::digest):
* crypto/algorithms/CryptoAlgorithmSHA256.h:
* crypto/algorithms/CryptoAlgorithmSHA384.cpp:
(WebCore::CryptoAlgorithmSHA384::digest):
* crypto/algorithms/CryptoAlgorithmSHA384.h:
* crypto/algorithms/CryptoAlgorithmSHA512.cpp:
(WebCore::CryptoAlgorithmSHA512::digest):
* crypto/algorithms/CryptoAlgorithmSHA512.h:

LayoutTests:

* crypto/subtle/digest-malformed-parameters-expected.txt: Added.
* crypto/subtle/digest-malformed-parameters.html: Added.
* crypto/subtle/sha1-digest-expected.txt: Added.
* crypto/subtle/sha1-digest.html: Added.
* crypto/subtle/sha224-digest-expected.txt: Added.
* crypto/subtle/sha224-digest.html: Added.
* crypto/subtle/sha256-digest-expected.txt: Added.
* crypto/subtle/sha256-digest.html: Added.
* crypto/subtle/sha384-digest-expected.txt: Added.
* crypto/subtle/sha384-digest.html: Added.
* crypto/subtle/sha512-digest-expected.txt: Added.
* crypto/subtle/sha512-digest.html: Added.
* crypto/workers/subtle/resources/sha1-digest.js: Added.
* crypto/workers/subtle/resources/sha224-digest.js: Added.
* crypto/workers/subtle/resources/sha256-digest.js: Added.
* crypto/workers/subtle/resources/sha384-digest.js: Added.
* crypto/workers/subtle/resources/sha512-digest.js: Added.
* crypto/workers/subtle/sha1-digest-expected.txt: Added.
* crypto/workers/subtle/sha1-digest.html: Added.
* crypto/workers/subtle/sha224-digest-expected.txt: Added.
* crypto/workers/subtle/sha224-digest.html: Added.
* crypto/workers/subtle/sha256-digest-expected.txt: Added.
* crypto/workers/subtle/sha256-digest.html: Added.
* crypto/workers/subtle/sha384-digest-expected.txt: Added.
* crypto/workers/subtle/sha384-digest.html: Added.
* crypto/workers/subtle/sha512-digest-expected.txt: Added.
* crypto/workers/subtle/sha512-digest.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209164 268f45cc-cd09-0410-ab3c-d52691b4dbfc

46 files changed:
LayoutTests/ChangeLog
LayoutTests/crypto/subtle/digest-malformed-parameters-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/digest-malformed-parameters.html [new file with mode: 0644]
LayoutTests/crypto/subtle/sha1-digest-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/sha1-digest.html [new file with mode: 0644]
LayoutTests/crypto/subtle/sha224-digest-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/sha224-digest.html [new file with mode: 0644]
LayoutTests/crypto/subtle/sha256-digest-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/sha256-digest.html [new file with mode: 0644]
LayoutTests/crypto/subtle/sha384-digest-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/sha384-digest.html [new file with mode: 0644]
LayoutTests/crypto/subtle/sha512-digest-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/sha512-digest.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/sha1-digest.js [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/sha224-digest.js [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/sha256-digest.js [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/sha384-digest.js [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/resources/sha512-digest.js [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/sha1-digest-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/sha1-digest.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/sha224-digest-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/sha224-digest.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/sha256-digest-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/sha256-digest.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/sha384-digest-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/sha384-digest.html [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/sha512-digest-expected.txt [new file with mode: 0644]
LayoutTests/crypto/workers/subtle/sha512-digest.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/WebCryptoAPI/digest/test_digest-expected.txt
LayoutTests/imported/w3c/WebCryptoAPI/idlharness-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
Source/WebCore/crypto/CryptoAlgorithm.cpp
Source/WebCore/crypto/CryptoAlgorithm.h
Source/WebCore/crypto/SubtleCrypto.idl
Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA1.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA1.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA224.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA224.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA256.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA256.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA384.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA384.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA512.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA512.h

index 1c4524f..3d656f2 100644 (file)
@@ -1,3 +1,39 @@
+2016-11-26  Jiewen Tan  <jiewen_tan@apple.com>
+
+        Update SubtleCrypto::digest to match the latest spec
+        https://bugs.webkit.org/show_bug.cgi?id=164742
+        <rdar://problem/29258037>
+
+        Reviewed by Darin Adler.
+
+        * crypto/subtle/digest-malformed-parameters-expected.txt: Added.
+        * crypto/subtle/digest-malformed-parameters.html: Added.
+        * crypto/subtle/sha1-digest-expected.txt: Added.
+        * crypto/subtle/sha1-digest.html: Added.
+        * crypto/subtle/sha224-digest-expected.txt: Added.
+        * crypto/subtle/sha224-digest.html: Added.
+        * crypto/subtle/sha256-digest-expected.txt: Added.
+        * crypto/subtle/sha256-digest.html: Added.
+        * crypto/subtle/sha384-digest-expected.txt: Added.
+        * crypto/subtle/sha384-digest.html: Added.
+        * crypto/subtle/sha512-digest-expected.txt: Added.
+        * crypto/subtle/sha512-digest.html: Added.
+        * crypto/workers/subtle/resources/sha1-digest.js: Added.
+        * crypto/workers/subtle/resources/sha224-digest.js: Added.
+        * crypto/workers/subtle/resources/sha256-digest.js: Added.
+        * crypto/workers/subtle/resources/sha384-digest.js: Added.
+        * crypto/workers/subtle/resources/sha512-digest.js: Added.
+        * crypto/workers/subtle/sha1-digest-expected.txt: Added.
+        * crypto/workers/subtle/sha1-digest.html: Added.
+        * crypto/workers/subtle/sha224-digest-expected.txt: Added.
+        * crypto/workers/subtle/sha224-digest.html: Added.
+        * crypto/workers/subtle/sha256-digest-expected.txt: Added.
+        * crypto/workers/subtle/sha256-digest.html: Added.
+        * crypto/workers/subtle/sha384-digest-expected.txt: Added.
+        * crypto/workers/subtle/sha384-digest.html: Added.
+        * crypto/workers/subtle/sha512-digest-expected.txt: Added.
+        * crypto/workers/subtle/sha512-digest.html: Added.
+
 2016-11-30  Antoine Quint  <graouts@apple.com>
 
         [Modern Media Controls] UI Library: <audio> controls
diff --git a/LayoutTests/crypto/subtle/digest-malformed-parameters-expected.txt b/LayoutTests/crypto/subtle/digest-malformed-parameters-expected.txt
new file mode 100644 (file)
index 0000000..203fa38
--- /dev/null
@@ -0,0 +1,11 @@
+Test digest with malformed parameters
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS crypto.subtle.digest() rejected promise  with TypeError: Not enough arguments.
+PASS crypto.subtle.digest(1) rejected promise  with TypeError: Not enough arguments.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/digest-malformed-parameters.html b/LayoutTests/crypto/subtle/digest-malformed-parameters.html
new file mode 100644 (file)
index 0000000..9a7b991
--- /dev/null
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test digest with malformed parameters");
+
+var message = asciiToUint8Array("Hello, World!");
+
+// Not enough arguments.
+shouldReject('crypto.subtle.digest()');
+shouldReject('crypto.subtle.digest(1)');
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/sha1-digest-expected.txt b/LayoutTests/crypto/subtle/sha1-digest-expected.txt
new file mode 100644 (file)
index 0000000..29a7b09
--- /dev/null
@@ -0,0 +1,10 @@
+Test digest with SHA-1
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(digest) is expectedDigest
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/sha1-digest.html b/LayoutTests/crypto/subtle/sha1-digest.html
new file mode 100644 (file)
index 0000000..862ac18
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test digest with SHA-1");
+
+jsTestIsAsync = true;
+
+var message = asciiToUint8Array("Hello, World!");
+var expectedDigest = "0a0a9f2a6772942557ab5355d76af442f8f65e01";
+
+crypto.subtle.digest("sha-1", message).then(function(result){
+    digest = result;
+    shouldBe("bytesToHexString(digest)", "expectedDigest");
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/sha224-digest-expected.txt b/LayoutTests/crypto/subtle/sha224-digest-expected.txt
new file mode 100644 (file)
index 0000000..70c25c4
--- /dev/null
@@ -0,0 +1,10 @@
+Test digest with SHA-224
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(digest) is expectedDigest
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/sha224-digest.html b/LayoutTests/crypto/subtle/sha224-digest.html
new file mode 100644 (file)
index 0000000..77d7490
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test digest with SHA-224");
+
+jsTestIsAsync = true;
+
+var message = asciiToUint8Array("Hello, World!");
+var expectedDigest = "72a23dfa411ba6fde01dbfabf3b00a709c93ebf273dc29e2d8b261ff";
+
+crypto.subtle.digest("sha-224", message).then(function(result){
+    digest = result;
+    shouldBe("bytesToHexString(digest)", "expectedDigest");
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/sha256-digest-expected.txt b/LayoutTests/crypto/subtle/sha256-digest-expected.txt
new file mode 100644 (file)
index 0000000..b58be50
--- /dev/null
@@ -0,0 +1,10 @@
+Test digest with SHA-256
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(digest) is expectedDigest
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/sha256-digest.html b/LayoutTests/crypto/subtle/sha256-digest.html
new file mode 100644 (file)
index 0000000..a8e7663
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test digest with SHA-256");
+
+jsTestIsAsync = true;
+
+var message = asciiToUint8Array("Hello, World!");
+var expectedDigest = "dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f";
+
+crypto.subtle.digest("sha-256", message).then(function(result){
+    digest = result;
+    shouldBe("bytesToHexString(digest)", "expectedDigest");
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/sha384-digest-expected.txt b/LayoutTests/crypto/subtle/sha384-digest-expected.txt
new file mode 100644 (file)
index 0000000..26d68f5
--- /dev/null
@@ -0,0 +1,10 @@
+Test digest with SHA-384
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(digest) is expectedDigest
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/sha384-digest.html b/LayoutTests/crypto/subtle/sha384-digest.html
new file mode 100644 (file)
index 0000000..fa3d4fe
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test digest with SHA-384");
+
+jsTestIsAsync = true;
+
+var message = asciiToUint8Array("Hello, World!");
+var expectedDigest = "5485cc9b3365b4305dfb4e8337e0a598a574f8242bf17289e0dd6c20a3cd44a089de16ab4ab308f63e44b1170eb5f515";
+
+crypto.subtle.digest("sha-384", message).then(function(result){
+    digest = result;
+    shouldBe("bytesToHexString(digest)", "expectedDigest");
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/sha512-digest-expected.txt b/LayoutTests/crypto/subtle/sha512-digest-expected.txt
new file mode 100644 (file)
index 0000000..450fbd6
--- /dev/null
@@ -0,0 +1,10 @@
+Test digest with SHA-512
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS bytesToHexString(digest) is expectedDigest
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/sha512-digest.html b/LayoutTests/crypto/subtle/sha512-digest.html
new file mode 100644 (file)
index 0000000..e46889a
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+<script src="../resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test digest with SHA-512");
+
+jsTestIsAsync = true;
+
+var message = asciiToUint8Array("Hello, World!");
+var expectedDigest = "374d794a95cdcfd8b35993185fef9ba368f160d8daf432d08ba9f1ed1e5abe6cc69291e0fa2fe0006a52570ef18c19def4e617c33ce52ef0a6e5fbe318cb0387";
+
+crypto.subtle.digest("sha-512", message).then(function(result){
+    digest = result;
+    shouldBe("bytesToHexString(digest)", "expectedDigest");
+    finishJSTest();
+});
+
+</script>
+
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/workers/subtle/resources/sha1-digest.js b/LayoutTests/crypto/workers/subtle/resources/sha1-digest.js
new file mode 100644 (file)
index 0000000..dd08fc4
--- /dev/null
@@ -0,0 +1,15 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts('../../../resources/common.js');
+
+description("Test digest with SHA-1 in workers");
+
+jsTestIsAsync = true;
+
+var message = asciiToUint8Array("Hello, World!");
+var expectedDigest = "0a0a9f2a6772942557ab5355d76af442f8f65e01";
+
+crypto.subtle.digest("sha-1", message).then(function(result){
+    digest = result;
+    shouldBe("bytesToHexString(digest)", "expectedDigest");
+    finishJSTest();
+});
diff --git a/LayoutTests/crypto/workers/subtle/resources/sha224-digest.js b/LayoutTests/crypto/workers/subtle/resources/sha224-digest.js
new file mode 100644 (file)
index 0000000..815625e
--- /dev/null
@@ -0,0 +1,15 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts('../../../resources/common.js');
+
+description("Test digest with SHA-224 in workers");
+
+jsTestIsAsync = true;
+
+var message = asciiToUint8Array("Hello, World!");
+var expectedDigest = "72a23dfa411ba6fde01dbfabf3b00a709c93ebf273dc29e2d8b261ff";
+
+crypto.subtle.digest("sha-224", message).then(function(result){
+    digest = result;
+    shouldBe("bytesToHexString(digest)", "expectedDigest");
+    finishJSTest();
+});
diff --git a/LayoutTests/crypto/workers/subtle/resources/sha256-digest.js b/LayoutTests/crypto/workers/subtle/resources/sha256-digest.js
new file mode 100644 (file)
index 0000000..1904b7f
--- /dev/null
@@ -0,0 +1,15 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts('../../../resources/common.js');
+
+description("Test digest with SHA-256 in workers");
+
+jsTestIsAsync = true;
+
+var message = asciiToUint8Array("Hello, World!");
+var expectedDigest = "dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f";
+
+crypto.subtle.digest("sha-256", message).then(function(result){
+    digest = result;
+    shouldBe("bytesToHexString(digest)", "expectedDigest");
+    finishJSTest();
+});
diff --git a/LayoutTests/crypto/workers/subtle/resources/sha384-digest.js b/LayoutTests/crypto/workers/subtle/resources/sha384-digest.js
new file mode 100644 (file)
index 0000000..2f12a5e
--- /dev/null
@@ -0,0 +1,15 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts('../../../resources/common.js');
+
+description("Test digest with SHA-384 in workers");
+
+jsTestIsAsync = true;
+
+var message = asciiToUint8Array("Hello, World!");
+var expectedDigest = "5485cc9b3365b4305dfb4e8337e0a598a574f8242bf17289e0dd6c20a3cd44a089de16ab4ab308f63e44b1170eb5f515";
+
+crypto.subtle.digest("sha-384", message).then(function(result){
+    digest = result;
+    shouldBe("bytesToHexString(digest)", "expectedDigest");
+    finishJSTest();
+});
diff --git a/LayoutTests/crypto/workers/subtle/resources/sha512-digest.js b/LayoutTests/crypto/workers/subtle/resources/sha512-digest.js
new file mode 100644 (file)
index 0000000..f769532
--- /dev/null
@@ -0,0 +1,15 @@
+importScripts('../../../../resources/js-test-pre.js');
+importScripts('../../../resources/common.js');
+
+description("Test digest with SHA-512 in workers");
+
+jsTestIsAsync = true;
+
+var message = asciiToUint8Array("Hello, World!");
+var expectedDigest = "374d794a95cdcfd8b35993185fef9ba368f160d8daf432d08ba9f1ed1e5abe6cc69291e0fa2fe0006a52570ef18c19def4e617c33ce52ef0a6e5fbe318cb0387";
+
+crypto.subtle.digest("sha-512", message).then(function(result){
+    digest = result;
+    shouldBe("bytesToHexString(digest)", "expectedDigest");
+    finishJSTest();
+});
diff --git a/LayoutTests/crypto/workers/subtle/sha1-digest-expected.txt b/LayoutTests/crypto/workers/subtle/sha1-digest-expected.txt
new file mode 100644 (file)
index 0000000..6265d31
--- /dev/null
@@ -0,0 +1,11 @@
+[Worker] Test digest with SHA-1 in workers
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/sha1-digest.js
+PASS [Worker] bytesToHexString(digest) is expectedDigest
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/workers/subtle/sha1-digest.html b/LayoutTests/crypto/workers/subtle/sha1-digest.html
new file mode 100644 (file)
index 0000000..e6d4bbf
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+    <script>
+        worker = startWorker('resources/sha1-digest.js');
+    </script>
+    <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/workers/subtle/sha224-digest-expected.txt b/LayoutTests/crypto/workers/subtle/sha224-digest-expected.txt
new file mode 100644 (file)
index 0000000..378d88e
--- /dev/null
@@ -0,0 +1,11 @@
+[Worker] Test digest with SHA-224 in workers
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/sha224-digest.js
+PASS [Worker] bytesToHexString(digest) is expectedDigest
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/workers/subtle/sha224-digest.html b/LayoutTests/crypto/workers/subtle/sha224-digest.html
new file mode 100644 (file)
index 0000000..d5598ac
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+    <script>
+        worker = startWorker('resources/sha224-digest.js');
+    </script>
+    <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/workers/subtle/sha256-digest-expected.txt b/LayoutTests/crypto/workers/subtle/sha256-digest-expected.txt
new file mode 100644 (file)
index 0000000..921b04d
--- /dev/null
@@ -0,0 +1,11 @@
+[Worker] Test digest with SHA-256 in workers
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/sha256-digest.js
+PASS [Worker] bytesToHexString(digest) is expectedDigest
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/workers/subtle/sha256-digest.html b/LayoutTests/crypto/workers/subtle/sha256-digest.html
new file mode 100644 (file)
index 0000000..7c1ee24
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+    <script>
+        worker = startWorker('resources/sha256-digest.js');
+    </script>
+    <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/workers/subtle/sha384-digest-expected.txt b/LayoutTests/crypto/workers/subtle/sha384-digest-expected.txt
new file mode 100644 (file)
index 0000000..6a8e4f8
--- /dev/null
@@ -0,0 +1,11 @@
+[Worker] Test digest with SHA-384 in workers
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/sha384-digest.js
+PASS [Worker] bytesToHexString(digest) is expectedDigest
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/workers/subtle/sha384-digest.html b/LayoutTests/crypto/workers/subtle/sha384-digest.html
new file mode 100644 (file)
index 0000000..c832bd8
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+    <script>
+        worker = startWorker('resources/sha384-digest.js');
+    </script>
+    <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/workers/subtle/sha512-digest-expected.txt b/LayoutTests/crypto/workers/subtle/sha512-digest-expected.txt
new file mode 100644 (file)
index 0000000..cfda74d
--- /dev/null
@@ -0,0 +1,11 @@
+[Worker] Test digest with SHA-512 in workers
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/sha512-digest.js
+PASS [Worker] bytesToHexString(digest) is expectedDigest
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/workers/subtle/sha512-digest.html b/LayoutTests/crypto/workers/subtle/sha512-digest.html
new file mode 100644 (file)
index 0000000..aee4524
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+    <script>
+        worker = startWorker('resources/sha512-digest.js');
+    </script>
+    <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
index 3bda441..40eff13 100644 (file)
@@ -1,3 +1,14 @@
+2016-11-26  Jiewen Tan  <jiewen_tan@apple.com>
+
+        Update SubtleCrypto::digest to match the latest spec
+        https://bugs.webkit.org/show_bug.cgi?id=164742
+        <rdar://problem/29258037>
+
+        Reviewed by Darin Adler.
+
+        * WebCryptoAPI/digest/test_digest-expected.txt:
+        * WebCryptoAPI/idlharness-expected.txt:
+
 2016-11-30  Jiewen Tan  <jiewen_tan@apple.com>
 
         Update SubtleCrypto::wrapKey to match the latest spec
index 5b9b29a..0432776 100644 (file)
@@ -1,84 +1,84 @@
 encrypt Tests for digest method
 
 
-FAIL SHA-1 with empty source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-1 with empty source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-1 with empty source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-1 with empty source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-256 with empty source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-256 with empty source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-256 with empty source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-256 with empty source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-384 with empty source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-384 with empty source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-384 with empty source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-384 with empty source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-512 with empty source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-512 with empty source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-512 with empty source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-512 with empty source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-1 with short source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-1 with short source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-1 with short source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-1 with short source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-256 with short source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-256 with short source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-256 with short source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-256 with short source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-384 with short source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-384 with short source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-384 with short source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-384 with short source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-512 with short source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-512 with short source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-512 with short source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-512 with short source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-1 with medium source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-1 with medium source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-1 with medium source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-1 with medium source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-256 with medium source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-256 with medium source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-256 with medium source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-256 with medium source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-384 with medium source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-384 with medium source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-384 with medium source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-384 with medium source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-512 with medium source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-512 with medium source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-512 with medium source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-512 with medium source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-1 with long source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-1 with long source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-1 with long source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-1 with long source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-256 with long source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-256 with long source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-256 with long source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-256 with long source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-384 with long source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-384 with long source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-384 with long source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-384 with long source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL SHA-512 with long source data subtle.digest is not a function. (In 'subtle.digest({name: upCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL sha-512 with long source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL Sha-512 with long source data subtle.digest is not a function. (In 'subtle.digest({name: mixedCase}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL SHA-512 with long source data and altered buffer after call subtle.digest is not a function. (In 'subtle.digest({name: upCase}, copiedBuffer)', 'subtle.digest' is undefined)
-FAIL AES-GCM with empty subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL RSA-OAEP with empty subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL PBKDF2 with empty subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL AES-KW with empty subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL AES-GCM with short subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL RSA-OAEP with short subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL PBKDF2 with short subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL AES-KW with short subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL AES-GCM with medium subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL RSA-OAEP with medium subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL PBKDF2 with medium subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL AES-KW with medium subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL AES-GCM with long subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL RSA-OAEP with long subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL PBKDF2 with long subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
-FAIL AES-KW with long subtle.digest is not a function. (In 'subtle.digest({name: badName}, sourceData[size])', 'subtle.digest' is undefined)
+PASS SHA-1 with empty source data 
+PASS sha-1 with empty source data 
+PASS Sha-1 with empty source data 
+PASS SHA-1 with empty source data and altered buffer after call 
+PASS SHA-256 with empty source data 
+PASS sha-256 with empty source data 
+PASS Sha-256 with empty source data 
+PASS SHA-256 with empty source data and altered buffer after call 
+PASS SHA-384 with empty source data 
+PASS sha-384 with empty source data 
+PASS Sha-384 with empty source data 
+PASS SHA-384 with empty source data and altered buffer after call 
+PASS SHA-512 with empty source data 
+PASS sha-512 with empty source data 
+PASS Sha-512 with empty source data 
+PASS SHA-512 with empty source data and altered buffer after call 
+PASS SHA-1 with short source data 
+PASS sha-1 with short source data 
+PASS Sha-1 with short source data 
+PASS SHA-1 with short source data and altered buffer after call 
+PASS SHA-256 with short source data 
+PASS sha-256 with short source data 
+PASS Sha-256 with short source data 
+PASS SHA-256 with short source data and altered buffer after call 
+PASS SHA-384 with short source data 
+PASS sha-384 with short source data 
+PASS Sha-384 with short source data 
+PASS SHA-384 with short source data and altered buffer after call 
+PASS SHA-512 with short source data 
+PASS sha-512 with short source data 
+PASS Sha-512 with short source data 
+PASS SHA-512 with short source data and altered buffer after call 
+PASS SHA-1 with medium source data 
+PASS sha-1 with medium source data 
+PASS Sha-1 with medium source data 
+PASS SHA-1 with medium source data and altered buffer after call 
+PASS SHA-256 with medium source data 
+PASS sha-256 with medium source data 
+PASS Sha-256 with medium source data 
+PASS SHA-256 with medium source data and altered buffer after call 
+PASS SHA-384 with medium source data 
+PASS sha-384 with medium source data 
+PASS Sha-384 with medium source data 
+PASS SHA-384 with medium source data and altered buffer after call 
+PASS SHA-512 with medium source data 
+PASS sha-512 with medium source data 
+PASS Sha-512 with medium source data 
+PASS SHA-512 with medium source data and altered buffer after call 
+PASS SHA-1 with long source data 
+PASS sha-1 with long source data 
+PASS Sha-1 with long source data 
+PASS SHA-1 with long source data and altered buffer after call 
+PASS SHA-256 with long source data 
+PASS sha-256 with long source data 
+PASS Sha-256 with long source data 
+PASS SHA-256 with long source data and altered buffer after call 
+PASS SHA-384 with long source data 
+PASS sha-384 with long source data 
+PASS Sha-384 with long source data 
+PASS SHA-384 with long source data and altered buffer after call 
+PASS SHA-512 with long source data 
+PASS sha-512 with long source data 
+PASS Sha-512 with long source data 
+PASS SHA-512 with long source data and altered buffer after call 
+PASS AES-GCM with empty 
+PASS RSA-OAEP with empty 
+PASS PBKDF2 with empty 
+PASS AES-KW with empty 
+PASS AES-GCM with short 
+PASS RSA-OAEP with short 
+PASS PBKDF2 with short 
+PASS AES-KW with short 
+PASS AES-GCM with medium 
+PASS RSA-OAEP with medium 
+PASS PBKDF2 with medium 
+PASS AES-KW with medium 
+PASS AES-GCM with long 
+PASS RSA-OAEP with long 
+PASS PBKDF2 with long 
+PASS AES-KW with long 
 
index a31b241..6e04953 100644 (file)
@@ -51,8 +51,8 @@ PASS SubtleCrypto interface: crypto.subtle must inherit property "sign" with the
 PASS SubtleCrypto interface: calling sign(AlgorithmIdentifier,CryptoKey,BufferSource) on crypto.subtle with too few arguments must throw TypeError 
 PASS SubtleCrypto interface: crypto.subtle must inherit property "verify" with the proper type (3) 
 PASS SubtleCrypto interface: calling verify(AlgorithmIdentifier,CryptoKey,BufferSource,BufferSource) on crypto.subtle with too few arguments must throw TypeError 
-FAIL SubtleCrypto interface: crypto.subtle must inherit property "digest" with the proper type (4) assert_inherits: property "digest" not found in prototype chain
-FAIL SubtleCrypto interface: calling digest(AlgorithmIdentifier,BufferSource) on crypto.subtle with too few arguments must throw TypeError assert_inherits: property "digest" not found in prototype chain
+PASS SubtleCrypto interface: crypto.subtle must inherit property "digest" with the proper type (4) 
+PASS SubtleCrypto interface: calling digest(AlgorithmIdentifier,BufferSource) on crypto.subtle with too few arguments must throw TypeError 
 PASS SubtleCrypto interface: crypto.subtle must inherit property "generateKey" with the proper type (5) 
 PASS SubtleCrypto interface: calling generateKey(AlgorithmIdentifier,boolean,[object Object]) on crypto.subtle with too few arguments must throw TypeError 
 FAIL SubtleCrypto interface: crypto.subtle must inherit property "deriveKey" with the proper type (6) assert_inherits: property "deriveKey" not found in prototype chain
index e13b920..b067657 100644 (file)
@@ -1,3 +1,53 @@
+2016-11-26  Jiewen Tan  <jiewen_tan@apple.com>
+
+        Update SubtleCrypto::digest to match the latest spec
+        https://bugs.webkit.org/show_bug.cgi?id=164742
+        <rdar://problem/29258037>
+
+        Reviewed by Darin Adler.
+
+        This patch updates the SubtleCrypto::digest method to match the latest spec:
+        https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-digest.
+        It also refers to the latest Editor's Draft to a certain degree:
+        https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-digest.
+        Currently supported digest algorithms are SHA-1, SHA-224, SHA-256, SHA-384,
+        and SHA-512.
+
+        Tests: crypto/subtle/digest-malformed-parameters.html
+               crypto/subtle/sha1-digest.html
+               crypto/subtle/sha224-digest.html
+               crypto/subtle/sha256-digest.html
+               crypto/subtle/sha384-digest.html
+               crypto/subtle/sha512-digest.html
+               crypto/workers/subtle/sha1-digest.html
+               crypto/workers/subtle/sha224-digest.html
+               crypto/workers/subtle/sha256-digest.html
+               crypto/workers/subtle/sha384-digest.html
+               crypto/workers/subtle/sha512-digest.html
+
+        * bindings/js/JSSubtleCryptoCustom.cpp:
+        (WebCore::jsSubtleCryptoFunctionDigestPromise):
+        (WebCore::JSSubtleCrypto::digest):
+        * crypto/CryptoAlgorithm.cpp:
+        (WebCore::CryptoAlgorithm::digest):
+        * crypto/CryptoAlgorithm.h:
+        * crypto/SubtleCrypto.idl:
+        * crypto/algorithms/CryptoAlgorithmSHA1.cpp:
+        (WebCore::CryptoAlgorithmSHA1::digest):
+        * crypto/algorithms/CryptoAlgorithmSHA1.h:
+        * crypto/algorithms/CryptoAlgorithmSHA224.cpp:
+        (WebCore::CryptoAlgorithmSHA224::digest):
+        * crypto/algorithms/CryptoAlgorithmSHA224.h:
+        * crypto/algorithms/CryptoAlgorithmSHA256.cpp:
+        (WebCore::CryptoAlgorithmSHA256::digest):
+        * crypto/algorithms/CryptoAlgorithmSHA256.h:
+        * crypto/algorithms/CryptoAlgorithmSHA384.cpp:
+        (WebCore::CryptoAlgorithmSHA384::digest):
+        * crypto/algorithms/CryptoAlgorithmSHA384.h:
+        * crypto/algorithms/CryptoAlgorithmSHA512.cpp:
+        (WebCore::CryptoAlgorithmSHA512::digest):
+        * crypto/algorithms/CryptoAlgorithmSHA512.h:
+
 2016-11-30  Antoine Quint  <graouts@apple.com>
 
         [Modern Media Controls] UI Library: <audio> controls
index 81533f1..2f98b91 100644 (file)
@@ -645,6 +645,38 @@ static void jsSubtleCryptoFunctionVerifyPromise(ExecState& state, Ref<DeferredPr
     algorithm->verify(key.releaseNonNull(), WTFMove(signature), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue());
 }
 
+static void jsSubtleCryptoFunctionDigestPromise(ExecState& state, Ref<DeferredPromise>&& promise)
+{
+    VM& vm = state.vm();
+    auto scope = DECLARE_THROW_SCOPE(vm);
+
+    if (UNLIKELY(state.argumentCount() < 2)) {
+        promise->reject<JSValue>(createNotEnoughArgumentsError(&state));
+        return;
+    }
+
+    auto params = normalizeCryptoAlgorithmParameters(state, state.uncheckedArgument(0), Operations::Digest);
+    RETURN_IF_EXCEPTION(scope, void());
+
+    auto data = toVector(state, state.uncheckedArgument(1));
+    RETURN_IF_EXCEPTION(scope, void());
+
+    auto algorithm = createAlgorithm(state, params->identifier);
+    RETURN_IF_EXCEPTION(scope, void());
+
+    auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& digest) mutable {
+        fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), digest.data(), digest.size());
+        return;
+    };
+    auto exceptionCallback = [capturedPromise = WTFMove(promise)](ExceptionCode ec) mutable {
+        rejectWithException(WTFMove(capturedPromise), ec);
+    };
+
+    auto subtle = jsDynamicDowncast<JSSubtleCrypto*>(state.thisValue());
+    ASSERT(subtle);
+    algorithm->digest(WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), *scriptExecutionContextFromExecState(&state), subtle->wrapped().workQueue());
+}
+
 static void jsSubtleCryptoFunctionGenerateKeyPromise(ExecState& state, Ref<DeferredPromise>&& promise)
 {
     VM& vm = state.vm();
@@ -910,6 +942,11 @@ JSValue JSSubtleCrypto::verify(ExecState& state)
     return callPromiseFunction<jsSubtleCryptoFunctionVerifyPromise, PromiseExecutionScope::WindowOrWorker>(state);
 }
 
+JSValue JSSubtleCrypto::digest(ExecState& state)
+{
+    return callPromiseFunction<jsSubtleCryptoFunctionDigestPromise, PromiseExecutionScope::WindowOrWorker>(state);
+}
+
 JSValue JSSubtleCrypto::generateKey(ExecState& state)
 {
     return callPromiseFunction<jsSubtleCryptoFunctionGenerateKeyPromise, PromiseExecutionScope::WindowOrWorker>(state);
index b1681ce..9752f9e 100644 (file)
@@ -52,6 +52,11 @@ void CryptoAlgorithm::verify(Ref<CryptoKey>&&, Vector<uint8_t>&&, Vector<uint8_t
     exceptionCallback(NOT_SUPPORTED_ERR);
 }
 
+void CryptoAlgorithm::digest(Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&, WorkQueue&)
+{
+    exceptionCallback(NOT_SUPPORTED_ERR);
+}
+
 void CryptoAlgorithm::generateKey(const CryptoAlgorithmParameters&, bool, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)
 {
     exceptionCallback(NOT_SUPPORTED_ERR);
index 22bb545..ce57914 100644 (file)
@@ -68,6 +68,7 @@ public:
     virtual void decrypt(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     virtual void sign(Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     virtual void verify(Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+    virtual void digest(Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
     virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsageBitmap, KeyOrKeyPairCallback&&, ExceptionCallback&&, ScriptExecutionContext&);
     virtual void importKey(SubtleCrypto::KeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&);
     virtual void exportKey(SubtleCrypto::KeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&);
index 53143df..ff25881 100644 (file)
@@ -35,6 +35,7 @@ enum KeyFormat { "raw", "spki", "pkcs8", "jwk" };
     [Custom] Promise<any> decrypt(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data);
     [Custom] Promise<any> sign(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource data);
     [Custom] Promise<any> verify(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource signature, BufferSource data);
+    [Custom] Promise<any> digest(AlgorithmIdentifier algorithm, BufferSource data);
     // FIXME: Should this return a Promise<(CryptoKey or CryptoKeyPair)>?
     [Custom] Promise<any> generateKey(AlgorithmIdentifier algorithm, boolean extractable, sequence<CryptoKeyUsage> keyUsages);
     [Custom] Promise<CryptoKey> importKey(KeyFormat format, (BufferSource or JsonWebKey) keyData, AlgorithmIdentifier algorithm, boolen extractable, sequence<CryptoKeyUsage> keyUsages);
index 5f1ad69..0c8dfdd 100644 (file)
@@ -29,6 +29,8 @@
 #if ENABLE(SUBTLE_CRYPTO)
 
 #include "CryptoDigest.h"
+#include "ExceptionCode.h"
+#include "ScriptExecutionContext.h"
 
 namespace WebCore {
 
@@ -42,6 +44,25 @@ CryptoAlgorithmIdentifier CryptoAlgorithmSHA1::identifier() const
     return s_identifier;
 }
 
+void CryptoAlgorithmSHA1::digest(Vector<uint8_t>&& message, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+    auto digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_1);
+    if (!digest) {
+        exceptionCallback(OperationError);
+        return;
+    }
+
+    context.ref();
+    workQueue.dispatch([digest = WTFMove(digest), message = WTFMove(message), callback = WTFMove(callback), &context]() mutable {
+        digest->addBytes(message.data(), message.size());
+        auto result = digest->computeHash();
+        context.postTask([callback = WTFMove(callback), result = WTFMove(result)](ScriptExecutionContext& context) {
+            callback(result);
+            context.deref();
+        });
+    });
+}
+
 ExceptionOr<void> CryptoAlgorithmSHA1::digest(const CryptoAlgorithmParametersDeprecated&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
 {
     auto digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_1);
index 18d1ce6..f355b49 100644 (file)
@@ -40,6 +40,7 @@ public:
 private:
     CryptoAlgorithmSHA1() = default;
     CryptoAlgorithmIdentifier identifier() const final;
+    void digest(Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     ExceptionOr<void> digest(const CryptoAlgorithmParametersDeprecated&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback) final;
 };
 
index 9fa945b..6ca1aee 100644 (file)
@@ -29,6 +29,8 @@
 #if ENABLE(SUBTLE_CRYPTO)
 
 #include "CryptoDigest.h"
+#include "ExceptionCode.h"
+#include "ScriptExecutionContext.h"
 
 namespace WebCore {
 
@@ -42,6 +44,25 @@ CryptoAlgorithmIdentifier CryptoAlgorithmSHA224::identifier() const
     return s_identifier;
 }
 
+void CryptoAlgorithmSHA224::digest(Vector<uint8_t>&& message, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+    auto digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_224);
+    if (!digest) {
+        exceptionCallback(OperationError);
+        return;
+    }
+
+    context.ref();
+    workQueue.dispatch([digest = WTFMove(digest), message = WTFMove(message), callback = WTFMove(callback), &context]() mutable {
+        digest->addBytes(message.data(), message.size());
+        auto result = digest->computeHash();
+        context.postTask([callback = WTFMove(callback), result = WTFMove(result)](ScriptExecutionContext& context) {
+            callback(result);
+            context.deref();
+        });
+    });
+}
+
 ExceptionOr<void> CryptoAlgorithmSHA224::digest(const CryptoAlgorithmParametersDeprecated&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
 {
     auto digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_224);
index 0b5462c..a5b1f63 100644 (file)
@@ -40,6 +40,7 @@ public:
 private:
     CryptoAlgorithmSHA224() = default;
     CryptoAlgorithmIdentifier identifier() const final;
+    void digest(Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     ExceptionOr<void> digest(const CryptoAlgorithmParametersDeprecated&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback) final;
 };
 
index 04c5f9a..73660f5 100644 (file)
@@ -29,6 +29,8 @@
 #if ENABLE(SUBTLE_CRYPTO)
 
 #include "CryptoDigest.h"
+#include "ExceptionCode.h"
+#include "ScriptExecutionContext.h"
 
 namespace WebCore {
 
@@ -42,6 +44,25 @@ CryptoAlgorithmIdentifier CryptoAlgorithmSHA256::identifier() const
     return s_identifier;
 }
 
+void CryptoAlgorithmSHA256::digest(Vector<uint8_t>&& message, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+    auto digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_256);
+    if (!digest) {
+        exceptionCallback(OperationError);
+        return;
+    }
+
+    context.ref();
+    workQueue.dispatch([digest = WTFMove(digest), message = WTFMove(message), callback = WTFMove(callback), &context]() mutable {
+        digest->addBytes(message.data(), message.size());
+        auto result = digest->computeHash();
+        context.postTask([callback = WTFMove(callback), result = WTFMove(result)](ScriptExecutionContext& context) {
+            callback(result);
+            context.deref();
+        });
+    });
+}
+
 ExceptionOr<void> CryptoAlgorithmSHA256::digest(const CryptoAlgorithmParametersDeprecated&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
 {
     auto digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_256);
index 9db3215..c2acc82 100644 (file)
@@ -40,6 +40,7 @@ public:
 private:
     CryptoAlgorithmSHA256() = default;
     CryptoAlgorithmIdentifier identifier() const final;
+    void digest(Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     ExceptionOr<void> digest(const CryptoAlgorithmParametersDeprecated&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback) final;
 };
 
index bc8866d..c97752d 100644 (file)
@@ -29,6 +29,8 @@
 #if ENABLE(SUBTLE_CRYPTO)
 
 #include "CryptoDigest.h"
+#include "ExceptionCode.h"
+#include "ScriptExecutionContext.h"
 
 namespace WebCore {
 
@@ -42,6 +44,25 @@ CryptoAlgorithmIdentifier CryptoAlgorithmSHA384::identifier() const
     return s_identifier;
 }
 
+void CryptoAlgorithmSHA384::digest(Vector<uint8_t>&& message, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+    auto digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_384);
+    if (!digest) {
+        exceptionCallback(OperationError);
+        return;
+    }
+
+    context.ref();
+    workQueue.dispatch([digest = WTFMove(digest), message = WTFMove(message), callback = WTFMove(callback), &context]() mutable {
+        digest->addBytes(message.data(), message.size());
+        auto result = digest->computeHash();
+        context.postTask([callback = WTFMove(callback), result = WTFMove(result)](ScriptExecutionContext& context) {
+            callback(result);
+            context.deref();
+        });
+    });
+}
+
 ExceptionOr<void> CryptoAlgorithmSHA384::digest(const CryptoAlgorithmParametersDeprecated&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
 {
     auto digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_384);
index 1e1f2b0..4f7bab4 100644 (file)
@@ -40,6 +40,7 @@ public:
 private:
     CryptoAlgorithmSHA384() = default;
     CryptoAlgorithmIdentifier identifier() const final;
+    void digest(Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     ExceptionOr<void> digest(const CryptoAlgorithmParametersDeprecated&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback) final;
 };
 
index 7f0748d..33e483d 100644 (file)
@@ -29,6 +29,8 @@
 #if ENABLE(SUBTLE_CRYPTO)
 
 #include "CryptoDigest.h"
+#include "ExceptionCode.h"
+#include "ScriptExecutionContext.h"
 
 namespace WebCore {
 
@@ -42,6 +44,25 @@ CryptoAlgorithmIdentifier CryptoAlgorithmSHA512::identifier() const
     return s_identifier;
 }
 
+void CryptoAlgorithmSHA512::digest(Vector<uint8_t>&& message, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+{
+    auto digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_512);
+    if (!digest) {
+        exceptionCallback(OperationError);
+        return;
+    }
+
+    context.ref();
+    workQueue.dispatch([digest = WTFMove(digest), message = WTFMove(message), callback = WTFMove(callback), &context]() mutable {
+        digest->addBytes(message.data(), message.size());
+        auto result = digest->computeHash();
+        context.postTask([callback = WTFMove(callback), result = WTFMove(result)](ScriptExecutionContext& context) {
+            callback(result);
+            context.deref();
+        });
+    });
+}
+
 ExceptionOr<void> CryptoAlgorithmSHA512::digest(const CryptoAlgorithmParametersDeprecated&, const CryptoOperationData& data, VectorCallback&& callback, VoidCallback&& failureCallback)
 {
     auto digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_512);
index 0f67156..b53971e 100644 (file)
@@ -40,6 +40,7 @@ public:
 private:
     CryptoAlgorithmSHA512() = default;
     CryptoAlgorithmIdentifier identifier() const final;
+    void digest(Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&) final;
     ExceptionOr<void> digest(const CryptoAlgorithmParametersDeprecated&, const CryptoOperationData&, VectorCallback&&, VoidCallback&& failureCallback) final;
 };