WebCrypto algorithms should be exposed via KeyAlgorithm dictionary
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Sep 2016 00:19:12 +0000 (00:19 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Sep 2016 00:19:12 +0000 (00:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=128748
<rdar://problem/27359438>

Reviewed by Brent Fulgham and Chris Dumez.

Source/WebCore:

Replace custom CryptoAlgorithmBuilder/buildAlgorithmDescription with KeyAlgorithm dictionary which is
defined by the spec: https://www.w3.org/TR/WebCryptoAPI/#key-algorithm-dictionary. Moreover, mark
CryptoKey.usages as CachedAttribute.

Tests: crypto/subtle/crypto-key-algorithm-gc.html
       crypto/subtle/crypto-key-usages-gc.html

* PlatformEfl.cmake:
* PlatformGTK.cmake:
* PlatformMac.cmake:
Remove CryptoAlgorithmDescriptionBuilder.cpp.
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSCryptoAlgorithmBuilder.cpp:
(WebCore::JSCryptoAlgorithmBuilder::add):
(WebCore::JSCryptoAlgorithmBuilder::createEmptyClone): Deleted.
* bindings/js/JSCryptoAlgorithmBuilder.h:
* bindings/js/JSCryptoKeyCustom.cpp:
(WebCore::JSCryptoKey::algorithm):
Get rid of dependency on CryptoAlgorithmDescriptionBuilder.
* crypto/CryptoAlgorithmDescriptionBuilder.cpp: Removed.
* crypto/CryptoAlgorithmDescriptionBuilder.h: Removed.
Replace it with KeyAlgorithm.
* crypto/CryptoKey.cpp:
(WebCore::CryptoKey::CryptoKey):
(WebCore::CryptoKey::buildAlgorithmDescription): Deleted.
* crypto/CryptoKey.h:
(WebCore::KeyAlgorithm::KeyAlgorithm):
(WebCore::KeyAlgorithm::~KeyAlgorithm):
(WebCore::CryptoKey::algorithmIdentifier):
* crypto/CryptoKey.idl:
Add KeyAlgorithm dictionary which is returned via CryptoKey.buildAlgorithm() method,
and rename m_algorithm to m_algorithmIdentifier to distingush it with newly
added KeyAlgorithm dictionary.
* crypto/gnutls/CryptoKeyRSAGnuTLS.cpp:
(WebCore::buildAlgorithm):
(WebCore::CryptoKeyRSA::buildAlgorithmDescription): Deleted.
* crypto/keys/CryptoKeyAES.cpp:
(WebCore::CryptoKeyAES::buildAlgorithm):
(WebCore::CryptoKeyAES::buildAlgorithmDescription): Deleted.
* crypto/keys/CryptoKeyAES.h:
(WebCore::AesKeyAlgorithm::AesKeyAlgorithm):
(WebCore::AesKeyAlgorithm::~AesKeyAlgorithm):
* crypto/keys/CryptoKeyHMAC.cpp:
(WebCore::CryptoKeyHMAC::buildAlgorithm):
(WebCore::CryptoKeyHMAC::buildAlgorithmDescription): Deleted.
* crypto/keys/CryptoKeyHMAC.h:
(WebCore::HmacKeyAlgorithm::HmacKeyAlgorithm):
(WebCore::HmacKeyAlgorithm::~HmacKeyAlgorithm):
* crypto/keys/CryptoKeyRSA.h:
(WebCore::RsaKeyAlgorithm::RsaKeyAlgorithm):
(WebCore::RsaKeyAlgorithm::~RsaKeyAlgorithm):
(WebCore::RsaHashedKeyAlgorithm::RsaHashedKeyAlgorithm):
(WebCore::RsaHashedKeyAlgorithm::~RsaHashedKeyAlgorithm):
* crypto/mac/CryptoKeyRSAMac.cpp:
(WebCore::CryptoKeyRSA::buildAlgorithm):
(WebCore::CryptoKeyRSA::buildAlgorithmDescription): Deleted.

LayoutTests:

* crypto/subtle/crypto-key-algorithm-gc-expected.txt: Added.
* crypto/subtle/crypto-key-algorithm-gc.html: Added.
* crypto/subtle/crypto-key-usages-gc-expected.txt: Added.
* crypto/subtle/crypto-key-usages-gc.html: Added.
* crypto/subtle/hmac-generate-key-expected.txt:
* crypto/subtle/hmac-generate-key.html:

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

27 files changed:
LayoutTests/ChangeLog
LayoutTests/crypto/subtle/crypto-key-algorithm-gc-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/crypto-key-algorithm-gc.html [new file with mode: 0644]
LayoutTests/crypto/subtle/crypto-key-usages-gc-expected.txt [new file with mode: 0644]
LayoutTests/crypto/subtle/crypto-key-usages-gc.html [new file with mode: 0644]
LayoutTests/crypto/subtle/hmac-generate-key-expected.txt
LayoutTests/crypto/subtle/hmac-generate-key.html
Source/WebCore/ChangeLog
Source/WebCore/PlatformEfl.cmake
Source/WebCore/PlatformGTK.cmake
Source/WebCore/PlatformMac.cmake
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.cpp
Source/WebCore/bindings/js/JSCryptoAlgorithmBuilder.h
Source/WebCore/bindings/js/JSCryptoKeyCustom.cpp
Source/WebCore/crypto/CryptoAlgorithmDescriptionBuilder.cpp [deleted file]
Source/WebCore/crypto/CryptoAlgorithmDescriptionBuilder.h [deleted file]
Source/WebCore/crypto/CryptoKey.cpp
Source/WebCore/crypto/CryptoKey.h
Source/WebCore/crypto/CryptoKey.idl
Source/WebCore/crypto/gnutls/CryptoKeyRSAGnuTLS.cpp
Source/WebCore/crypto/keys/CryptoKeyAES.cpp
Source/WebCore/crypto/keys/CryptoKeyAES.h
Source/WebCore/crypto/keys/CryptoKeyHMAC.cpp
Source/WebCore/crypto/keys/CryptoKeyHMAC.h
Source/WebCore/crypto/keys/CryptoKeyRSA.h
Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp

index a969aba..f59233c 100644 (file)
@@ -1,3 +1,18 @@
+2016-09-14  Jiewen Tan  <jiewen_tan@apple.com>
+
+        WebCrypto algorithms should be exposed via KeyAlgorithm dictionary
+        https://bugs.webkit.org/show_bug.cgi?id=128748
+        <rdar://problem/27359438>
+
+        Reviewed by Brent Fulgham and Chris Dumez.
+
+        * crypto/subtle/crypto-key-algorithm-gc-expected.txt: Added.
+        * crypto/subtle/crypto-key-algorithm-gc.html: Added.
+        * crypto/subtle/crypto-key-usages-gc-expected.txt: Added.
+        * crypto/subtle/crypto-key-usages-gc.html: Added.
+        * crypto/subtle/hmac-generate-key-expected.txt:
+        * crypto/subtle/hmac-generate-key.html:
+
 2016-09-14  Chris Dumez  <cdumez@apple.com>
 
         REGRESSION (r205670): ASSERTION FAILED: methodTable(vm)->toThis(this, exec, NotStrictMode) == this
diff --git a/LayoutTests/crypto/subtle/crypto-key-algorithm-gc-expected.txt b/LayoutTests/crypto/subtle/crypto-key-algorithm-gc-expected.txt
new file mode 100644 (file)
index 0000000..77d1766
--- /dev/null
@@ -0,0 +1,13 @@
+Test that CryptoKey.algorithm preserves custom properties.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+Generating a HMAC key with default length...
+PASS key.algorithm === key.algorithm is true
+PASS key.algorithm.foo is "bar"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/crypto-key-algorithm-gc.html b/LayoutTests/crypto/subtle/crypto-key-algorithm-gc.html
new file mode 100644 (file)
index 0000000..810dc74
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src="../../resources/js-test-pre.js"></script>
+<script src="resources/common.js"></script>
+</head>
+<body>
+<script>
+
+description("Test that CryptoKey.algorithm preserves custom properties.");
+jsTestIsAsync = true;
+
+debug("\nGenerating a HMAC key with default length...");
+crypto.subtle.generateKey({name: "hmac", hash: "sha-1"}, true, ["sign", "verify"]).then(function(result) {
+    key = result;
+    startTest();
+});
+
+function startTest()
+{
+    shouldBeTrue("key.algorithm === key.algorithm");
+    key.algorithm.foo = "bar";
+    gc();
+    setTimeout(continueTest, 10);
+}
+
+function continueTest()
+{
+    gc();
+    setTimeout(finishTest, 10);
+}
+
+function finishTest()
+{
+    gc();
+    shouldBeEqualToString('key.algorithm.foo', 'bar');
+    finishJSTest();
+}
+
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/crypto/subtle/crypto-key-usages-gc-expected.txt b/LayoutTests/crypto/subtle/crypto-key-usages-gc-expected.txt
new file mode 100644 (file)
index 0000000..ed155f0
--- /dev/null
@@ -0,0 +1,13 @@
+Test that CryptoKey.usages preserves custom properties.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+Generating a HMAC key with default length...
+PASS key.usages === key.usages is true
+PASS key.usages.foo is "bar"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/crypto/subtle/crypto-key-usages-gc.html b/LayoutTests/crypto/subtle/crypto-key-usages-gc.html
new file mode 100644 (file)
index 0000000..cc27737
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src="../../resources/js-test-pre.js"></script>
+<script src="resources/common.js"></script>
+</head>
+<body>
+<script>
+
+description("Test that CryptoKey.usages preserves custom properties.");
+jsTestIsAsync = true;
+
+debug("\nGenerating a HMAC key with default length...");
+crypto.subtle.generateKey({name: "hmac", hash: "sha-1"}, true, ["sign", "verify"]).then(function(result) {
+    key = result;
+    startTest();
+});
+
+function startTest()
+{
+    shouldBeTrue("key.usages === key.usages");
+    key.usages.foo = "bar";
+    gc();
+    setTimeout(continueTest, 10);
+}
+
+function continueTest()
+{
+    gc();
+    setTimeout(finishTest, 10);
+}
+
+function finishTest()
+{
+    gc();
+    shouldBeEqualToString('key.usages.foo', 'bar');
+    finishJSTest();
+}
+
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
index 5bd31bd..53921e4 100644 (file)
@@ -13,6 +13,7 @@ PASS key.type is 'secret'
 PASS key.extractable is true
 PASS key.algorithm.name is 'HMAC'
 PASS key.algorithm.length is 64
+PASS key.algorithm.hash.name is 'SHA-1'
 PASS key.usages is ["sign", "verify"]
 
 Generating a key with custom length...
@@ -20,6 +21,7 @@ PASS key.type is 'secret'
 PASS key.extractable is true
 PASS key.algorithm.name is 'HMAC'
 PASS key.algorithm.length is 5
+PASS key.algorithm.hash.name is 'SHA-1'
 PASS key.usages is ["sign"]
 PASS successfullyParsed is true
 
index 3afc568..2b9bf3a 100644 (file)
@@ -28,6 +28,7 @@ crypto.subtle.generateKey({name: "hmac", hash: "sha-1"}, extractable, ["sign", "
     shouldBe("key.extractable", "true");
     shouldBe("key.algorithm.name", "'HMAC'");
     shouldBe("key.algorithm.length", "64");
+    shouldBe("key.algorithm.hash.name", "'SHA-1'");
     shouldBe("key.usages", '["sign", "verify"]');
 
     debug("\nGenerating a key with custom length...");
@@ -39,6 +40,7 @@ crypto.subtle.generateKey({name: "hmac", hash: "sha-1"}, extractable, ["sign", "
     shouldBe("key.extractable", "true");
     shouldBe("key.algorithm.name", "'HMAC'");
     shouldBe("key.algorithm.length", "5");
+    shouldBe("key.algorithm.hash.name", "'SHA-1'");
     shouldBe("key.usages", '["sign"]');
     finishJSTest();
 });
index f23e608..7a24bf7 100644 (file)
@@ -1,3 +1,68 @@
+2016-09-14  Jiewen Tan  <jiewen_tan@apple.com>
+
+        WebCrypto algorithms should be exposed via KeyAlgorithm dictionary
+        https://bugs.webkit.org/show_bug.cgi?id=128748
+        <rdar://problem/27359438>
+
+        Reviewed by Brent Fulgham and Chris Dumez.
+
+        Replace custom CryptoAlgorithmBuilder/buildAlgorithmDescription with KeyAlgorithm dictionary which is
+        defined by the spec: https://www.w3.org/TR/WebCryptoAPI/#key-algorithm-dictionary. Moreover, mark
+        CryptoKey.usages as CachedAttribute.
+
+        Tests: crypto/subtle/crypto-key-algorithm-gc.html
+               crypto/subtle/crypto-key-usages-gc.html
+
+        * PlatformEfl.cmake:
+        * PlatformGTK.cmake:
+        * PlatformMac.cmake:
+        Remove CryptoAlgorithmDescriptionBuilder.cpp.
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSCryptoAlgorithmBuilder.cpp:
+        (WebCore::JSCryptoAlgorithmBuilder::add):
+        (WebCore::JSCryptoAlgorithmBuilder::createEmptyClone): Deleted.
+        * bindings/js/JSCryptoAlgorithmBuilder.h:
+        * bindings/js/JSCryptoKeyCustom.cpp:
+        (WebCore::JSCryptoKey::algorithm):
+        Get rid of dependency on CryptoAlgorithmDescriptionBuilder.
+        * crypto/CryptoAlgorithmDescriptionBuilder.cpp: Removed.
+        * crypto/CryptoAlgorithmDescriptionBuilder.h: Removed.
+        Replace it with KeyAlgorithm.
+        * crypto/CryptoKey.cpp:
+        (WebCore::CryptoKey::CryptoKey):
+        (WebCore::CryptoKey::buildAlgorithmDescription): Deleted.
+        * crypto/CryptoKey.h:
+        (WebCore::KeyAlgorithm::KeyAlgorithm):
+        (WebCore::KeyAlgorithm::~KeyAlgorithm):
+        (WebCore::CryptoKey::algorithmIdentifier):
+        * crypto/CryptoKey.idl:
+        Add KeyAlgorithm dictionary which is returned via CryptoKey.buildAlgorithm() method,
+        and rename m_algorithm to m_algorithmIdentifier to distingush it with newly
+        added KeyAlgorithm dictionary.
+        * crypto/gnutls/CryptoKeyRSAGnuTLS.cpp:
+        (WebCore::buildAlgorithm):
+        (WebCore::CryptoKeyRSA::buildAlgorithmDescription): Deleted.
+        * crypto/keys/CryptoKeyAES.cpp:
+        (WebCore::CryptoKeyAES::buildAlgorithm):
+        (WebCore::CryptoKeyAES::buildAlgorithmDescription): Deleted.
+        * crypto/keys/CryptoKeyAES.h:
+        (WebCore::AesKeyAlgorithm::AesKeyAlgorithm):
+        (WebCore::AesKeyAlgorithm::~AesKeyAlgorithm):
+        * crypto/keys/CryptoKeyHMAC.cpp:
+        (WebCore::CryptoKeyHMAC::buildAlgorithm):
+        (WebCore::CryptoKeyHMAC::buildAlgorithmDescription): Deleted.
+        * crypto/keys/CryptoKeyHMAC.h:
+        (WebCore::HmacKeyAlgorithm::HmacKeyAlgorithm):
+        (WebCore::HmacKeyAlgorithm::~HmacKeyAlgorithm):
+        * crypto/keys/CryptoKeyRSA.h:
+        (WebCore::RsaKeyAlgorithm::RsaKeyAlgorithm):
+        (WebCore::RsaKeyAlgorithm::~RsaKeyAlgorithm):
+        (WebCore::RsaHashedKeyAlgorithm::RsaHashedKeyAlgorithm):
+        (WebCore::RsaHashedKeyAlgorithm::~RsaHashedKeyAlgorithm):
+        * crypto/mac/CryptoKeyRSAMac.cpp:
+        (WebCore::CryptoKeyRSA::buildAlgorithm):
+        (WebCore::CryptoKeyRSA::buildAlgorithmDescription): Deleted.
+
 2016-09-14  Chris Dumez  <cdumez@apple.com>
 
         REGRESSION (r205670): ASSERTION FAILED: methodTable(vm)->toThis(this, exec, NotStrictMode) == this
index c51d1c2..6f687e8 100644 (file)
@@ -403,7 +403,6 @@ endif ()
 if (ENABLE_SUBTLE_CRYPTO)
     list(APPEND WebCore_SOURCES
         crypto/CryptoAlgorithm.cpp
-        crypto/CryptoAlgorithmDescriptionBuilder.cpp
         crypto/CryptoAlgorithmRegistry.cpp
         crypto/CryptoKey.cpp
         crypto/CryptoKeyPair.cpp
index 59f222f..9daeff3 100644 (file)
@@ -397,7 +397,6 @@ endif ()
 if (ENABLE_SUBTLE_CRYPTO)
     list(APPEND WebCore_SOURCES
         crypto/CryptoAlgorithm.cpp
-        crypto/CryptoAlgorithmDescriptionBuilder.cpp
         crypto/CryptoAlgorithmRegistry.cpp
         crypto/CryptoKey.cpp
         crypto/CryptoKeyPair.cpp
index 4a8f862..34b8db2 100644 (file)
@@ -176,7 +176,6 @@ list(APPEND WebCore_SOURCES
 
     crypto/CommonCryptoUtilities.cpp
     crypto/CryptoAlgorithm.cpp
-    crypto/CryptoAlgorithmDescriptionBuilder.cpp
     crypto/CryptoAlgorithmRegistry.cpp
     crypto/CryptoKey.cpp
     crypto/CryptoKeyPair.cpp
index 28ca673..4c6fcc9 100644 (file)
                E157A8E418173A3A009F821D /* CryptoKey.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E157A8E218173A3A009F821D /* CryptoKey.cpp */; };
                E157A8E518173A3A009F821D /* CryptoKey.h in Headers */ = {isa = PBXBuildFile; fileRef = E157A8E318173A3A009F821D /* CryptoKey.h */; };
                E157A8E818184C67009F821D /* JSCryptoKeyCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E157A8E618184C67009F821D /* JSCryptoKeyCustom.cpp */; };
-               E157A8EC181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E157A8EA181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.cpp */; };
-               E157A8ED181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = E157A8EB181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.h */; };
                E157A8F018185425009F821D /* JSCryptoAlgorithmBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E157A8EE18185425009F821D /* JSCryptoAlgorithmBuilder.cpp */; };
                E157A8F118185425009F821D /* JSCryptoAlgorithmBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = E157A8EF18185425009F821D /* JSCryptoAlgorithmBuilder.h */; };
                E15A36D71104572000B7B639 /* XMLNSNames.h in Headers */ = {isa = PBXBuildFile; fileRef = E15A36D61104572000B7B639 /* XMLNSNames.h */; };
                E157A8E218173A3A009F821D /* CryptoKey.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoKey.cpp; sourceTree = "<group>"; };
                E157A8E318173A3A009F821D /* CryptoKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKey.h; sourceTree = "<group>"; };
                E157A8E618184C67009F821D /* JSCryptoKeyCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCryptoKeyCustom.cpp; sourceTree = "<group>"; };
-               E157A8EA181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CryptoAlgorithmDescriptionBuilder.cpp; sourceTree = "<group>"; };
-               E157A8EB181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmDescriptionBuilder.h; sourceTree = "<group>"; };
                E157A8EE18185425009F821D /* JSCryptoAlgorithmBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCryptoAlgorithmBuilder.cpp; sourceTree = "<group>"; };
                E157A8EF18185425009F821D /* JSCryptoAlgorithmBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCryptoAlgorithmBuilder.h; sourceTree = "<group>"; };
                E15A36D61104572000B7B639 /* XMLNSNames.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMLNSNames.h; sourceTree = "<group>"; };
                                E1FE137318402A6700892F13 /* CommonCryptoUtilities.h */,
                                E172AF6B180F24C600FBADB9 /* CryptoAlgorithm.cpp */,
                                E172AF6C180F24C600FBADB9 /* CryptoAlgorithm.h */,
-                               E157A8EA181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.cpp */,
-                               E157A8EB181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.h */,
                                E1C657241816E69D00256CDD /* CryptoAlgorithmIdentifier.h */,
                                E1C657261816F9FE00256CDD /* CryptoAlgorithmParameters.h */,
                                E1FF8F6A180DB5BE00132674 /* CryptoAlgorithmRegistry.cpp */,
                                E1FE137B184D21BB00892F13 /* CryptoAlgorithmAES_KW.h in Headers */,
                                E125F83A1824104800D84CD9 /* CryptoAlgorithmAesCbcParams.h in Headers */,
                                E19AC3F71824E5D100349426 /* CryptoAlgorithmAesKeyGenParams.h in Headers */,
-                               E157A8ED181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.h in Headers */,
                                E125F8321822F11B00D84CD9 /* CryptoAlgorithmHMAC.h in Headers */,
                                E19DA29C18189ADD00088BC8 /* CryptoAlgorithmHmacKeyParams.h in Headers */,
                                E1C6571F1816E50300256CDD /* CryptoAlgorithmHmacParams.h in Headers */,
                                E125F845182425C900D84CD9 /* CryptoAlgorithmAES_CBCMac.cpp in Sources */,
                                E1FE137A184D21BB00892F13 /* CryptoAlgorithmAES_KW.cpp in Sources */,
                                E1FE137E184D270200892F13 /* CryptoAlgorithmAES_KWMac.cpp in Sources */,
-                               E157A8EC181851AC009F821D /* CryptoAlgorithmDescriptionBuilder.cpp in Sources */,
                                E125F8311822F11B00D84CD9 /* CryptoAlgorithmHMAC.cpp in Sources */,
                                E125F8381822F1EB00D84CD9 /* CryptoAlgorithmHMACMac.cpp in Sources */,
                                E1FF8F6C180DB5BE00132674 /* CryptoAlgorithmRegistry.cpp in Sources */,
index a9f3726..d99c27a 100644 (file)
@@ -48,11 +48,6 @@ JSCryptoAlgorithmBuilder::~JSCryptoAlgorithmBuilder()
 {
 }
 
-std::unique_ptr<CryptoAlgorithmDescriptionBuilder> JSCryptoAlgorithmBuilder::createEmptyClone() const
-{
-    return std::make_unique<JSCryptoAlgorithmBuilder>(m_exec);
-}
-
 void JSCryptoAlgorithmBuilder::add(const char* key, unsigned value)
 {
     VM& vm = m_exec->vm();
@@ -75,12 +70,11 @@ void JSCryptoAlgorithmBuilder::add(const char* key, const Vector<uint8_t>& buffe
     m_dictionary->putDirect(vm, identifier, arrayView->wrap(m_exec, vm.entryScope->globalObject()));
 }
 
-void JSCryptoAlgorithmBuilder::add(const char* key, const CryptoAlgorithmDescriptionBuilder& nestedBuilder)
+void JSCryptoAlgorithmBuilder::add(const char* key, const JSCryptoAlgorithmBuilder& nestedBuilder)
 {
     VM& vm = m_exec->vm();
     Identifier identifier = Identifier::fromString(&vm, key);
-    const JSCryptoAlgorithmBuilder& jsBuilder = static_cast<const JSCryptoAlgorithmBuilder&>(nestedBuilder);
-    m_dictionary->putDirect(vm, identifier, jsBuilder.result());
+    m_dictionary->putDirect(vm, identifier, nestedBuilder.result());
 }
 
 } // namespace WebCore
index d537b4c..2873bd1 100644 (file)
 #ifndef JSCryptoAlgorithmBuilder_h
 #define JSCryptoAlgorithmBuilder_h
 
-#include "CryptoAlgorithmDescriptionBuilder.h"
+#include <wtf/Forward.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
 
 #if ENABLE(SUBTLE_CRYPTO)
 
@@ -37,19 +40,18 @@ class JSObject;
 
 namespace WebCore {
 
-class JSCryptoAlgorithmBuilder final : public CryptoAlgorithmDescriptionBuilder {
+class JSCryptoAlgorithmBuilder {
+    WTF_MAKE_NONCOPYABLE(JSCryptoAlgorithmBuilder);
 public:
     JSCryptoAlgorithmBuilder(JSC::ExecState*);
     virtual ~JSCryptoAlgorithmBuilder();
 
     JSC::JSObject* result() const { return m_dictionary; }
 
-    std::unique_ptr<CryptoAlgorithmDescriptionBuilder> createEmptyClone() const override;
-
-    void add(const char*, unsigned) override;
-    void add(const char*, const String&) override;
-    void add(const char*, const Vector<uint8_t>&) override;
-    void add(const char*, const CryptoAlgorithmDescriptionBuilder&) override;
+    void add(const char*, unsigned);
+    void add(const char*, const String&);
+    void add(const char*, const Vector<uint8_t>&);
+    void add(const char*, const JSCryptoAlgorithmBuilder&);
 
 private:
     JSC::ExecState* m_exec;
index 58594be..e975400 100644 (file)
 
 #if ENABLE(SUBTLE_CRYPTO)
 
+#include "CryptoKeyAES.h"
+#include "CryptoKeyHMAC.h"
+#include "CryptoKeyRSA.h"
 #include "JSCryptoAlgorithmBuilder.h"
+#include <heap/HeapInlines.h>
 #include <runtime/JSCJSValueInlines.h>
 
 using namespace JSC;
@@ -37,11 +41,50 @@ namespace WebCore {
 
 JSValue JSCryptoKey::algorithm(JSC::ExecState& state) const
 {
+    if (m_algorithm)
+        return m_algorithm.get();
+
     JSCryptoAlgorithmBuilder builder(&state);
-    wrapped().buildAlgorithmDescription(builder);
-    return builder.result();
-}
 
+    std::unique_ptr<KeyAlgorithm> algorithm = wrapped().buildAlgorithm();
+    switch (algorithm->keyAlgorithmClass()) {
+    case KeyAlgorithmClass::AES: {
+        auto& aesAlgorithm = downcast<AesKeyAlgorithm>(*algorithm);
+        builder.add("name", aesAlgorithm.name());
+        builder.add("length", aesAlgorithm.length());
+        break;
+    }
+    case KeyAlgorithmClass::HMAC: {
+        auto& hmacAlgorithm = downcast<HmacKeyAlgorithm>(*algorithm);
+        builder.add("name", hmacAlgorithm.name());
+        JSCryptoAlgorithmBuilder hmacHash(&state);
+        hmacHash.add("name", hmacAlgorithm.hash());
+        builder.add("hash", hmacHash);
+        builder.add("length", hmacAlgorithm.length());
+        break;
+    }
+    case KeyAlgorithmClass::HRSA: {
+        auto& rsaAlgorithm = downcast<RsaHashedKeyAlgorithm>(*algorithm);
+        builder.add("name", rsaAlgorithm.name());
+        builder.add("modulusLength", rsaAlgorithm.modulusLength());
+        builder.add("publicExponent", rsaAlgorithm.publicExponent());
+        JSCryptoAlgorithmBuilder rsaHash(&state);
+        rsaHash.add("name", rsaAlgorithm.hash());
+        builder.add("hash", rsaHash);
+        break;
+    }
+    case KeyAlgorithmClass::RSA: {
+        auto& rsaAlgorithm = downcast<RsaKeyAlgorithm>(*algorithm);
+        builder.add("name", rsaAlgorithm.name());
+        builder.add("modulusLength", rsaAlgorithm.modulusLength());
+        builder.add("publicExponent", rsaAlgorithm.publicExponent());
+        break;
+    }
+    }
+
+    m_algorithm.set(state.vm(), this, builder.result());
+    return m_algorithm.get();
+}
 
 } // namespace WebCore
 
diff --git a/Source/WebCore/crypto/CryptoAlgorithmDescriptionBuilder.cpp b/Source/WebCore/crypto/CryptoAlgorithmDescriptionBuilder.cpp
deleted file mode 100644 (file)
index 8b2277e..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "CryptoAlgorithmDescriptionBuilder.h"
-
-#if ENABLE(SUBTLE_CRYPTO)
-
-namespace WebCore {
-
-CryptoAlgorithmDescriptionBuilder::CryptoAlgorithmDescriptionBuilder()
-{
-}
-
-CryptoAlgorithmDescriptionBuilder::~CryptoAlgorithmDescriptionBuilder()
-{
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(SUBTLE_CRYPTO)
diff --git a/Source/WebCore/crypto/CryptoAlgorithmDescriptionBuilder.h b/Source/WebCore/crypto/CryptoAlgorithmDescriptionBuilder.h
deleted file mode 100644 (file)
index a7fe14b..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef CryptoAlgorithmDescriptionBuilder_h
-#define CryptoAlgorithmDescriptionBuilder_h
-
-#include <wtf/Forward.h>
-#include <wtf/Noncopyable.h>
-#include <wtf/Vector.h>
-
-#if ENABLE(SUBTLE_CRYPTO)
-
-namespace WebCore {
-
-class CryptoAlgorithmDescriptionBuilder {
-    WTF_MAKE_NONCOPYABLE(CryptoAlgorithmDescriptionBuilder);
-public:
-    CryptoAlgorithmDescriptionBuilder();
-    virtual ~CryptoAlgorithmDescriptionBuilder();
-
-    virtual std::unique_ptr<CryptoAlgorithmDescriptionBuilder> createEmptyClone() const = 0;
-
-    virtual void add(const char*, unsigned) = 0;
-    virtual void add(const char*, const String&) = 0;
-    virtual void add(const char*, const Vector<uint8_t>&) = 0;
-    virtual void add(const char*, const CryptoAlgorithmDescriptionBuilder&) = 0;
-};
-
-} // namespace WebCore
-
-#endif // ENABLE(SUBTLE_CRYPTO)
-#endif // CryptoAlgorithmDescriptionBuilder_h
index d827f7c..6007506 100644 (file)
 
 #if ENABLE(SUBTLE_CRYPTO)
 
-#include "CryptoAlgorithmDescriptionBuilder.h"
 #include "CryptoAlgorithmRegistry.h"
 #include <wtf/CryptographicallyRandomNumber.h>
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
-CryptoKey::CryptoKey(CryptoAlgorithmIdentifier algorithm, Type type, bool extractable, CryptoKeyUsage usages)
-    : m_algorithm(algorithm)
+CryptoKey::CryptoKey(CryptoAlgorithmIdentifier algorithmIdentifier, Type type, bool extractable, CryptoKeyUsage usages)
+    : m_algorithmIdentifier(algorithmIdentifier)
     , m_type(type)
     , m_extractable(extractable)
     , m_usages(usages)
@@ -47,12 +45,6 @@ CryptoKey::~CryptoKey()
 {
 }
 
-void CryptoKey::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder& builder) const
-{
-    builder.add("name", CryptoAlgorithmRegistry::singleton().nameForIdentifier(m_algorithm));
-    // Subclasses will add other keys.
-}
-
 auto CryptoKey::usages() const -> Vector<Usage>
 {
     // The result is ordered alphabetically.
index eb6b701..fb8945f 100644 (file)
@@ -35,6 +35,7 @@
 #include <wtf/RefCounted.h>
 #include <wtf/TypeCasts.h>
 #include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -42,11 +43,38 @@ class CryptoAlgorithmDescriptionBuilder;
 class CryptoKeyData;
 
 enum class CryptoKeyClass {
-    HMAC,
     AES,
+    HMAC,
     RSA
 };
 
+enum class KeyAlgorithmClass {
+    AES,
+    HMAC,
+    HRSA,
+    RSA,
+};
+
+class KeyAlgorithm {
+public:
+    virtual ~KeyAlgorithm()
+    {
+    }
+
+    virtual KeyAlgorithmClass keyAlgorithmClass() const = 0;
+
+    const String& name() const { return m_name; }
+
+protected:
+    explicit KeyAlgorithm(const String& name)
+        : m_name(name)
+    {
+    }
+
+private:
+    String m_name;
+};
+
 class CryptoKey : public RefCounted<CryptoKey> {
 public:
     using Type = CryptoKeyType;
@@ -57,7 +85,7 @@ public:
 
     Type type() const;
     bool extractable() const { return m_extractable; }
-    virtual void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const;
+    virtual std::unique_ptr<KeyAlgorithm> buildAlgorithm() const = 0;
 
     // FIXME: Confusing to have CryptoKeyUsage and CryptoKey::Usage named almost the same, but be slightly different.
     // CryptoKeyUsage values are bit masks so they can be combined with "or", while this is a normal enum that must
@@ -65,7 +93,7 @@ public:
     enum class Usage { Encrypt, Decrypt, Sign, Verify, DeriveKey, DeriveBits, WrapKey, UnwrapKey };
     Vector<Usage> usages() const;
 
-    CryptoAlgorithmIdentifier algorithmIdentifier() const { return m_algorithm; }
+    CryptoAlgorithmIdentifier algorithmIdentifier() const { return m_algorithmIdentifier; }
     CryptoKeyUsage usagesBitmap() const { return m_usages; }
     bool allows(CryptoKeyUsage usage) const { return usage == (m_usages & usage); }
 
@@ -74,7 +102,7 @@ public:
     static Vector<uint8_t> randomData(size_t);
 
 private:
-    CryptoAlgorithmIdentifier m_algorithm;
+    CryptoAlgorithmIdentifier m_algorithmIdentifier;
     Type m_type;
     bool m_extractable;
     CryptoKeyUsage m_usages;
@@ -92,5 +120,10 @@ SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToClassName) \
     static bool isType(const WebCore::CryptoKey& key) { return key.keyClass() == WebCore::KeyClass; } \
 SPECIALIZE_TYPE_TRAITS_END()
 
+#define SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(ToClassName, KeyAlgorithmClass) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToClassName) \
+    static bool isType(const WebCore::KeyAlgorithm& algorithm) { return algorithm.keyAlgorithmClass() == WebCore::KeyAlgorithmClass; } \
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // ENABLE(SUBTLE_CRYPTO)
 #endif // CryptoKey_h
index c4f1c3c..dc756e7 100644 (file)
@@ -47,6 +47,6 @@ enum KeyUsage {
 ] interface CryptoKey {
     readonly attribute KeyType type;
     readonly attribute boolean extractable;
-    [Custom] readonly attribute Algorithm algorithm;
-    readonly attribute sequence<KeyUsage> usages;
+    [CachedAttribute, CustomGetter] readonly attribute object algorithm;
+    [CachedAttribute] readonly attribute sequence<KeyUsage> usages;
 };
index d7045a5..16f6db3 100644 (file)
@@ -28,7 +28,6 @@
 
 #if ENABLE(SUBTLE_CRYPTO)
 
-#include "CryptoAlgorithmDescriptionBuilder.h"
 #include "CryptoAlgorithmRegistry.h"
 #include "CryptoKeyDataRSAComponents.h"
 #include "CryptoKeyPair.h"
@@ -81,10 +80,11 @@ size_t CryptoKeyRSA::keySizeInBits() const
     return 0;
 }
 
-void CryptoKeyRSA::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder& builder) const
+std::unique_ptr<KeyAlgorithm> CryptoKeyRSA::buildAlgorithm() const
 {
     notImplemented();
-    UNUSED_PARAM(builder);
+    Vector<uint8_t> publicExponent;
+    return std::make_unique<RsaKeyAlgorithm>(emptyString(), 0, WTFMove(publicExponent));
 }
 
 std::unique_ptr<CryptoKeyData> CryptoKeyRSA::exportData() const
index 44b5007..a0af254 100644 (file)
@@ -28,7 +28,6 @@
 
 #if ENABLE(SUBTLE_CRYPTO)
 
-#include "CryptoAlgorithmDescriptionBuilder.h"
 #include "CryptoAlgorithmRegistry.h"
 #include "CryptoKeyDataOctetSequence.h"
 #include <wtf/text/WTFString.h>
@@ -63,10 +62,9 @@ RefPtr<CryptoKeyAES> CryptoKeyAES::generate(CryptoAlgorithmIdentifier algorithm,
     return adoptRef(new CryptoKeyAES(algorithm, randomData(lengthBits / 8), extractable, usages));
 }
 
-void CryptoKeyAES::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder& builder) const
+std::unique_ptr<KeyAlgorithm> CryptoKeyAES::buildAlgorithm() const
 {
-    CryptoKey::buildAlgorithmDescription(builder);
-    builder.add("length", m_key.size() * 8);
+    return std::make_unique<AesKeyAlgorithm>(CryptoAlgorithmRegistry::singleton().nameForIdentifier(algorithmIdentifier()), m_key.size() * 8);
 }
 
 std::unique_ptr<CryptoKeyData> CryptoKeyAES::exportData() const
index 45a5bb8..527059f 100644 (file)
 
 namespace WebCore {
 
+class AesKeyAlgorithm final : public KeyAlgorithm {
+public:
+    AesKeyAlgorithm(const String& name, size_t length)
+        : KeyAlgorithm(name)
+        , m_length(length)
+    {
+    }
+
+    KeyAlgorithmClass keyAlgorithmClass() const final { return KeyAlgorithmClass::AES; }
+
+    size_t length() const { return m_length; }
+
+private:
+    size_t m_length;
+};
+
 class CryptoKeyAES final : public CryptoKey {
 public:
     static Ref<CryptoKeyAES> create(CryptoAlgorithmIdentifier algorithm, const Vector<uint8_t>& key, bool extractable, CryptoKeyUsage usage)
@@ -46,15 +62,15 @@ public:
 
     static RefPtr<CryptoKeyAES> generate(CryptoAlgorithmIdentifier, size_t lengthBits, bool extractable, CryptoKeyUsage);
 
-    CryptoKeyClass keyClass() const override { return CryptoKeyClass::AES; }
+    CryptoKeyClass keyClass() const final { return CryptoKeyClass::AES; }
 
     const Vector<uint8_t>& key() const { return m_key; }
 
 private:
     CryptoKeyAES(CryptoAlgorithmIdentifier, const Vector<uint8_t>& key, bool extractable, CryptoKeyUsage);
 
-    void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const override;
-    std::unique_ptr<CryptoKeyData> exportData() const override;
+    std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
+    std::unique_ptr<CryptoKeyData> exportData() const final;
 
     Vector<uint8_t> m_key;
 };
@@ -63,6 +79,8 @@ private:
 
 SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyAES, CryptoKeyClass::AES)
 
+SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(AesKeyAlgorithm, KeyAlgorithmClass::AES)
+
 #endif // ENABLE(SUBTLE_CRYPTO)
 
 #endif // CryptoKeyAES_h
index af604f4..c574f77 100644 (file)
@@ -28,7 +28,6 @@
 
 #if ENABLE(SUBTLE_CRYPTO)
 
-#include "CryptoAlgorithmDescriptionBuilder.h"
 #include "CryptoAlgorithmRegistry.h"
 #include "CryptoKeyDataOctetSequence.h"
 #include <wtf/text/WTFString.h>
@@ -67,15 +66,10 @@ RefPtr<CryptoKeyHMAC> CryptoKeyHMAC::generate(size_t lengthBytes, CryptoAlgorith
     return adoptRef(new CryptoKeyHMAC(randomData(lengthBytes), hash, extractable, usages));
 }
 
-void CryptoKeyHMAC::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder& builder) const
+std::unique_ptr<KeyAlgorithm> CryptoKeyHMAC::buildAlgorithm() const
 {
-    CryptoKey::buildAlgorithmDescription(builder);
-
-    auto hashDescriptionBuilder = builder.createEmptyClone();
-    hashDescriptionBuilder->add("name", CryptoAlgorithmRegistry::singleton().nameForIdentifier(m_hash));
-    builder.add("hash", *hashDescriptionBuilder);
-
-    builder.add("length", m_key.size());
+    return std::make_unique<HmacKeyAlgorithm>(CryptoAlgorithmRegistry::singleton().nameForIdentifier(algorithmIdentifier()),
+        CryptoAlgorithmRegistry::singleton().nameForIdentifier(m_hash), m_key.size());
 }
 
 std::unique_ptr<CryptoKeyData> CryptoKeyHMAC::exportData() const
index 468ad07..524207e 100644 (file)
 
 namespace WebCore {
 
+class HmacKeyAlgorithm final : public KeyAlgorithm {
+public:
+    HmacKeyAlgorithm(const String& name, const String& hash, size_t length)
+        : KeyAlgorithm(name)
+        , m_hash(hash)
+        , m_length(length)
+    {
+    }
+
+    KeyAlgorithmClass keyAlgorithmClass() const final { return KeyAlgorithmClass::HMAC; }
+
+    const String& hash() const { return m_hash; }
+    size_t length() const { return m_length; }
+
+private:
+    String m_hash;
+    size_t m_length;
+};
+
 class CryptoKeyHMAC final : public CryptoKey {
 public:
     static Ref<CryptoKeyHMAC> create(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage usage)
@@ -44,7 +63,7 @@ public:
     // If lengthBytes is 0, a recommended length is used, which is the size of the associated hash function's block size.
     static RefPtr<CryptoKeyHMAC> generate(size_t lengthBytes, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage);
 
-    CryptoKeyClass keyClass() const override { return CryptoKeyClass::HMAC; }
+    CryptoKeyClass keyClass() const final { return CryptoKeyClass::HMAC; }
 
     const Vector<uint8_t>& key() const { return m_key; }
 
@@ -53,8 +72,8 @@ public:
 private:
     CryptoKeyHMAC(const Vector<uint8_t>& key, CryptoAlgorithmIdentifier hash, bool extractable, CryptoKeyUsage);
 
-    void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const override;
-    std::unique_ptr<CryptoKeyData> exportData() const override;
+    std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
+    std::unique_ptr<CryptoKeyData> exportData() const final;
 
     CryptoAlgorithmIdentifier m_hash;
     Vector<uint8_t> m_key;
@@ -64,5 +83,7 @@ private:
 
 SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyHMAC, CryptoKeyClass::HMAC)
 
+SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(HmacKeyAlgorithm, KeyAlgorithmClass::HMAC)
+
 #endif // ENABLE(SUBTLE_CRYPTO)
 #endif // CryptoKeyHMAC_h
index 6ea200b..726c9bf 100644 (file)
@@ -47,6 +47,41 @@ class CryptoKeyDataRSAComponents;
 class CryptoKeyPair;
 class PromiseWrapper;
 
+class RsaKeyAlgorithm : public KeyAlgorithm {
+public:
+    RsaKeyAlgorithm(const String& name, size_t modulusLength, Vector<uint8_t>&& publicExponent)
+        : KeyAlgorithm(name)
+        , m_modulusLength(modulusLength)
+        , m_publicExponent(WTFMove(publicExponent))
+    {
+    }
+
+    KeyAlgorithmClass keyAlgorithmClass() const override { return KeyAlgorithmClass::RSA; }
+
+    size_t modulusLength() const { return m_modulusLength; }
+    const Vector<uint8_t>& publicExponent() const { return m_publicExponent; }
+
+private:
+    size_t m_modulusLength;
+    Vector<uint8_t> m_publicExponent;
+};
+
+class RsaHashedKeyAlgorithm final : public RsaKeyAlgorithm {
+public:
+    RsaHashedKeyAlgorithm(const String& name, size_t modulusLength, Vector<uint8_t>&& publicExponent, const String& hash)
+        : RsaKeyAlgorithm(name, modulusLength, WTFMove(publicExponent))
+        , m_hash(hash)
+    {
+    }
+
+    KeyAlgorithmClass keyAlgorithmClass() const final { return KeyAlgorithmClass::HRSA; }
+
+    const String& hash() const { return m_hash; }
+
+private:
+    String m_hash;
+};
+
 class CryptoKeyRSA final : public CryptoKey {
 public:
     static Ref<CryptoKeyRSA> create(CryptoAlgorithmIdentifier identifier, CryptoAlgorithmIdentifier hash, bool hasHash, CryptoKeyType type, PlatformRSAKey platformKey, bool extractable, CryptoKeyUsage usage)
@@ -69,10 +104,10 @@ public:
 private:
     CryptoKeyRSA(CryptoAlgorithmIdentifier, CryptoAlgorithmIdentifier hash, bool hasHash, CryptoKeyType, PlatformRSAKey, bool extractable, CryptoKeyUsage);
 
-    CryptoKeyClass keyClass() const override { return CryptoKeyClass::RSA; }
+    CryptoKeyClass keyClass() const final { return CryptoKeyClass::RSA; }
 
-    void buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder&) const override;
-    std::unique_ptr<CryptoKeyData> exportData() const override;
+    std::unique_ptr<KeyAlgorithm> buildAlgorithm() const final;
+    std::unique_ptr<CryptoKeyData> exportData() const final;
 
     PlatformRSAKey m_platformKey;
 
@@ -84,5 +119,9 @@ private:
 
 SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyRSA, CryptoKeyClass::RSA)
 
+SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(RsaKeyAlgorithm, KeyAlgorithmClass::RSA)
+
+SPECIALIZE_TYPE_TRAITS_KEY_ALGORITHM(RsaHashedKeyAlgorithm, KeyAlgorithmClass::HRSA)
+
 #endif // ENABLE(SUBTLE_CRYPTO)
 #endif // CryptoKeyRSA_h
index 140c9b3..d4df6ca 100644 (file)
@@ -29,7 +29,6 @@
 #if ENABLE(SUBTLE_CRYPTO)
 
 #include "CommonCryptoUtilities.h"
-#include "CryptoAlgorithmDescriptionBuilder.h"
 #include "CryptoAlgorithmRegistry.h"
 #include "CryptoKeyDataRSAComponents.h"
 #include "CryptoKeyPair.h"
@@ -160,26 +159,22 @@ size_t CryptoKeyRSA::keySizeInBits() const
     return modulus.size() * 8;
 }
 
-void CryptoKeyRSA::buildAlgorithmDescription(CryptoAlgorithmDescriptionBuilder& builder) const
+std::unique_ptr<KeyAlgorithm> CryptoKeyRSA::buildAlgorithm() const
 {
-    CryptoKey::buildAlgorithmDescription(builder);
-
+    String name = CryptoAlgorithmRegistry::singleton().nameForIdentifier(algorithmIdentifier());
     Vector<uint8_t> modulus;
     Vector<uint8_t> publicExponent;
     CCCryptorStatus status = getPublicKeyComponents(m_platformKey, modulus, publicExponent);
     if (status) {
         WTFLogAlways("Couldn't get RSA key components, status %d", status);
-        return;
+        publicExponent.clear();
+        return std::make_unique<RsaKeyAlgorithm>(name, 0, WTFMove(publicExponent));
     }
 
-    builder.add("modulusLength", modulus.size() * 8);
-    builder.add("publicExponent", publicExponent);
-
-    if (m_restrictedToSpecificHash) {
-        auto hashDescriptionBuilder = builder.createEmptyClone();
-        hashDescriptionBuilder->add("name", CryptoAlgorithmRegistry::singleton().nameForIdentifier(m_hash));
-        builder.add("hash", *hashDescriptionBuilder);
-    }
+    size_t modulusLength = modulus.size() * 8;
+    if (m_restrictedToSpecificHash)
+        return std::make_unique<RsaHashedKeyAlgorithm>(name, modulusLength, WTFMove(publicExponent), CryptoAlgorithmRegistry::singleton().nameForIdentifier(m_hash));
+    return std::make_unique<RsaKeyAlgorithm>(name, modulusLength, WTFMove(publicExponent));
 }
 
 std::unique_ptr<CryptoKeyData> CryptoKeyRSA::exportData() const