WebCrypto no longer uses sequences of ArrayBuffers
authorap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Nov 2013 18:58:39 +0000 (18:58 +0000)
committerap@apple.com <ap@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Nov 2013 18:58:39 +0000 (18:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=124451

Reviewed by Sam Weinig.

Source/WebCore:

Covered by existing tests.

Changed all operations to take single CryptoOperationData objects.

* bindings/js/JSCryptoOperationData.cpp:
* bindings/js/JSCryptoOperationData.h:
* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::JSSubtleCrypto::encrypt):
(WebCore::JSSubtleCrypto::decrypt):
(WebCore::JSSubtleCrypto::sign):
(WebCore::JSSubtleCrypto::verify):
(WebCore::JSSubtleCrypto::digest):
* crypto/CryptoAlgorithm.cpp:
(WebCore::CryptoAlgorithm::encrypt):
(WebCore::CryptoAlgorithm::decrypt):
(WebCore::CryptoAlgorithm::sign):
(WebCore::CryptoAlgorithm::verify):
(WebCore::CryptoAlgorithm::digest):
* crypto/CryptoAlgorithm.h:
* crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify):
* crypto/algorithms/CryptoAlgorithmAES_CBC.h:
* crypto/algorithms/CryptoAlgorithmHMAC.h:
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
* 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:
* crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
(WebCore::transformAES_CBC):
(WebCore::CryptoAlgorithmAES_CBC::encrypt):
(WebCore::CryptoAlgorithmAES_CBC::decrypt):
* crypto/mac/CryptoAlgorithmHMACMac.cpp:
(WebCore::calculateSignature):
(WebCore::CryptoAlgorithmHMAC::sign):
(WebCore::CryptoAlgorithmHMAC::verify):
* crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:

LayoutTests:

Updated tests accordingly.

* crypto/subtle/aes-cbc-192-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-256-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-encrypt-decrypt-expected.txt:
* crypto/subtle/aes-cbc-encrypt-decrypt-with-padding.html:
* crypto/subtle/aes-cbc-encrypt-decrypt.html:
* crypto/subtle/aes-cbc-import-jwk.html:
* crypto/subtle/aes-cbc-wrong-key-class-expected.txt:
* crypto/subtle/aes-cbc-wrong-key-class.html:
* crypto/subtle/argument-conversion-expected.txt:
* crypto/subtle/argument-conversion.html:
* crypto/subtle/hmac-import-jwk.html:
* crypto/subtle/hmac-sign-verify-empty-key.html:
* crypto/subtle/hmac-sign-verify.html:
* crypto/subtle/rsassa-pkcs1-v1_5-sign-verify.html:
* crypto/subtle/sha-1-expected.txt:
* crypto/subtle/sha-1.html:
* crypto/subtle/sha-224-expected.txt:
* crypto/subtle/sha-224.html:
* crypto/subtle/sha-256-expected.txt:
* crypto/subtle/sha-256.html:
* crypto/subtle/sha-384-expected.txt:
* crypto/subtle/sha-384.html:
* crypto/subtle/sha-512-expected.txt:
* crypto/subtle/sha-512.html:

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

48 files changed:
LayoutTests/ChangeLog
LayoutTests/crypto/subtle/aes-cbc-192-encrypt-decrypt.html
LayoutTests/crypto/subtle/aes-cbc-256-encrypt-decrypt.html
LayoutTests/crypto/subtle/aes-cbc-encrypt-decrypt-expected.txt
LayoutTests/crypto/subtle/aes-cbc-encrypt-decrypt-with-padding.html
LayoutTests/crypto/subtle/aes-cbc-encrypt-decrypt.html
LayoutTests/crypto/subtle/aes-cbc-import-jwk.html
LayoutTests/crypto/subtle/aes-cbc-wrong-key-class-expected.txt
LayoutTests/crypto/subtle/aes-cbc-wrong-key-class.html
LayoutTests/crypto/subtle/argument-conversion-expected.txt
LayoutTests/crypto/subtle/argument-conversion.html
LayoutTests/crypto/subtle/hmac-import-jwk.html
LayoutTests/crypto/subtle/hmac-sign-verify-empty-key.html
LayoutTests/crypto/subtle/hmac-sign-verify.html
LayoutTests/crypto/subtle/rsassa-pkcs1-v1_5-sign-verify.html
LayoutTests/crypto/subtle/sha-1-expected.txt
LayoutTests/crypto/subtle/sha-1.html
LayoutTests/crypto/subtle/sha-224-expected.txt
LayoutTests/crypto/subtle/sha-224.html
LayoutTests/crypto/subtle/sha-256-expected.txt
LayoutTests/crypto/subtle/sha-256.html
LayoutTests/crypto/subtle/sha-384-expected.txt
LayoutTests/crypto/subtle/sha-384.html
LayoutTests/crypto/subtle/sha-512-expected.txt
LayoutTests/crypto/subtle/sha-512.html
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSCryptoOperationData.cpp
Source/WebCore/bindings/js/JSCryptoOperationData.h
Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
Source/WebCore/crypto/CryptoAlgorithm.cpp
Source/WebCore/crypto/CryptoAlgorithm.h
Source/WebCore/crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h
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
Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp
Source/WebCore/crypto/mac/CryptoAlgorithmHMACMac.cpp
Source/WebCore/crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h

index 50c1a7c..4527b8d 100644 (file)
@@ -1,3 +1,37 @@
+2013-11-16  Alexey Proskuryakov  <ap@apple.com>
+
+        WebCrypto no longer uses sequences of ArrayBuffers
+        https://bugs.webkit.org/show_bug.cgi?id=124451
+
+        Reviewed by Sam Weinig.
+
+        Updated tests accordingly.
+
+        * crypto/subtle/aes-cbc-192-encrypt-decrypt.html:
+        * crypto/subtle/aes-cbc-256-encrypt-decrypt.html:
+        * crypto/subtle/aes-cbc-encrypt-decrypt-expected.txt:
+        * crypto/subtle/aes-cbc-encrypt-decrypt-with-padding.html:
+        * crypto/subtle/aes-cbc-encrypt-decrypt.html:
+        * crypto/subtle/aes-cbc-import-jwk.html:
+        * crypto/subtle/aes-cbc-wrong-key-class-expected.txt:
+        * crypto/subtle/aes-cbc-wrong-key-class.html:
+        * crypto/subtle/argument-conversion-expected.txt:
+        * crypto/subtle/argument-conversion.html:
+        * crypto/subtle/hmac-import-jwk.html:
+        * crypto/subtle/hmac-sign-verify-empty-key.html:
+        * crypto/subtle/hmac-sign-verify.html:
+        * crypto/subtle/rsassa-pkcs1-v1_5-sign-verify.html:
+        * crypto/subtle/sha-1-expected.txt:
+        * crypto/subtle/sha-1.html:
+        * crypto/subtle/sha-224-expected.txt:
+        * crypto/subtle/sha-224.html:
+        * crypto/subtle/sha-256-expected.txt:
+        * crypto/subtle/sha-256.html:
+        * crypto/subtle/sha-384-expected.txt:
+        * crypto/subtle/sha-384.html:
+        * crypto/subtle/sha-512-expected.txt:
+        * crypto/subtle/sha-512.html:
+
 2013-11-15  Alexey Proskuryakov  <ap@apple.com>
 
         Support exporting symmetric keys as JWK
index 77a30bc..2f4047b 100644 (file)
@@ -28,13 +28,13 @@ crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "dec
     shouldBe("key.usages", "['encrypt', 'decrypt']");
 
     debug("Using the key to encrypt plaintext...");
-    return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
+    return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext);
 }).then(function(result) {
     encryptionResult = result;
     shouldBe("bytesToHexString(new Uint8Array(encryptionResult))", "'4f021db243bc633d7178183a9fa071e8b4d9ada9ad7dedf4e5e738763f69145a571b242012fb7ae07fa9baac3df102e008b0e27988598881d920a9e64f5615cd612ccd79224b350935d45dd6a98f8176'");
 
     debug("Decrypting it back...");
-    return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, [result]);
+    return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, result);
 }).then(function(result) {
     decryptionResult = result;
     shouldBe("new Uint8Array(decryptionResult)", "plaintext");
index 3e430e6..22f716f 100644 (file)
@@ -28,13 +28,13 @@ crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "dec
     shouldBe("key.usages", "['encrypt', 'decrypt']");
 
     debug("Using the key to encrypt plaintext...");
-    return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
+    return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext);
 }).then(function(result) {
     encryptionResult = result;
     shouldBe("bytesToHexString(new Uint8Array(encryptionResult))", "'f58c4c04d6e5f1ba779eabfb5f7bfbd69cfc4e967edb808d679f777bc6702c7d39f23369a9d9bacfa530e26304231461b2eb05e2c39be9fcda6c19078c6a9d1b3f461796d6b0d6b2e0c2a72b4d80e644'");
 
     debug("Decrypting it back...");
-    return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, [result]);
+    return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, result);
 }).then(function(result) {
     decryptionResult = result;
     shouldBe("new Uint8Array(decryptionResult)", "plaintext");
index 0cb5a85..eaacde9 100644 (file)
@@ -14,10 +14,10 @@ PASS bytesToHexString(new Uint8Array(encryptionResult)) is '7649abac8119b246cee9
 Decrypting it back...
 PASS new Uint8Array(decryptionResult) is plaintext
 Testing initialization vector bindings...
-PASS crypto.subtle.encrypt({name: 'AES-CBC', iv: null}, key, [plaintext]) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
-PASS crypto.subtle.encrypt({name: 'AES-CBC'}, key, [plaintext]) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
-PASS crypto.subtle.encrypt({name: 'AES-CBC', iv: 3}, key, [plaintext]) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
-PASS crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array([0])}, key, [plaintext]) threw exception Error: AES-CBC initialization data must be 16 bytes.
+PASS crypto.subtle.encrypt({name: 'AES-CBC', iv: null}, key, plaintext) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
+PASS crypto.subtle.encrypt({name: 'AES-CBC'}, key, plaintext) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
+PASS crypto.subtle.encrypt({name: 'AES-CBC', iv: 3}, key, plaintext) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
+PASS crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array([0])}, key, plaintext) threw exception Error: AES-CBC initialization data must be 16 bytes.
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 735250a..6d00c92 100644 (file)
@@ -28,13 +28,13 @@ crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "dec
     shouldBe("key.usages", "['encrypt', 'decrypt']");
 
     debug("Using the key to encrypt plaintext...");
-    return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
+    return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext);
 }).then(function(result) {
     cyphertext = result;
     shouldBe("bytesToHexString(new Uint8Array(cyphertext))", "'630199c5f202cc7167bb84c6c72b349d'");
 
     debug("Decrypting it back...");
-    return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, [result]);
+    return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, result);
 }).then(function(result) {
     decryptionResult = result;
     shouldBe("new Uint8Array(decryptionResult)", "plaintext");
index 1018fd7..510554c 100644 (file)
@@ -28,22 +28,22 @@ crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "dec
     shouldBe("key.usages", "['encrypt', 'decrypt']");
 
     debug("Using the key to encrypt plaintext...");
-    return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
+    return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext);
 }).then(function(result) {
     encryptionResult = result;
     shouldBe("bytesToHexString(new Uint8Array(encryptionResult))", "'7649abac8119b246cee98e9b12e9197d5086cb9b507219ee95db113a917678b273bed6b8e3c1743b7116e69e222295163ff1caa1681fac09120eca307586e1a78cb82807230e1321d3fae00d18cc2012'");
 
     debug("Decrypting it back...");
-    return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, [result]);
+    return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, result);
 }).then(function(result) {
     decryptionResult = result;
     shouldBe("new Uint8Array(decryptionResult)", "plaintext");
 
     debug("Testing initialization vector bindings...");
-    shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC', iv: null}, key, [plaintext])");
-    shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC'}, key, [plaintext])");
-    shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC', iv: 3}, key, [plaintext])");
-    shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array([0])}, key, [plaintext])");
+    shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC', iv: null}, key, plaintext)");
+    shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC'}, key, plaintext)");
+    shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC', iv: 3}, key, plaintext)");
+    shouldThrow("crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array([0])}, key, plaintext)");
 
     finishJSTest();
 });
index 30283a4..07a97b5 100644 (file)
@@ -39,7 +39,7 @@ crypto.subtle.importKey("jwk", jwkKeyAsArrayBuffer, null, false, ["encrypt"]).th
     shouldBe("key.usages", '["encrypt"]');
 
     debug("\nUsing the key to encrypt plaintext...");
-    return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]);
+    return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext);
 }).then(function(result) {
     encryptionResult = result;
     shouldBe("bytesToHexString(new Uint8Array(encryptionResult))", "'4f021db243bc633d7178183a9fa071e8b4d9ada9ad7dedf4e5e738763f69145a571b242012fb7ae07fa9baac3df102e008b0e27988598881d920a9e64f5615cd612ccd79224b350935d45dd6a98f8176'");
index 27bd653..dcd086f 100644 (file)
@@ -5,7 +5,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
 
 Importing a raw HMAC key from string literal...
 Using the key to encrypt plaintext...
-PASS crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext]) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext) threw exception Error: NotSupportedError: DOM Exception 9.
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 94299b4..c24b3e7 100644 (file)
@@ -22,7 +22,7 @@ debug("Importing a raw HMAC key from string literal...");
 crypto.subtle.importKey("raw", hmacKey, {name: 'hmac', hash: {name: 'sha-1'}}, extractable, ["sign", "verify", "encrypt", "decrypt"]).then(function(result) {
     key = result;
     debug("Using the key to encrypt plaintext...");
-    shouldThrow('crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, [plaintext])')
+    shouldThrow('crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext)')
 
     finishJSTest();
 });
index c219dfa..7aa9e3a 100644 (file)
@@ -3,8 +3,6 @@ Test crypto.subtle argument conversion
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-SHA1 of new Uint8Array([]))
-PASS bytesToHexString(new Uint8Array(digest)) is 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
 
 Passing algorithm name as a string object...
 PASS ...succeeded
@@ -17,23 +15,23 @@ PASS ...succeeded
 
 Passing invalid data to digest()
 PASS crypto.subtle.digest({name: 'sha-1'}) threw exception TypeError: Not enough arguments.
-PASS crypto.subtle.digest({name: 'sha-1'}, null) threw exception TypeError: Value is not a sequence.
-PASS crypto.subtle.digest({name: 'sha-1'}, 10) threw exception TypeError: Value is not a sequence.
-PASS crypto.subtle.digest({name: 'sha-1'}, [10]) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be part of CryptoOperationData sequence.
-PASS crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([0])) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be part of CryptoOperationData sequence.
+PASS crypto.subtle.digest({name: 'sha-1'}, null) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
+PASS crypto.subtle.digest({name: 'sha-1'}, 10) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
+PASS crypto.subtle.digest({name: 'sha-1'}, [10]) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
+PASS crypto.subtle.digest({name: 'sha-1'}, [new Uint8Array([0])]) threw exception TypeError: Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData.
 
 Passing invalid algorithmIdentifiers to digest()
-PASS crypto.subtle.digest({ toString:function() { return 'sha-1' } }, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
-PASS crypto.subtle.digest({name: ''}, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
-PASS crypto.subtle.digest({name: null}, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
-PASS crypto.subtle.digest({name: undefined}, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
-PASS crypto.subtle.digest({name: 'sha'}, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
-PASS crypto.subtle.digest({name: 1}, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
-PASS crypto.subtle.digest('', [data]) threw exception Error: NotSupportedError: DOM Exception 9.
-PASS crypto.subtle.digest(null, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
-PASS crypto.subtle.digest(undefined, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
-PASS crypto.subtle.digest(1, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
-PASS crypto.subtle.digest({}, [data]) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS crypto.subtle.digest({ toString:function() { return 'sha-1' } }, data) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS crypto.subtle.digest({name: ''}, data) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS crypto.subtle.digest({name: null}, data) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS crypto.subtle.digest({name: undefined}, data) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS crypto.subtle.digest({name: 'sha'}, data) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS crypto.subtle.digest({name: 1}, data) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS crypto.subtle.digest('', data) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS crypto.subtle.digest(null, data) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS crypto.subtle.digest(undefined, data) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS crypto.subtle.digest(1, data) threw exception Error: NotSupportedError: DOM Exception 9.
+PASS crypto.subtle.digest({}, data) threw exception Error: NotSupportedError: DOM Exception 9.
 PASS successfullyParsed is true
 
 TEST COMPLETE
index d3f589b..4fafd87 100644 (file)
@@ -14,24 +14,16 @@ description("Test crypto.subtle argument conversion");
 jsTestIsAsync = true;
 
 Promise.fulfill(null).then(function() {
-    // This looks like invalid input, but it actually isn't - Uint8Array is a sequence too,
-    // so it's just an empty sequence, same as passing [].
-    debug("SHA1 of new Uint8Array([]))");
-    return crypto.subtle.digest('sha-1', new Uint8Array([]));
-}).then(function(result) {
-    digest = result;
-    shouldBe("bytesToHexString(new Uint8Array(digest))", "'da39a3ee5e6b4b0d3255bfef95601890afd80709'");
-
     debug("\nPassing algorithm name as a string object...");
-    return crypto.subtle.digest(new String('sha-1'), []);
+    return crypto.subtle.digest(new String('sha-1'), new Uint8Array([]));
 }).then(function(result) {
     testPassed("...succeeded");
     debug("\nPassing algorithm name as a string object in a dictionary...");
-    return crypto.subtle.digest({name: new String('sha-1')}, []);
+    return crypto.subtle.digest({name: new String('sha-1')}, new Uint8Array([]));
 }).then(function(result) {
     testPassed("...succeeded");
     debug("\nPassing algorithm name as an object with toString");
-    return crypto.subtle.digest({name: { toString:function() { return 'sha-1' } } }, []);
+    return crypto.subtle.digest({name: { toString:function() { return 'sha-1' } } }, new Uint8Array([]));
 }).then(function(result) {
     testPassed("...succeeded");
 
@@ -40,21 +32,21 @@ Promise.fulfill(null).then(function() {
     shouldThrow("crypto.subtle.digest({name: 'sha-1'}, null)");
     shouldThrow("crypto.subtle.digest({name: 'sha-1'}, 10)");
     shouldThrow("crypto.subtle.digest({name: 'sha-1'}, [10])");
-    shouldThrow("crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([0]))");
+    shouldThrow("crypto.subtle.digest({name: 'sha-1'}, [new Uint8Array([0])])");
 
     debug("\nPassing invalid algorithmIdentifiers to digest()");
     data = new Uint8Array([0]);
-    shouldThrow("crypto.subtle.digest({ toString:function() { return 'sha-1' } }, [data])"); // Algorithm normalization doesn't attempt to call toString.
-    shouldThrow("crypto.subtle.digest({name: ''}, [data])");
-    shouldThrow("crypto.subtle.digest({name: null}, [data])");
-    shouldThrow("crypto.subtle.digest({name: undefined}, [data])");
-    shouldThrow("crypto.subtle.digest({name: 'sha'}, [data])");
-    shouldThrow("crypto.subtle.digest({name: 1}, [data])");
-    shouldThrow("crypto.subtle.digest('', [data])");
-    shouldThrow("crypto.subtle.digest(null, [data])");
-    shouldThrow("crypto.subtle.digest(undefined, [data])");
-    shouldThrow("crypto.subtle.digest(1, [data])");
-    shouldThrow("crypto.subtle.digest({}, [data])");
+    shouldThrow("crypto.subtle.digest({ toString:function() { return 'sha-1' } }, data)"); // Algorithm normalization doesn't attempt to call toString.
+    shouldThrow("crypto.subtle.digest({name: ''}, data)");
+    shouldThrow("crypto.subtle.digest({name: null}, data)");
+    shouldThrow("crypto.subtle.digest({name: undefined}, data)");
+    shouldThrow("crypto.subtle.digest({name: 'sha'}, data)");
+    shouldThrow("crypto.subtle.digest({name: 1}, data)");
+    shouldThrow("crypto.subtle.digest('', data)");
+    shouldThrow("crypto.subtle.digest(null, data)");
+    shouldThrow("crypto.subtle.digest(undefined, data)");
+    shouldThrow("crypto.subtle.digest(1, data)");
+    shouldThrow("crypto.subtle.digest({}, data)");
 }).then(finishJSTest);
 
 </script>
index a9352a0..a156bb2 100644 (file)
@@ -36,13 +36,13 @@ crypto.subtle.importKey("jwk", hmacKeyAsArrayBuffer, null, extractable, ["sign",
     shouldBe("key.usages", '["sign", "verify"]');
 
     debug("\nUsing the key to sign message 'foo'...");
-    return crypto.subtle.sign(key.algorithm, key, [asciiToUint8Array('foo')]);
+    return crypto.subtle.sign(key.algorithm, key, asciiToUint8Array('foo'));
 }).then(function(result) {
     signature = result;
     shouldBe("bytesToHexString(new Uint8Array(signature))", "'e03736fe098892b2a2da77812431f7c014d32e2fd69f3bcff883ac923a8fa2da'");
 
     debug("\nVerifying the signature...");
-    return crypto.subtle.verify(key.algorithm, key, result, [asciiToUint8Array('foo')]);
+    return crypto.subtle.verify(key.algorithm, key, result, asciiToUint8Array('foo'));
 }).then(function(result) {
     verificationResult = result;
     shouldBe("verificationResult", "true");
index 4cac349..acda47e 100644 (file)
@@ -27,13 +27,13 @@ crypto.subtle.importKey("raw", hmacKey, {name: 'hmac', hash: {name: 'sha-1'}}, e
     shouldBe("key.usages", "['sign', 'verify']");
 
     debug("Using the key to sign 'foo'...");
-    return crypto.subtle.sign(key.algorithm, key, [asciiToUint8Array('foo')]);
+    return crypto.subtle.sign(key.algorithm, key, asciiToUint8Array('foo'));
 }).then(function(result) {
     signature = result;
     shouldBe("bytesToHexString(new Uint8Array(signature))", "'a3cc770fc033e2cb419d42b64e0081a3bd3be30e'");
 
     debug("Verifying the signature...");
-    return crypto.subtle.verify(key.algorithm, key, result, [asciiToUint8Array('foo')]);
+    return crypto.subtle.verify(key.algorithm, key, result, asciiToUint8Array('foo'));
 }).then(function(result) {
     verificationResult = result;
     shouldBe("verificationResult", "true");
index 422d767..f3487a6 100644 (file)
@@ -27,13 +27,13 @@ crypto.subtle.importKey("raw", hmacKey, {name: 'hmac', hash: {name: 'sha-1'}}, e
     shouldBe("key.usages", "['sign', 'verify']");
 
     debug("Using the key to sign 'foo'...");
-    return crypto.subtle.sign(key.algorithm, key, [asciiToUint8Array('foo')]);
+    return crypto.subtle.sign(key.algorithm, key, asciiToUint8Array('foo'));
 }).then(function(result) {
     signature = result;
     shouldBe("bytesToHexString(new Uint8Array(signature))", "'bebbc02e46b0f81183f40c25dce23e5045d65519'");
 
     debug("Verifying the signature...");
-    return crypto.subtle.verify(key.algorithm, key, result, [asciiToUint8Array('foo')]);
+    return crypto.subtle.verify(key.algorithm, key, result, asciiToUint8Array('foo'));
 }).then(function(result) {
     verificationResult = result;
     shouldBe("verificationResult", "true");
index 86616ef..5a6556d 100644 (file)
@@ -45,18 +45,18 @@ crypto.subtle.importKey("jwk", asciiToUint8Array(JSON.stringify(publicKeyJSON)),
 }).then(function(result) {
     privateKey = result;
     debug("\nSigning some text...");
-    return crypto.subtle.sign({ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, privateKey, [data]);
+    return crypto.subtle.sign({ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, privateKey, data);
 }).then(function(result) {
     signature = result;
     shouldBe("bytesToHexString(new Uint8Array(signature))", "'0fd9a8aef4cc1876c0b762545336c6d1fb315ae16ae4b5e4bf34d384d8585ea7a01e76ea09ee7f7ee8d1c122e7dd15b7c94a573b2aa07203e8d13bc6fd16156cd8e5f0c15a15dccb62d152127fca09882fb53bc3e60ab586d15b95cf411e3aab4a1c231a7e91aab09ee3d4b13d11e97505ddff77683470da510ee76e8bd530c56a85f901626a5a710f716f113dfe9cf6c473ee16fa248aea3480a1033abe30f4c1243289a661e64d7818b55698280688097135968c6d4b029496d85cab2a67e4696737781f70e4392c7df71bbd6c92465947f029a1de48160aced11b5721b1cd25039fe2c16c2b38de73df3b9a83e3ea755fd0cfe51ca06b61fadf6d84677f95'");
 
     debug("\nVerifying the signature...");
-    return crypto.subtle.verify({ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, publicKey, signature, [data]);
+    return crypto.subtle.verify({ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, publicKey, signature, data);
 }).then(function(result) {
     verificationResult = result;
     shouldBe("verificationResult", "true");
     debug("\nVerifying a bad signature...");
-    return crypto.subtle.verify({ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, publicKey, new Uint8Array(256), [data]);
+    return crypto.subtle.verify({ name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, publicKey, new Uint8Array(256), data);
 }).then(function(result) {
     verificationResult = result;
     shouldBe("verificationResult", "false");
index c27dce2..6ba856e 100644 (file)
@@ -9,8 +9,6 @@ SHA1 of [0x0]
 PASS bytesToHexString(new Uint8Array(digest)) is '5ba93c9db0cff93f52b521d7420e43f6eda2784f'
 SHA1 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 PASS bytesToHexString(new Uint8Array(digest)) is '2c7e7c384f7829694282b1e3a6216def8082d055'
-SHA1 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]
-PASS bytesToHexString(new Uint8Array(digest)) is '2c7e7c384f7829694282b1e3a6216def8082d055'
 PASS crypto.subtle.generateKey('sha-1') threw exception Error: NotSupportedError: DOM Exception 9.
 PASS successfullyParsed is true
 
index 2166ce8..ed925e1 100644 (file)
@@ -15,29 +15,24 @@ jsTestIsAsync = true;
 
 Promise.fulfill(null).then(function() {
     debug("SHA1 of []");
-    return crypto.subtle.digest('sha-1', [new Uint8Array([])]);
+    return crypto.subtle.digest('sha-1', new Uint8Array([]));
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'da39a3ee5e6b4b0d3255bfef95601890afd80709'");
 
     debug("SHA1 of [0x0]")
-    return crypto.subtle.digest({name: 'sha-1'}, [new Uint8Array([0])]);
+    return crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([0]));
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'5ba93c9db0cff93f52b521d7420e43f6eda2784f'");
 
     debug("SHA1 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]");
     var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
-    return crypto.subtle.digest({name: 'sha-1'}, [data]);
+    return crypto.subtle.digest({name: 'sha-1'}, data);
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'2c7e7c384f7829694282b1e3a6216def8082d055'");
 
-    debug("SHA1 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]");
-    return crypto.subtle.digest({name: 'sha-1'}, [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array([5, 6, 7, 8, 9, 10])]);
-}).then(function(result) {
-    digest = result;
-    shouldBe("bytesToHexString(new Uint8Array(digest))", "'2c7e7c384f7829694282b1e3a6216def8082d055'");
     // All SHA-1 can do is digest.
     shouldThrow("crypto.subtle.generateKey('sha-1')");
     finishJSTest();
index c045c8f..fd50145 100644 (file)
@@ -9,8 +9,6 @@ SHA224 of [0x0]
 PASS bytesToHexString(new Uint8Array(digest)) is 'fff9292b4201617bdc4d3053fce02734166a683d7d858a7f5f59b073'
 SHA224 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 PASS bytesToHexString(new Uint8Array(digest)) is '767d0cdc11079ba8dca276df5c4b85507de67dce47eda4cd9196d312'
-SHA224 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]
-PASS bytesToHexString(new Uint8Array(digest)) is '767d0cdc11079ba8dca276df5c4b85507de67dce47eda4cd9196d312'
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 241a7f5..c0e16e8 100644 (file)
@@ -15,26 +15,20 @@ jsTestIsAsync = true;
 
 Promise.fulfill(null).then(function() {
     debug("SHA224 of []");
-    return crypto.subtle.digest('sha-224', [new Uint8Array([])]);
+    return crypto.subtle.digest('sha-224', new Uint8Array([]));
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f'");
 
     debug("SHA224 of [0x0]")
-    return crypto.subtle.digest({name: 'sha-224'}, [new Uint8Array([0])]);
+    return crypto.subtle.digest({name: 'sha-224'}, new Uint8Array([0]));
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'fff9292b4201617bdc4d3053fce02734166a683d7d858a7f5f59b073'");
 
     debug("SHA224 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]");
     var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
-    return crypto.subtle.digest({name: 'sha-224'}, [data]);
-}).then(function(result) {
-    digest = result;
-    shouldBe("bytesToHexString(new Uint8Array(digest))", "'767d0cdc11079ba8dca276df5c4b85507de67dce47eda4cd9196d312'");
-
-    debug("SHA224 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]");
-    return crypto.subtle.digest({name: 'sha-224'}, [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array([5, 6, 7, 8, 9, 10])]);
+    return crypto.subtle.digest({name: 'sha-224'}, data);
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'767d0cdc11079ba8dca276df5c4b85507de67dce47eda4cd9196d312'");
index 54ad551..e9ab27a 100644 (file)
@@ -9,8 +9,6 @@ SHA256 of [0x0]
 PASS bytesToHexString(new Uint8Array(digest)) is '6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d'
 SHA256 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 PASS bytesToHexString(new Uint8Array(digest)) is '78a6273103d17c39a0b6126e226cec70e33337f4bc6a38067401b54a33e78ead'
-SHA256 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]
-PASS bytesToHexString(new Uint8Array(digest)) is '78a6273103d17c39a0b6126e226cec70e33337f4bc6a38067401b54a33e78ead'
 PASS successfullyParsed is true
 
 TEST COMPLETE
index b13ed84..a6d80eb 100644 (file)
@@ -15,26 +15,20 @@ jsTestIsAsync = true;
 
 Promise.fulfill(null).then(function() {
     debug("SHA256 of []");
-    return crypto.subtle.digest('sha-256', [new Uint8Array([])]);
+    return crypto.subtle.digest('sha-256', new Uint8Array([]));
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'");
 
     debug("SHA256 of [0x0]")
-    return crypto.subtle.digest({name: 'sha-256'}, [new Uint8Array([0])]);
+    return crypto.subtle.digest({name: 'sha-256'}, new Uint8Array([0]));
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d'");
 
     debug("SHA256 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]");
     var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
-    return crypto.subtle.digest({name: 'sha-256'}, [data]);
-}).then(function(result) {
-    digest = result;
-    shouldBe("bytesToHexString(new Uint8Array(digest))", "'78a6273103d17c39a0b6126e226cec70e33337f4bc6a38067401b54a33e78ead'");
-
-    debug("SHA256 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]");
-    return crypto.subtle.digest({name: 'sha-256'}, [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array([5, 6, 7, 8, 9, 10])]);
+    return crypto.subtle.digest({name: 'sha-256'}, data);
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'78a6273103d17c39a0b6126e226cec70e33337f4bc6a38067401b54a33e78ead'");
index 4ea13f0..00c5ce2 100644 (file)
@@ -9,8 +9,6 @@ SHA384 of [0x0]
 PASS bytesToHexString(new Uint8Array(digest)) is 'bec021b4f368e3069134e012c2b4307083d3a9bdd206e24e5f0d86e13d6636655933ec2b413465966817a9c208a11717'
 SHA384 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 PASS bytesToHexString(new Uint8Array(digest)) is '89bfcf569ae4af718510da78c67414109f5739bb5c40d51c9c8c50e2b2cee86f2f80c8b9d68f7c01201a0714572fe602'
-SHA384 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]
-PASS bytesToHexString(new Uint8Array(digest)) is '89bfcf569ae4af718510da78c67414109f5739bb5c40d51c9c8c50e2b2cee86f2f80c8b9d68f7c01201a0714572fe602'
 PASS successfullyParsed is true
 
 TEST COMPLETE
index a33096d..3ff66cc 100644 (file)
@@ -15,26 +15,20 @@ jsTestIsAsync = true;
 
 Promise.fulfill(null).then(function() {
     debug("SHA384 of []");
-    return crypto.subtle.digest('sha-384', [new Uint8Array([])]);
+    return crypto.subtle.digest('sha-384', new Uint8Array([]));
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b'");
 
     debug("SHA384 of [0x0]")
-    return crypto.subtle.digest({name: 'sha-384'}, [new Uint8Array([0])]);
+    return crypto.subtle.digest({name: 'sha-384'}, new Uint8Array([0]));
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'bec021b4f368e3069134e012c2b4307083d3a9bdd206e24e5f0d86e13d6636655933ec2b413465966817a9c208a11717'");
 
     debug("SHA384 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]");
     var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
-    return crypto.subtle.digest({name: 'sha-384'}, [data]);
-}).then(function(result) {
-    digest = result;
-    shouldBe("bytesToHexString(new Uint8Array(digest))", "'89bfcf569ae4af718510da78c67414109f5739bb5c40d51c9c8c50e2b2cee86f2f80c8b9d68f7c01201a0714572fe602'");
-
-    debug("SHA384 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]");
-    return crypto.subtle.digest({name: 'sha-384'}, [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array([5, 6, 7, 8, 9, 10])]);
+    return crypto.subtle.digest({name: 'sha-384'}, data);
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'89bfcf569ae4af718510da78c67414109f5739bb5c40d51c9c8c50e2b2cee86f2f80c8b9d68f7c01201a0714572fe602'");
index df15ad1..e147fd9 100644 (file)
@@ -9,8 +9,6 @@ SHA512 of [0x0]
 PASS bytesToHexString(new Uint8Array(digest)) is 'b8244d028981d693af7b456af8efa4cad63d282e19ff14942c246e50d9351d22704a802a71c3580b6370de4ceb293c324a8423342557d4e5c38438f0e36910ee'
 SHA512 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 PASS bytesToHexString(new Uint8Array(digest)) is '8ffaee0cccc162851faf051ae38667eefd423c0164c50055f8ade00afc3705e3cdeb9900004b0e426ca66ab63aa3b99b075273f44fd37c22a3555c6fd1f37ccb'
-SHA512 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]
-PASS bytesToHexString(new Uint8Array(digest)) is '8ffaee0cccc162851faf051ae38667eefd423c0164c50055f8ade00afc3705e3cdeb9900004b0e426ca66ab63aa3b99b075273f44fd37c22a3555c6fd1f37ccb'
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 30a7b4c..71e5240 100644 (file)
@@ -15,26 +15,20 @@ jsTestIsAsync = true;
 
 Promise.fulfill(null).then(function() {
     debug("SHA512 of []");
-    return crypto.subtle.digest('sha-512', [new Uint8Array([])]);
+    return crypto.subtle.digest('sha-512', new Uint8Array([]));
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e'");
 
     debug("SHA512 of [0x0]")
-    return crypto.subtle.digest({name: 'sha-512'}, [new Uint8Array([0])]);
+    return crypto.subtle.digest({name: 'sha-512'}, new Uint8Array([0]));
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'b8244d028981d693af7b456af8efa4cad63d282e19ff14942c246e50d9351d22704a802a71c3580b6370de4ceb293c324a8423342557d4e5c38438f0e36910ee'");
 
     debug("SHA512 of [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]");
     var data = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
-    return crypto.subtle.digest({name: 'sha-512'}, [data]);
-}).then(function(result) {
-    digest = result;
-    shouldBe("bytesToHexString(new Uint8Array(digest))", "'8ffaee0cccc162851faf051ae38667eefd423c0164c50055f8ade00afc3705e3cdeb9900004b0e426ca66ab63aa3b99b075273f44fd37c22a3555c6fd1f37ccb'");
-
-    debug("SHA512 of [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array(5, 6, 7, 8, 9, 10])]");
-    return crypto.subtle.digest({name: 'sha-512'}, [new Uint8Array([0, 1, 2, 3, 4]), new Uint8Array([5, 6, 7, 8, 9, 10])]);
+    return crypto.subtle.digest({name: 'sha-512'}, data);
 }).then(function(result) {
     digest = result;
     shouldBe("bytesToHexString(new Uint8Array(digest))", "'8ffaee0cccc162851faf051ae38667eefd423c0164c50055f8ade00afc3705e3cdeb9900004b0e426ca66ab63aa3b99b075273f44fd37c22a3555c6fd1f37ccb'");
index a129660..5d244f7 100644 (file)
@@ -1,3 +1,60 @@
+2013-11-16  Alexey Proskuryakov  <ap@apple.com>
+
+        WebCrypto no longer uses sequences of ArrayBuffers
+        https://bugs.webkit.org/show_bug.cgi?id=124451
+
+        Reviewed by Sam Weinig.
+
+        Covered by existing tests.
+
+        Changed all operations to take single CryptoOperationData objects.
+
+        * bindings/js/JSCryptoOperationData.cpp:
+        * bindings/js/JSCryptoOperationData.h:
+        * bindings/js/JSSubtleCryptoCustom.cpp:
+        (WebCore::JSSubtleCrypto::encrypt):
+        (WebCore::JSSubtleCrypto::decrypt):
+        (WebCore::JSSubtleCrypto::sign):
+        (WebCore::JSSubtleCrypto::verify):
+        (WebCore::JSSubtleCrypto::digest):
+        * crypto/CryptoAlgorithm.cpp:
+        (WebCore::CryptoAlgorithm::encrypt):
+        (WebCore::CryptoAlgorithm::decrypt):
+        (WebCore::CryptoAlgorithm::sign):
+        (WebCore::CryptoAlgorithm::verify):
+        (WebCore::CryptoAlgorithm::digest):
+        * crypto/CryptoAlgorithm.h:
+        * crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify):
+        * crypto/algorithms/CryptoAlgorithmAES_CBC.h:
+        * crypto/algorithms/CryptoAlgorithmHMAC.h:
+        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
+        * 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:
+        * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
+        (WebCore::transformAES_CBC):
+        (WebCore::CryptoAlgorithmAES_CBC::encrypt):
+        (WebCore::CryptoAlgorithmAES_CBC::decrypt):
+        * crypto/mac/CryptoAlgorithmHMACMac.cpp:
+        (WebCore::calculateSignature):
+        (WebCore::CryptoAlgorithmHMAC::sign):
+        (WebCore::CryptoAlgorithmHMAC::verify):
+        * crypto/parameters/CryptoAlgorithmRsaKeyGenParams.h:
+
 2013-11-16  Zoltan Horvath  <zoltan@webkit.org>
 
         Remove the include of LineWidth.h from SimpleLineLayoutFunctions.cpp
index 59bff01..0077208 100644 (file)
@@ -34,29 +34,6 @@ using namespace JSC;
 
 namespace WebCore {
 
-bool sequenceOfCryptoOperationDataFromJSValue(ExecState* exec, JSValue value, Vector<CryptoOperationData>& result)
-{
-    unsigned sequenceLength;
-    JSObject* sequence = toJSSequence(exec, value, sequenceLength);
-    if (!sequence) {
-        ASSERT(exec->hadException());
-        return false;
-    }
-
-    for (unsigned i = 0; i < sequenceLength; ++i) {
-        JSValue item = sequence->get(exec, i);
-        if (ArrayBuffer* buffer = toArrayBuffer(item))
-            result.append(std::make_pair(static_cast<char*>(buffer->data()), buffer->byteLength()));
-        else if (RefPtr<ArrayBufferView> bufferView = toArrayBufferView(item))
-            result.append(std::make_pair(static_cast<char*>(bufferView->baseAddress()), bufferView->byteLength()));
-        else {
-            throwTypeError(exec, "Only ArrayBuffer and ArrayBufferView objects can be part of CryptoOperationData sequence");
-            return false;
-        }
-    }
-    return true;
-}
-
 bool cryptoOperationDataFromJSValue(ExecState* exec, JSValue value, CryptoOperationData& result)
 {
     if (ArrayBuffer* buffer = toArrayBuffer(value))
index a9e2333..aa45844 100644 (file)
@@ -26,8 +26,6 @@
 #ifndef JSCryptoOperationData_h
 #define JSCryptoOperationData_h
 
-#include <wtf/Vector.h>
-
 #if ENABLE(SUBTLE_CRYPTO)
 
 namespace JSC {
@@ -39,7 +37,6 @@ namespace WebCore {
 
 typedef std::pair<const char*, size_t> CryptoOperationData;
 
-bool sequenceOfCryptoOperationDataFromJSValue(JSC::ExecState*, JSC::JSValue, Vector<CryptoOperationData>&);
 bool cryptoOperationDataFromJSValue(JSC::ExecState*, JSC::JSValue, CryptoOperationData&);
 
 } // namespace WebCore
index 1c1d8e4..3ce24ed 100644 (file)
@@ -155,8 +155,8 @@ JSValue JSSubtleCrypto::encrypt(ExecState* exec)
         return jsUndefined();
     }
 
-    Vector<CryptoOperationData> data;
-    if (!sequenceOfCryptoOperationDataFromJSValue(exec, exec->uncheckedArgument(2), data)) {
+    CryptoOperationData data;
+    if (!cryptoOperationDataFromJSValue(exec, exec->uncheckedArgument(2), data)) {
         ASSERT(exec->hadException());
         return jsUndefined();
     }
@@ -201,8 +201,8 @@ JSValue JSSubtleCrypto::decrypt(ExecState* exec)
         return jsUndefined();
     }
 
-    Vector<CryptoOperationData> data;
-    if (!sequenceOfCryptoOperationDataFromJSValue(exec, exec->uncheckedArgument(2), data)) {
+    CryptoOperationData data;
+    if (!cryptoOperationDataFromJSValue(exec, exec->uncheckedArgument(2), data)) {
         ASSERT(exec->hadException());
         return jsUndefined();
     }
@@ -247,8 +247,8 @@ JSValue JSSubtleCrypto::sign(ExecState* exec)
         return jsUndefined();
     }
 
-    Vector<CryptoOperationData> data;
-    if (!sequenceOfCryptoOperationDataFromJSValue(exec, exec->uncheckedArgument(2), data)) {
+    CryptoOperationData data;
+    if (!cryptoOperationDataFromJSValue(exec, exec->uncheckedArgument(2), data)) {
         ASSERT(exec->hadException());
         return jsUndefined();
     }
@@ -299,8 +299,8 @@ JSValue JSSubtleCrypto::verify(ExecState* exec)
         return jsUndefined();
     }
 
-    Vector<CryptoOperationData> data;
-    if (!sequenceOfCryptoOperationDataFromJSValue(exec, exec->uncheckedArgument(3), data)) {
+    CryptoOperationData data;
+    if (!cryptoOperationDataFromJSValue(exec, exec->uncheckedArgument(3), data)) {
         ASSERT(exec->hadException());
         return jsUndefined();
     }
@@ -335,8 +335,8 @@ JSValue JSSubtleCrypto::digest(ExecState* exec)
         return jsUndefined();
     }
 
-    Vector<CryptoOperationData> data;
-    if (!sequenceOfCryptoOperationDataFromJSValue(exec, exec->uncheckedArgument(1), data)) {
+    CryptoOperationData data;
+    if (!cryptoOperationDataFromJSValue(exec, exec->uncheckedArgument(1), data)) {
         ASSERT(exec->hadException());
         return jsUndefined();
     }
index 10c3546..0895570 100644 (file)
@@ -40,27 +40,27 @@ CryptoAlgorithm::~CryptoAlgorithm()
 {
 }
 
-void CryptoAlgorithm::encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+void CryptoAlgorithm::encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
 {
     ec = NOT_SUPPORTED_ERR;
 }
 
-void CryptoAlgorithm::decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+void CryptoAlgorithm::decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
 {
     ec = NOT_SUPPORTED_ERR;
 }
 
-void CryptoAlgorithm::sign(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+void CryptoAlgorithm::sign(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
 {
     ec = NOT_SUPPORTED_ERR;
 }
 
-void CryptoAlgorithm::verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+void CryptoAlgorithm::verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
 {
     ec = NOT_SUPPORTED_ERR;
 }
 
-void CryptoAlgorithm::digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
+void CryptoAlgorithm::digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)
 {
     ec = NOT_SUPPORTED_ERR;
 }
index 7bd8df8..bc8f08a 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "CryptoAlgorithmIdentifier.h"
 #include "CryptoKeyUsage.h"
-#include <wtf/Vector.h>
+#include <wtf/Noncopyable.h>
 
 #if ENABLE(SUBTLE_CRYPTO)
 
@@ -51,11 +51,11 @@ public:
 
     virtual CryptoAlgorithmIdentifier identifier() const = 0;
 
-    virtual void encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
-    virtual void decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
-    virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
-    virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
-    virtual void digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
+    virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
     virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
     virtual void deriveKey(const CryptoAlgorithmParameters&, const CryptoKey& baseKey, CryptoAlgorithm* derivedKeyType, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
     virtual void deriveBits(const CryptoAlgorithmParameters&, const CryptoKey& baseKey, unsigned long length, std::unique_ptr<PromiseWrapper>, ExceptionCode&);
index 4d83180..6e3413a 100644 (file)
@@ -89,7 +89,7 @@ static bool getCommonCryptoDigestAlgorithm(CryptoAlgorithmIdentifier hashFunctio
     }
 }
 
-void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
+void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
 {
     const CryptoAlgorithmRsaSsaParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaParams(parameters);
 
@@ -111,8 +111,7 @@ void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(const CryptoAlgorithmParameters& par
         return;
     }
 
-    for (size_t i = 0; i != data.size(); ++i)
-        digest->addBytes(data[i].first, data[i].second);
+    digest->addBytes(data.first, data.second);
 
     Vector<unsigned char> digestData = digest->computeHash();
 
@@ -129,7 +128,7 @@ void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(const CryptoAlgorithmParameters& par
     promise->fulfill(signature);
 }
 
-void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& signature, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
+void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& signature, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
 {
     const CryptoAlgorithmRsaSsaParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaParams(parameters);
 
@@ -151,8 +150,7 @@ void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(const CryptoAlgorithmParameters& p
         return;
     }
 
-    for (size_t i = 0; i != data.size(); ++i)
-        digest->addBytes(data[i].first, data[i].second);
+    digest->addBytes(data.first, data.second);
 
     Vector<unsigned char> digestData = digest->computeHash();
 
index 69b14ca..c2f0e1f 100644 (file)
@@ -41,8 +41,8 @@ public:
 
     virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE;
 
-    virtual void encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
-    virtual void decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
+    virtual void encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
+    virtual void decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
     virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
     virtual void importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
 
index 74eb8b0..e905ba3 100644 (file)
@@ -41,8 +41,8 @@ public:
 
     virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE;
 
-    virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
-    virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
+    virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
+    virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
     virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
     virtual void importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
 
index 2c5da8e..17548dc 100644 (file)
@@ -41,8 +41,8 @@ public:
 
     virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE;
 
-    virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
-    virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
+    virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
+    virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
     virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
     virtual void importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
 
index fa7fb63..6f41187 100644 (file)
@@ -53,7 +53,7 @@ CryptoAlgorithmIdentifier CryptoAlgorithmSHA1::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmSHA1::digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
+void CryptoAlgorithmSHA1::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
 {
     std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_1);
     if (!digest) {
@@ -61,8 +61,7 @@ void CryptoAlgorithmSHA1::digest(const CryptoAlgorithmParameters&, const Vector<
         return;
     }
 
-    for (size_t i = 0, size = data.size(); i < size; ++i)
-        digest->addBytes(data[i].first, data[i].second);
+    digest->addBytes(data.first, data.second);
 
     promise->fulfill(digest->computeHash());
 }
index 545547a..18b39b8 100644 (file)
@@ -41,7 +41,7 @@ public:
 
     virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE;
 
-    virtual void digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
+    virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
 
 private:
     CryptoAlgorithmSHA1();
index a6b74a3..d634fb3 100644 (file)
@@ -53,7 +53,7 @@ CryptoAlgorithmIdentifier CryptoAlgorithmSHA224::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmSHA224::digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
+void CryptoAlgorithmSHA224::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
 {
     std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_224);
     if (!digest) {
@@ -61,8 +61,7 @@ void CryptoAlgorithmSHA224::digest(const CryptoAlgorithmParameters&, const Vecto
         return;
     }
 
-    for (size_t i = 0, size = data.size(); i < size; ++i)
-        digest->addBytes(data[i].first, data[i].second);
+    digest->addBytes(data.first, data.second);
 
     promise->fulfill(digest->computeHash());
 }
index 7548aa7..f22b875 100644 (file)
@@ -41,7 +41,7 @@ public:
 
     virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE;
 
-    virtual void digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
+    virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
 
 private:
     CryptoAlgorithmSHA224();
index e6cc12f..0f8ef3e 100644 (file)
@@ -53,7 +53,7 @@ CryptoAlgorithmIdentifier CryptoAlgorithmSHA256::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmSHA256::digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
+void CryptoAlgorithmSHA256::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
 {
     std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_256);
     if (!digest) {
@@ -61,8 +61,7 @@ void CryptoAlgorithmSHA256::digest(const CryptoAlgorithmParameters&, const Vecto
         return;
     }
 
-    for (size_t i = 0, size = data.size(); i < size; ++i)
-        digest->addBytes(data[i].first, data[i].second);
+    digest->addBytes(data.first, data.second);
 
     promise->fulfill(digest->computeHash());
 }
index bc35125..b1c3992 100644 (file)
@@ -41,7 +41,7 @@ public:
 
     virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE;
 
-    virtual void digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
+    virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
 
 private:
     CryptoAlgorithmSHA256();
index e5ebcb2..9a074d9 100644 (file)
@@ -53,7 +53,7 @@ CryptoAlgorithmIdentifier CryptoAlgorithmSHA384::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmSHA384::digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
+void CryptoAlgorithmSHA384::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
 {
     std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_384);
     if (!digest) {
@@ -61,8 +61,7 @@ void CryptoAlgorithmSHA384::digest(const CryptoAlgorithmParameters&, const Vecto
         return;
     }
 
-    for (size_t i = 0, size = data.size(); i < size; ++i)
-        digest->addBytes(data[i].first, data[i].second);
+    digest->addBytes(data.first, data.second);
 
     promise->fulfill(digest->computeHash());
 }
index 85e0856..89c9c56 100644 (file)
@@ -41,7 +41,7 @@ public:
 
     virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE;
 
-    virtual void digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
+    virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
 
 private:
     CryptoAlgorithmSHA384();
index 6bdbadc..8dc51b1 100644 (file)
@@ -53,7 +53,7 @@ CryptoAlgorithmIdentifier CryptoAlgorithmSHA512::identifier() const
     return s_identifier;
 }
 
-void CryptoAlgorithmSHA512::digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
+void CryptoAlgorithmSHA512::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)
 {
     std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_512);
     if (!digest) {
@@ -61,8 +61,7 @@ void CryptoAlgorithmSHA512::digest(const CryptoAlgorithmParameters&, const Vecto
         return;
     }
 
-    for (size_t i = 0, size = data.size(); i < size; ++i)
-        digest->addBytes(data[i].first, data[i].second);
+    digest->addBytes(data.first, data.second);
 
     promise->fulfill(digest->computeHash());
 }
index 5272a7b..66c4f01 100644 (file)
@@ -41,7 +41,7 @@ public:
 
     virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE;
 
-    virtual void digest(const CryptoAlgorithmParameters&, const Vector<CryptoOperationData>&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
+    virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;
 
 private:
     CryptoAlgorithmSHA512();
index 81e76c3..df2c131 100644 (file)
@@ -36,7 +36,7 @@
 
 namespace WebCore {
 
-static void transformAES_CBC(CCOperation operation, const CryptoAlgorithmAesCbcParams& parameters, const CryptoKeyAES& key, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise)
+static void transformAES_CBC(CCOperation operation, const CryptoAlgorithmAesCbcParams& parameters, const CryptoKeyAES& key, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise)
 {
     static_assert(sizeof(parameters.iv) == kCCBlockSizeAES128, "Initialization vector size must be the same as algorithm block size");
 
@@ -58,24 +58,18 @@ static void transformAES_CBC(CCOperation operation, const CryptoAlgorithmAesCbcP
         return;
     }
 
-    size_t inputSize = 0;
-    for (size_t i = 0, size = data.size(); i < size; ++i)
-        inputSize += data[i].second;
-
-    Vector<unsigned char> result(CCCryptorGetOutputLength(cryptor, inputSize, true));
-
-    unsigned char* p = result.data();
-    size_t resultChunkSize;
-    for (size_t i = 0, size = data.size(); i < size; ++i) {
-        status = CCCryptorUpdate(cryptor, data[i].first, data[i].second, p, result.end() - p, &resultChunkSize);
-        if (status) {
-            promise->reject(nullptr);
-            return;
-        }
-        p += resultChunkSize;
+    Vector<unsigned char> result(CCCryptorGetOutputLength(cryptor, data.second, true));
+
+    size_t bytesWritten;
+    status = CCCryptorUpdate(cryptor, data.first, data.second, result.data(), result.size(), &bytesWritten);
+    if (status) {
+        promise->reject(nullptr);
+        return;
     }
-    status = CCCryptorFinal(cryptor, p, result.end() - p, &resultChunkSize);
-    p += resultChunkSize;
+
+    unsigned char* p = result.data() + bytesWritten;
+    status = CCCryptorFinal(cryptor, p, result.end() - p, &bytesWritten);
+    p += bytesWritten;
     if (status) {
         promise->reject(nullptr);
         return;
@@ -89,7 +83,7 @@ static void transformAES_CBC(CCOperation operation, const CryptoAlgorithmAesCbcP
     promise->fulfill(result);
 }
 
-void CryptoAlgorithmAES_CBC::encrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
+void CryptoAlgorithmAES_CBC::encrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
 {
     const CryptoAlgorithmAesCbcParams& aesCBCParameters = toCryptoAlgorithmAesCbcParams(parameters);
 
@@ -102,7 +96,7 @@ void CryptoAlgorithmAES_CBC::encrypt(const CryptoAlgorithmParameters& parameters
     transformAES_CBC(kCCEncrypt, aesCBCParameters, aesKey, data, std::move(promise));
 }
 
-void CryptoAlgorithmAES_CBC::decrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
+void CryptoAlgorithmAES_CBC::decrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
 {
     const CryptoAlgorithmAesCbcParams& aesCBCParameters = toCryptoAlgorithmAesCbcParams(parameters);
 
index 5f3bc0e..9ba3cbd 100644 (file)
@@ -59,7 +59,7 @@ static bool getCommonCryptoAlgorithm(CryptoAlgorithmIdentifier hashFunction, CCH
     }
 }
 
-static Vector<unsigned char> calculateSignature(CCHmacAlgorithm algorithm, const Vector<char>& key, const Vector<CryptoOperationData>& data)
+static Vector<unsigned char> calculateSignature(CCHmacAlgorithm algorithm, const Vector<char>& key, const CryptoOperationData& data)
 {
     size_t digestLength;
     switch (algorithm) {
@@ -82,18 +82,13 @@ static Vector<unsigned char> calculateSignature(CCHmacAlgorithm algorithm, const
         ASSERT_NOT_REACHED();
     }
 
-    CCHmacContext context;
-    const char* keyData = key.data() ? key.data() : ""; // <rdar://problem/15467425> HMAC crashes when key pointer is null.
-    CCHmacInit(&context, algorithm, keyData, key.size());
-    for (size_t i = 0, size = data.size(); i < size; ++i)
-        CCHmacUpdate(&context, data[i].first, data[i].second);
-
     Vector<unsigned char> result(digestLength);
-    CCHmacFinal(&context, result.data());
+    const char* keyData = key.data() ? key.data() : ""; // <rdar://problem/15467425> HMAC crashes when key pointer is null.
+    CCHmac(algorithm, keyData, key.size(), data.first, data.second, result.data());
     return result;
 }
 
-void CryptoAlgorithmHMAC::sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
+void CryptoAlgorithmHMAC::sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
 {
     const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters);
 
@@ -114,7 +109,7 @@ void CryptoAlgorithmHMAC::sign(const CryptoAlgorithmParameters& parameters, cons
     promise->fulfill(signature);
 }
 
-void CryptoAlgorithmHMAC::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& expectedSignature, const Vector<CryptoOperationData>& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
+void CryptoAlgorithmHMAC::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& expectedSignature, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)
 {
     const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters);
 
index 2fd7ac0..6739a6f 100644 (file)
@@ -27,6 +27,7 @@
 #define CryptoAlgorithmRsaKeyGenParams_h
 
 #include "CryptoAlgorithmParameters.h"
+#include <wtf/Vector.h>
 
 #if ENABLE(SUBTLE_CRYPTO)