Update SubtleCrypto::encrypt to match the latest spec
https://bugs.webkit.org/show_bug.cgi?id=164738
<rdar://problem/29257812>

Reviewed by Brent Fulgham.

LayoutTests/imported/w3c:

* WebCryptoAPI/encrypt_decrypt/test_aes_cbc-expected.txt:
* WebCryptoAPI/encrypt_decrypt/test_aes_ctr-expected.txt:
* WebCryptoAPI/encrypt_decrypt/test_aes_gcm-expected.txt:
* WebCryptoAPI/encrypt_decrypt/test_rsa_oaep-expected.txt:
* WebCryptoAPI/idlharness-expected.txt:

Source/WebCore:

This patch does following few things:
1. It updates the SubtleCrypto::encrypt method to match the latest spec:
   https://www.w3.org/TR/WebCryptoAPI/#SubtleCrypto-method-encrypt.
   It also refers to the latest Editor's Draft to a certain degree:
   https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-encrypt.
2. It implements encrypt operations of the following algorithms: AES-CBC,
   RSAES-PKCS1-V1_5, and RSA-OAEP.
3. It addes ASSERT(parameters) for every method that accepts a
   std::unique_ptr<CryptoAlgorithmParameters>&& type parameter.
4. It changes RefPtr<CryptoKey>&& to Ref<CryptoKey>&& for every method that
   accepts a CryptoKey.

Tests: crypto/subtle/aes-cbc-encrypt-malformed-parameters.html
       crypto/subtle/aes-cbc-import-key-encrypt.html
       crypto/subtle/encrypt-malformed-parameters.html
       crypto/subtle/rsa-oaep-encrypt-malformed-parameters.html
       crypto/subtle/rsa-oaep-import-key-encrypt-label.html
       crypto/subtle/rsa-oaep-import-key-encrypt.html
       crypto/subtle/rsaes-pkcs1-v1_5-import-key-encrypt.html
       crypto/workers/subtle/aes-cbc-import-key-encrypt.html
       crypto/workers/subtle/rsa-oaep-import-key-encrypt.html
       crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-encrypt.html

* CMakeLists.txt:
* DerivedSources.make:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/BufferSource.h:
(WebCore::BufferSource::BufferSource):
Add a default constructor for initializing an empty BufferSource object.
* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::normalizeCryptoAlgorithmParameters):
(WebCore::jsSubtleCryptoFunctionEncryptPromise):
(WebCore::JSSubtleCrypto::encrypt):
* crypto/CryptoAlgorithm.cpp:
(WebCore::CryptoAlgorithm::encrypt):
(WebCore::CryptoAlgorithm::exportKey):
* crypto/CryptoAlgorithm.h:
* crypto/CryptoAlgorithmParameters.h:
* crypto/CryptoKey.h:
* crypto/SubtleCrypto.cpp:
(WebCore::SubtleCrypto::SubtleCrypto):
* crypto/SubtleCrypto.h:
(WebCore::SubtleCrypto::workQueue):
* crypto/SubtleCrypto.idl:
* crypto/gnutls/CryptoAlgorithmAES_CBCGnuTLS.cpp:
(WebCore::CryptoAlgorithmAES_CBC::platformEncrypt):
* crypto/gnutls/CryptoAlgorithmRSAES_PKCS1_v1_5GnuTLS.cpp:
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt):
* crypto/gnutls/CryptoAlgorithmRSA_OAEPGnuTLS.cpp:
(WebCore::CryptoAlgorithmRSA_OAEP::platformEncrypt):
* crypto/gnutls/CryptoKeyRSAGnuTLS.cpp:
(WebCore::CryptoKeyRSA::generatePair):
* crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
(WebCore::CryptoAlgorithmAES_CBC::encrypt):
(WebCore::CryptoAlgorithmAES_CBC::generateKey):
(WebCore::CryptoAlgorithmAES_CBC::importKey):
(WebCore::CryptoAlgorithmAES_CBC::exportKey):
* crypto/algorithms/CryptoAlgorithmAES_CBC.h:
* crypto/algorithms/CryptoAlgorithmAES_KW.cpp:
(WebCore::CryptoAlgorithmAES_KW::generateKey):
(WebCore::CryptoAlgorithmAES_KW::importKey):
(WebCore::CryptoAlgorithmAES_KW::exportKey):
* crypto/algorithms/CryptoAlgorithmAES_KW.h:
* crypto/algorithms/CryptoAlgorithmHMAC.cpp:
(WebCore::CryptoAlgorithmHMAC::generateKey):
(WebCore::CryptoAlgorithmHMAC::importKey):
(WebCore::CryptoAlgorithmHMAC::exportKey):
* crypto/algorithms/CryptoAlgorithmHMAC.h:
* crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::encrypt):
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::generateKey):
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::importKey):
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::exportKey):
* crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.h:
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey):
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey):
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::exportKey):
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:
* crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
(WebCore::CryptoAlgorithmRSA_OAEP::encrypt):
(WebCore::CryptoAlgorithmRSA_OAEP::generateKey):
(WebCore::CryptoAlgorithmRSA_OAEP::importKey):
(WebCore::CryptoAlgorithmRSA_OAEP::exportKey):
* crypto/algorithms/CryptoAlgorithmRSA_OAEP.h:
* crypto/keys/CryptoKeyRSA.h:
* crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:
(WebCore::transformAES_CBC):
(WebCore::CryptoAlgorithmAES_CBC::platformEncrypt):
(WebCore::CryptoAlgorithmAES_CBC::platformDecrypt):
* crypto/mac/CryptoAlgorithmRSAES_PKCS1_v1_5Mac.cpp:
(WebCore::encryptRSAES_PKCS1_v1_5):
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::platformEncrypt):
* crypto/mac/CryptoAlgorithmRSA_OAEPMac.cpp:
(WebCore::encryptRSA_OAEP):
(WebCore::CryptoAlgorithmRSA_OAEP::platformEncrypt):
* crypto/mac/CryptoKeyRSAMac.cpp:
(WebCore::CryptoKeyRSA::generatePair):
* crypto/parameters/AesCbcParams.idl: Added.
* crypto/parameters/CryptoAlgorithmAesCbcParams.h: Added.
* crypto/parameters/CryptoAlgorithmAesCbcParamsDeprecated.h:
* crypto/parameters/CryptoAlgorithmRsaOaepParams.h: Added.
* crypto/parameters/RsaOaepParams.idl: Added.

LayoutTests:

* TestExpectations:
* crypto/subtle/aes-cbc-encrypt-malformed-parameters-expected.txt: Added.
* crypto/subtle/aes-cbc-encrypt-malformed-parameters.html: Added.
* crypto/subtle/aes-cbc-import-key-encrypt-expected.txt: Added.
* crypto/subtle/aes-cbc-import-key-encrypt.html: Added.
* crypto/subtle/encrypt-malformed-parameters-expected.txt: Added.
* crypto/subtle/encrypt-malformed-parameters.html: Added.
* crypto/subtle/rsa-oaep-encrypt-malformed-parameters-expected.txt: Added.
* crypto/subtle/rsa-oaep-encrypt-malformed-parameters.html: Added.
* crypto/subtle/rsa-oaep-import-key-encrypt-expected.txt: Added.
* crypto/subtle/rsa-oaep-import-key-encrypt-label-expected.txt: Added.
* crypto/subtle/rsa-oaep-import-key-encrypt-label.html: Added.
* crypto/subtle/rsa-oaep-import-key-encrypt.html: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-import-key-encrypt-expected.txt: Added.
* crypto/subtle/rsaes-pkcs1-v1_5-import-key-encrypt.html: Added.
* crypto/workers/subtle/aes-cbc-import-key-encrypt-expected.txt: Added.
* crypto/workers/subtle/aes-cbc-import-key-encrypt.html: Added.
* crypto/workers/subtle/resources/aes-cbc-import-key-encrypt.js: Added.
* crypto/workers/subtle/resources/rsa-oaep-import-key-encrypt.js: Added.
* crypto/workers/subtle/resources/rsaes-pkcs1-v1_5-import-key-encrypt.js: Added.
* crypto/workers/subtle/rsa-oaep-import-key-encrypt-expected.txt: Added.
* crypto/workers/subtle/rsa-oaep-import-key-encrypt.html: Added.
* crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-encrypt-expected.txt: Added.
* crypto/workers/subtle/rsaes-pkcs1-v1_5-import-key-encrypt.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@208891 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/crypto/subtle/rsa-oaep-encrypt-malformed-parameters-expected.txt b/LayoutTests/crypto/subtle/rsa-oaep-encrypt-malformed-parameters-expected.txt
new file mode 100644
index 0000000..ef3531b
--- /dev/null
+++ b/LayoutTests/crypto/subtle/rsa-oaep-encrypt-malformed-parameters-expected.txt
@@ -0,0 +1,15 @@
+Test encrypting using RSA-OAEP with malformed parameters
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS crypto.subtle.encrypt({name: "RSA-OAEP", label: true}, key, plainText) rejected promise  with TypeError: Type error.
+PASS crypto.subtle.encrypt({name: "RSA-OAEP", label: 1}, key, plainText) rejected promise  with TypeError: Type error.
+PASS crypto.subtle.encrypt({name: "RSA-OAEP", label: null}, key, plainText) rejected promise  with TypeError: Type error.
+PASS crypto.subtle.encrypt({name: "RSA-OAEP", label: Symbol()}, key, plainText) rejected promise  with TypeError: Type error.
+PASS crypto.subtle.encrypt({name: "RSA-OAEP", label: { }}, key, plainText) rejected promise  with TypeError: Type error.
+PASS crypto.subtle.encrypt({name: "RSA-OAEP", label: "foo"}, key, plainText) rejected promise  with TypeError: Type error.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+