2011-02-12 Adam Barth <abarth@webkit.org>
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 12 Feb 2011 22:13:15 +0000 (22:13 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 12 Feb 2011 22:13:15 +0000 (22:13 +0000)
        Reviewed by Sam Weinig.

        crypto.getRandomValues should support all integer array types
        https://bugs.webkit.org/show_bug.cgi?id=54342

        Test which types of arrays work with crypto.getRandomValues.

        * security/crypto-random-values-types-expected.txt: Added.
        * security/crypto-random-values-types.html: Added.
2011-02-12  Adam Barth  <abarth@webkit.org>

        Reviewed by Sam Weinig.

        crypto.getRandomValues should support all integer array types
        https://bugs.webkit.org/show_bug.cgi?id=54342

        As discussed on whatwg, we should support all the integer array types.

        Test: security/crypto-random-values-types.html

        * page/Crypto.cpp:
        (WebCore::Crypto::getRandomValues):

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

LayoutTests/ChangeLog
LayoutTests/security/crypto-random-values-types-expected.txt [new file with mode: 0644]
LayoutTests/security/crypto-random-values-types.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/Crypto.cpp

index ca05de8..0f8ba4f 100644 (file)
@@ -1,3 +1,15 @@
+2011-02-12  Adam Barth  <abarth@webkit.org>
+
+        Reviewed by Sam Weinig.
+
+        crypto.getRandomValues should support all integer array types
+        https://bugs.webkit.org/show_bug.cgi?id=54342
+
+        Test which types of arrays work with crypto.getRandomValues.
+
+        * security/crypto-random-values-types-expected.txt: Added.
+        * security/crypto-random-values-types.html: Added.
+
 2011-02-12  Jochen Eisinger  <jochen@chromium.org>
 
         Reviewed by Jeremy Orlow.
diff --git a/LayoutTests/security/crypto-random-values-types-expected.txt b/LayoutTests/security/crypto-random-values-types-expected.txt
new file mode 100644 (file)
index 0000000..802cec8
--- /dev/null
@@ -0,0 +1,18 @@
+Tests which types are valid for crypto.randomValues.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS 'crypto' in window is true
+PASS 'getRandomValues' in window.crypto is true
+PASS crypto.getRandomValues(new Uint8Array(3)) is undefined.
+PASS crypto.getRandomValues(new Int8Array(3)) is undefined.
+PASS crypto.getRandomValues(new Uint16Array(3)) is undefined.
+PASS crypto.getRandomValues(new Int16Array(3)) is undefined.
+PASS crypto.getRandomValues(new Uint32Array(3)) is undefined.
+PASS crypto.getRandomValues(new Int32Array(3)) is undefined.
+PASS crypto.getRandomValues(new Float32Array(3)) threw exception Error: VALIDATION_ERR: DOM Exception 16.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/security/crypto-random-values-types.html b/LayoutTests/security/crypto-random-values-types.html
new file mode 100644 (file)
index 0000000..ba844f9
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
+<script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/utilities.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description("Tests which types are valid for crypto.randomValues.");
+
+if (!window.ArrayBuffer)
+    debug("This test requres ArrayBuffers to run!");
+
+shouldBe("'crypto' in window", "true");
+shouldBe("'getRandomValues' in window.crypto", "true");
+
+shouldBeUndefined("crypto.getRandomValues(new Uint8Array(3))");
+shouldBeUndefined("crypto.getRandomValues(new Int8Array(3))");
+shouldBeUndefined("crypto.getRandomValues(new Uint16Array(3))");
+shouldBeUndefined("crypto.getRandomValues(new Int16Array(3))");
+shouldBeUndefined("crypto.getRandomValues(new Uint32Array(3))");
+shouldBeUndefined("crypto.getRandomValues(new Int32Array(3))");
+
+shouldThrow("crypto.getRandomValues(new Float32Array(3))");
+
+var successfullyParsed = true;
+</script>
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
+
+
index f088f66..eb88eb4 100644 (file)
@@ -1,5 +1,19 @@
 2011-02-12  Adam Barth  <abarth@webkit.org>
 
+        Reviewed by Sam Weinig.
+
+        crypto.getRandomValues should support all integer array types
+        https://bugs.webkit.org/show_bug.cgi?id=54342
+
+        As discussed on whatwg, we should support all the integer array types.
+
+        Test: security/crypto-random-values-types.html
+
+        * page/Crypto.cpp:
+        (WebCore::Crypto::getRandomValues):
+
+2011-02-12  Adam Barth  <abarth@webkit.org>
+
         Reviewed by Mark Rowe.
 
         Use /dev/urandom as the OSRandomSource on OS(DARWIN)
index 0b1795e..7d5a76b 100644 (file)
 #include "Uint8Array.h"
 #include <wtf/CryptographicallyRandomNumber.h>
 
-
 namespace WebCore {
 
+namespace {
+
+bool isIntegerArray(ArrayBufferView* array)
+{
+    return array->isByteArray()
+        || array->isUnsignedByteArray()
+        || array->isShortArray()
+        || array->isUnsignedShortArray()
+        || array->isIntArray()
+        || array->isUnsignedIntArray();
+}
+
+}
+
 Crypto::Crypto()
 {
 }
@@ -44,7 +57,7 @@ Crypto::Crypto()
 void Crypto::getRandomValues(ArrayBufferView* array, ExceptionCode& ec)
 {
 #if USE(OS_RANDOMNESS)
-    if (!array || !array->isUnsignedByteArray()) {
+    if (!array || !isIntegerArray(array)) {
         ec = VALIDATION_ERR;
         return;
     }