Title: [174358] trunk/Source/WebCore
Revision
174358
Author
[email protected]
Date
2014-10-06 12:20:19 -0700 (Mon, 06 Oct 2014)

Log Message

Use is<>() / downcast<>() for CryptoKey subclasses
https://bugs.webkit.org/show_bug.cgi?id=137436

Reviewed by Ryosuke Niwa.

Use is<>() / downcast<>() for CryptoKey subclasses.

No new tests, no behavior change.

* bindings/js/JSCryptoKeySerializationJWK.cpp:
(WebCore::addJWKAlgorithmToJSON):
* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneSerializer::write):
* crypto/CryptoKey.h:
* crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
(WebCore::CryptoAlgorithmAES_CBC::keyAlgorithmMatches):
(WebCore::CryptoAlgorithmAES_CBC::encrypt):
(WebCore::CryptoAlgorithmAES_CBC::decrypt):
* crypto/algorithms/CryptoAlgorithmAES_KW.cpp:
(WebCore::CryptoAlgorithmAES_KW::keyAlgorithmMatches):
(WebCore::CryptoAlgorithmAES_KW::encryptForWrapKey):
(WebCore::CryptoAlgorithmAES_KW::decryptForUnwrapKey):
* crypto/algorithms/CryptoAlgorithmHMAC.cpp:
(WebCore::CryptoAlgorithmHMAC::keyAlgorithmMatches):
(WebCore::CryptoAlgorithmHMAC::sign):
(WebCore::CryptoAlgorithmHMAC::verify):
* crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::keyAlgorithmMatches):
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::encrypt):
(WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt):
* crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::keyAlgorithmMatches):
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
(WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify):
* crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
(WebCore::CryptoAlgorithmRSA_OAEP::keyAlgorithmMatches):
(WebCore::CryptoAlgorithmRSA_OAEP::encrypt):
(WebCore::CryptoAlgorithmRSA_OAEP::decrypt):
* crypto/keys/CryptoKeyAES.h:
(WebCore::isCryptoKeyAES): Deleted.
* crypto/keys/CryptoKeyHMAC.h:
(WebCore::isCryptoKeyHMAC): Deleted.
* crypto/keys/CryptoKeyRSA.h:
(WebCore::isCryptoKeyRSA): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (174357 => 174358)


--- trunk/Source/WebCore/ChangeLog	2014-10-06 19:09:55 UTC (rev 174357)
+++ trunk/Source/WebCore/ChangeLog	2014-10-06 19:20:19 UTC (rev 174358)
@@ -1,3 +1,50 @@
+2014-10-06  Christophe Dumez  <[email protected]>
+
+        Use is<>() / downcast<>() for CryptoKey subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=137436
+
+        Reviewed by Ryosuke Niwa.
+
+        Use is<>() / downcast<>() for CryptoKey subclasses.
+
+        No new tests, no behavior change.
+
+        * bindings/js/JSCryptoKeySerializationJWK.cpp:
+        (WebCore::addJWKAlgorithmToJSON):
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::CloneSerializer::write):
+        * crypto/CryptoKey.h:
+        * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:
+        (WebCore::CryptoAlgorithmAES_CBC::keyAlgorithmMatches):
+        (WebCore::CryptoAlgorithmAES_CBC::encrypt):
+        (WebCore::CryptoAlgorithmAES_CBC::decrypt):
+        * crypto/algorithms/CryptoAlgorithmAES_KW.cpp:
+        (WebCore::CryptoAlgorithmAES_KW::keyAlgorithmMatches):
+        (WebCore::CryptoAlgorithmAES_KW::encryptForWrapKey):
+        (WebCore::CryptoAlgorithmAES_KW::decryptForUnwrapKey):
+        * crypto/algorithms/CryptoAlgorithmHMAC.cpp:
+        (WebCore::CryptoAlgorithmHMAC::keyAlgorithmMatches):
+        (WebCore::CryptoAlgorithmHMAC::sign):
+        (WebCore::CryptoAlgorithmHMAC::verify):
+        * crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp:
+        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::keyAlgorithmMatches):
+        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::encrypt):
+        (WebCore::CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt):
+        * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::keyAlgorithmMatches):
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign):
+        (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify):
+        * crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp:
+        (WebCore::CryptoAlgorithmRSA_OAEP::keyAlgorithmMatches):
+        (WebCore::CryptoAlgorithmRSA_OAEP::encrypt):
+        (WebCore::CryptoAlgorithmRSA_OAEP::decrypt):
+        * crypto/keys/CryptoKeyAES.h:
+        (WebCore::isCryptoKeyAES): Deleted.
+        * crypto/keys/CryptoKeyHMAC.h:
+        (WebCore::isCryptoKeyHMAC): Deleted.
+        * crypto/keys/CryptoKeyRSA.h:
+        (WebCore::isCryptoKeyRSA): Deleted.
+
 2014-10-06  Simon Fraser  <[email protected]>
 
         Some compositing logic cleanup

Modified: trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp (174357 => 174358)


--- trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp	2014-10-06 19:09:55 UTC (rev 174357)
+++ trunk/Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp	2014-10-06 19:20:19 UTC (rev 174358)
@@ -556,17 +556,17 @@
     String jwkAlgorithm;
     switch (key.algorithmIdentifier()) {
     case CryptoAlgorithmIdentifier::HMAC:
-        switch (toCryptoKeyHMAC(key).hashAlgorithmIdentifier()) {
+        switch (downcast<CryptoKeyHMAC>(key).hashAlgorithmIdentifier()) {
         case CryptoAlgorithmIdentifier::SHA_256:
-            if (toCryptoKeyHMAC(key).key().size() * 8 >= 256)
+            if (downcast<CryptoKeyHMAC>(key).key().size() * 8 >= 256)
                 jwkAlgorithm = "HS256";
             break;
         case CryptoAlgorithmIdentifier::SHA_384:
-            if (toCryptoKeyHMAC(key).key().size() * 8 >= 384)
+            if (downcast<CryptoKeyHMAC>(key).key().size() * 8 >= 384)
                 jwkAlgorithm = "HS384";
             break;
         case CryptoAlgorithmIdentifier::SHA_512:
-            if (toCryptoKeyHMAC(key).key().size() * 8 >= 512)
+            if (downcast<CryptoKeyHMAC>(key).key().size() * 8 >= 512)
                 jwkAlgorithm = "HS512";
             break;
         default:
@@ -574,7 +574,7 @@
         }
         break;
     case CryptoAlgorithmIdentifier::AES_CBC:
-        switch (toCryptoKeyAES(key).key().size() * 8) {
+        switch (downcast<CryptoKeyAES>(key).key().size() * 8) {
         case 128:
             jwkAlgorithm = "A128CBC";
             break;
@@ -587,7 +587,7 @@
         }
         break;
     case CryptoAlgorithmIdentifier::AES_KW:
-        switch (toCryptoKeyAES(key).key().size() * 8) {
+        switch (downcast<CryptoKeyAES>(key).key().size() * 8) {
         case 128:
             jwkAlgorithm = "A128KW";
             break;
@@ -600,7 +600,7 @@
         }
         break;
     case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5: {
-        const CryptoKeyRSA& rsaKey = toCryptoKeyRSA(key);
+        const CryptoKeyRSA& rsaKey = downcast<CryptoKeyRSA>(key);
         CryptoAlgorithmIdentifier hash;
         if (!rsaKey.isRestrictedToHash(hash))
             break;
@@ -622,14 +622,14 @@
         break;
     }
     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5: {
-        const CryptoKeyRSA& rsaKey = toCryptoKeyRSA(key);
+        const CryptoKeyRSA& rsaKey = downcast<CryptoKeyRSA>(key);
         if (rsaKey.keySizeInBits() < 2048)
             break;
         jwkAlgorithm = "RSA1_5";
         break;
     }
     case CryptoAlgorithmIdentifier::RSA_OAEP: {
-        const CryptoKeyRSA& rsaKey = toCryptoKeyRSA(key);
+        const CryptoKeyRSA& rsaKey = downcast<CryptoKeyRSA>(key);
         CryptoAlgorithmIdentifier hash;
         // WebCrypto RSA-OAEP keys are not tied to any particular hash, unless previously imported from JWK, which only supports SHA-1.
         if (rsaKey.isRestrictedToHash(hash) && hash != CryptoAlgorithmIdentifier::SHA_1)

Modified: trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp (174357 => 174358)


--- trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp	2014-10-06 19:09:55 UTC (rev 174357)
+++ trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp	2014-10-06 19:20:19 UTC (rev 174358)
@@ -1173,19 +1173,19 @@
         switch (key->keyClass()) {
         case CryptoKeyClass::HMAC:
             write(CryptoKeyClassSubtag::HMAC);
-            write(toCryptoKeyHMAC(key)->key());
-            write(toCryptoKeyHMAC(key)->hashAlgorithmIdentifier());
+            write(downcast<CryptoKeyHMAC>(*key).key());
+            write(downcast<CryptoKeyHMAC>(*key).hashAlgorithmIdentifier());
             break;
         case CryptoKeyClass::AES:
             write(CryptoKeyClassSubtag::AES);
             write(key->algorithmIdentifier());
-            write(toCryptoKeyAES(key)->key());
+            write(downcast<CryptoKeyAES>(*key).key());
             break;
         case CryptoKeyClass::RSA:
             write(CryptoKeyClassSubtag::RSA);
             write(key->algorithmIdentifier());
             CryptoAlgorithmIdentifier hash;
-            bool isRestrictedToHash = toCryptoKeyRSA(key)->isRestrictedToHash(hash);
+            bool isRestrictedToHash = downcast<CryptoKeyRSA>(*key).isRestrictedToHash(hash);
             write(isRestrictedToHash);
             if (isRestrictedToHash)
                 write(hash);

Modified: trunk/Source/WebCore/crypto/CryptoKey.h (174357 => 174358)


--- trunk/Source/WebCore/crypto/CryptoKey.h	2014-10-06 19:09:55 UTC (rev 174357)
+++ trunk/Source/WebCore/crypto/CryptoKey.h	2014-10-06 19:20:19 UTC (rev 174358)
@@ -26,15 +26,16 @@
 #ifndef CryptoKey_h
 #define CryptoKey_h
 
+#if ENABLE(SUBTLE_CRYPTO)
+
 #include "CryptoAlgorithmIdentifier.h"
 #include "CryptoKeyType.h"
 #include "CryptoKeyUsage.h"
 #include <wtf/Forward.h>
 #include <wtf/RefCounted.h>
+#include <wtf/TypeCasts.h>
 #include <wtf/Vector.h>
 
-#if ENABLE(SUBTLE_CRYPTO)
-
 namespace WebCore {
 
 class CryptoAlgorithmDescriptionBuilder;
@@ -73,10 +74,12 @@
     CryptoKeyUsage m_usages;
 };
 
-#define CRYPTO_KEY_TYPE_CASTS(ToClassName) \
-    TYPE_CASTS_BASE(ToClassName, CryptoKey, key, WebCore::is##ToClassName(*key), WebCore::is##ToClassName(key))
-
 } // namespace WebCore
 
+#define SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(ToClassName, KeyClass) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToClassName) \
+    static bool isType(const WebCore::CryptoKey& key) { return key.keyClass() == WebCore::KeyClass; } \
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // ENABLE(SUBTLE_CRYPTO)
 #endif // CryptoKey_h

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp (174357 => 174358)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp	2014-10-06 19:09:55 UTC (rev 174357)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp	2014-10-06 19:20:19 UTC (rev 174358)
@@ -60,7 +60,7 @@
 {
     if (key.algorithmIdentifier() != s_identifier)
         return false;
-    ASSERT(isCryptoKeyAES(key));
+    ASSERT(is<CryptoKeyAES>(key));
 
     return true;
 }
@@ -74,7 +74,7 @@
         return;
     }
 
-    platformEncrypt(aesCBCParameters, toCryptoKeyAES(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
+    platformEncrypt(aesCBCParameters, downcast<CryptoKeyAES>(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
 }
 
 void CryptoAlgorithmAES_CBC::decrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec)
@@ -86,7 +86,7 @@
         return;
     }
 
-    platformDecrypt(aesCBCParameters, toCryptoKeyAES(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
+    platformDecrypt(aesCBCParameters, downcast<CryptoKeyAES>(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
 }
 
 void CryptoAlgorithmAES_CBC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, KeyOrKeyPairCallback callback, VoidCallback failureCallback, ExceptionCode&)

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.cpp (174357 => 174358)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.cpp	2014-10-06 19:09:55 UTC (rev 174357)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.cpp	2014-10-06 19:20:19 UTC (rev 174358)
@@ -59,7 +59,7 @@
 {
     if (key.algorithmIdentifier() != s_identifier)
         return false;
-    ASSERT(isCryptoKeyAES(key));
+    ASSERT(is<CryptoKeyAES>(key));
 
     return true;
 }
@@ -71,7 +71,7 @@
         return;
     }
 
-    platformEncrypt(toCryptoKeyAES(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
+    platformEncrypt(downcast<CryptoKeyAES>(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
 }
 
 void CryptoAlgorithmAES_KW::decryptForUnwrapKey(const CryptoAlgorithmParameters&, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec)
@@ -81,7 +81,7 @@
         return;
     }
 
-    platformDecrypt(toCryptoKeyAES(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
+    platformDecrypt(downcast<CryptoKeyAES>(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
 }
 
 void CryptoAlgorithmAES_KW::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, KeyOrKeyPairCallback callback, VoidCallback failureCallback, ExceptionCode&)

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp (174357 => 174358)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp	2014-10-06 19:09:55 UTC (rev 174357)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp	2014-10-06 19:20:19 UTC (rev 174358)
@@ -60,9 +60,8 @@
 {
     if (key.algorithmIdentifier() != s_identifier)
         return false;
-    ASSERT(isCryptoKeyHMAC(key));
 
-    if (toCryptoKeyHMAC(key).hashAlgorithmIdentifier() != parameters.hash)
+    if (downcast<CryptoKeyHMAC>(key).hashAlgorithmIdentifier() != parameters.hash)
         return false;
 
     return true;
@@ -77,7 +76,7 @@
         return;
     }
 
-    platformSign(hmacParameters, toCryptoKeyHMAC(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
+    platformSign(hmacParameters, downcast<CryptoKeyHMAC>(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
 }
 
 void CryptoAlgorithmHMAC::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& expectedSignature, const CryptoOperationData& data, BoolCallback callback, VoidCallback failureCallback, ExceptionCode& ec)
@@ -89,7 +88,7 @@
         return;
     }
 
-    platformVerify(hmacParameters, toCryptoKeyHMAC(key), expectedSignature, data, WTF::move(callback), WTF::move(failureCallback), ec);
+    platformVerify(hmacParameters, downcast<CryptoKeyHMAC>(key), expectedSignature, data, WTF::move(callback), WTF::move(failureCallback), ec);
 }
 
 void CryptoAlgorithmHMAC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, KeyOrKeyPairCallback callback, VoidCallback failureCallback, ExceptionCode&)

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp (174357 => 174358)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp	2014-10-06 19:09:55 UTC (rev 174357)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp	2014-10-06 19:20:19 UTC (rev 174358)
@@ -59,7 +59,7 @@
 {
     if (key.algorithmIdentifier() != s_identifier)
         return false;
-    ASSERT(isCryptoKeyRSA(key));
+    ASSERT(is<CryptoKeyRSA>(key));
 
     return true;
 }
@@ -71,7 +71,7 @@
         return;
     }
 
-    platformEncrypt(toCryptoKeyRSA(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
+    platformEncrypt(downcast<CryptoKeyRSA>(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
 }
 
 void CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt(const CryptoAlgorithmParameters&, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec)
@@ -81,7 +81,7 @@
         return;
     }
 
-    platformDecrypt(toCryptoKeyRSA(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
+    platformDecrypt(downcast<CryptoKeyRSA>(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
 }
 
 void CryptoAlgorithmRSAES_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, KeyOrKeyPairCallback callback, VoidCallback failureCallback, ExceptionCode&)

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp (174357 => 174358)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp	2014-10-06 19:09:55 UTC (rev 174357)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp	2014-10-06 19:20:19 UTC (rev 174358)
@@ -61,10 +61,9 @@
 {
     if (key.algorithmIdentifier() != s_identifier)
         return false;
-    ASSERT(isCryptoKeyRSA(key));
 
     CryptoAlgorithmIdentifier keyHash;
-    if (toCryptoKeyRSA(key).isRestrictedToHash(keyHash) && keyHash != algorithmParameters.hash)
+    if (downcast<CryptoKeyRSA>(key).isRestrictedToHash(keyHash) && keyHash != algorithmParameters.hash)
         return false;
 
     return true;
@@ -79,7 +78,7 @@
         return;
     }
 
-    platformSign(rsaSSAParameters, toCryptoKeyRSA(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
+    platformSign(rsaSSAParameters, downcast<CryptoKeyRSA>(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
 }
 
 void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& signature, const CryptoOperationData& data, BoolCallback callback, VoidCallback failureCallback, ExceptionCode& ec)
@@ -91,7 +90,7 @@
         return;
     }
 
-    platformVerify(rsaSSAParameters, toCryptoKeyRSA(key), signature, data, WTF::move(callback), WTF::move(failureCallback), ec);
+    platformVerify(rsaSSAParameters,  downcast<CryptoKeyRSA>(key), signature, data, WTF::move(callback), WTF::move(failureCallback), ec);
 }
 
 void CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, KeyOrKeyPairCallback callback, VoidCallback failureCallback, ExceptionCode&)

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp (174357 => 174358)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp	2014-10-06 19:09:55 UTC (rev 174357)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp	2014-10-06 19:20:19 UTC (rev 174358)
@@ -61,10 +61,9 @@
 {
     if (key.algorithmIdentifier() != s_identifier)
         return false;
-    ASSERT(isCryptoKeyRSA(key));
 
     CryptoAlgorithmIdentifier keyHash;
-    if (toCryptoKeyRSA(key).isRestrictedToHash(keyHash) && keyHash != algorithmParameters.hash)
+    if (downcast<CryptoKeyRSA>(key).isRestrictedToHash(keyHash) && keyHash != algorithmParameters.hash)
         return false;
 
     return true;
@@ -79,7 +78,7 @@
         return;
     }
 
-    platformEncrypt(rsaOAEPParameters, toCryptoKeyRSA(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
+    platformEncrypt(rsaOAEPParameters, downcast<CryptoKeyRSA>(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
 }
 
 void CryptoAlgorithmRSA_OAEP::decrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec)
@@ -91,7 +90,7 @@
         return;
     }
 
-    platformDecrypt(rsaOAEPParameters, toCryptoKeyRSA(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
+    platformDecrypt(rsaOAEPParameters, downcast<CryptoKeyRSA>(key), data, WTF::move(callback), WTF::move(failureCallback), ec);
 }
 
 void CryptoAlgorithmRSA_OAEP::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, KeyOrKeyPairCallback callback, VoidCallback failureCallback, ExceptionCode&)

Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h (174357 => 174358)


--- trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h	2014-10-06 19:09:55 UTC (rev 174357)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyAES.h	2014-10-06 19:20:19 UTC (rev 174358)
@@ -59,16 +59,10 @@
     Vector<uint8_t> m_key;
 };
 
-inline bool isCryptoKeyAES(const CryptoKey& key)
-{
-    return key.keyClass() == CryptoKeyClass::AES;
-}
-
-CRYPTO_KEY_TYPE_CASTS(CryptoKeyAES)
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyAES, CryptoKeyClass::AES)
+
 #endif // ENABLE(SUBTLE_CRYPTO)
 
-
 #endif // CryptoKeyAES_h

Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h (174357 => 174358)


--- trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h	2014-10-06 19:09:55 UTC (rev 174357)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyHMAC.h	2014-10-06 19:20:19 UTC (rev 174358)
@@ -60,14 +60,9 @@
     Vector<uint8_t> m_key;
 };
 
-inline bool isCryptoKeyHMAC(const CryptoKey& key)
-{
-    return key.keyClass() == CryptoKeyClass::HMAC;
-}
-
-CRYPTO_KEY_TYPE_CASTS(CryptoKeyHMAC)
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyHMAC, CryptoKeyClass::HMAC)
+
 #endif // ENABLE(SUBTLE_CRYPTO)
 #endif // CryptoKeyHMAC_h

Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h (174357 => 174358)


--- trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h	2014-10-06 19:09:55 UTC (rev 174357)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h	2014-10-06 19:20:19 UTC (rev 174358)
@@ -81,14 +81,9 @@
     CryptoAlgorithmIdentifier m_hash;
 };
 
-inline bool isCryptoKeyRSA(const CryptoKey& key)
-{
-    return key.keyClass() == CryptoKeyClass::RSA;
-}
-
-CRYPTO_KEY_TYPE_CASTS(CryptoKeyRSA)
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyRSA, CryptoKeyClass::RSA)
+
 #endif // ENABLE(SUBTLE_CRYPTO)
 #endif // CryptoKeyRSA_h
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to