Use is<>() / downcast<>() for CryptoKey subclasses
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Oct 2014 19:20:19 +0000 (19:20 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Oct 2014 19:20:19 +0000 (19:20 +0000)
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.

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

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSCryptoKeySerializationJWK.cpp
Source/WebCore/bindings/js/SerializedScriptValue.cpp
Source/WebCore/crypto/CryptoKey.h
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_KW.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSA_OAEP.cpp
Source/WebCore/crypto/keys/CryptoKeyAES.h
Source/WebCore/crypto/keys/CryptoKeyHMAC.h
Source/WebCore/crypto/keys/CryptoKeyRSA.h

index 953a30f..c32fbb6 100644 (file)
@@ -1,3 +1,50 @@
+2014-10-06  Christophe Dumez  <cdumez@apple.com>
+
+        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  <simon.fraser@apple.com>
 
         Some compositing logic cleanup
index 2747fb8..02fa1c0 100644 (file)
@@ -556,17 +556,17 @@ static void addJWKAlgorithmToJSON(ExecState* exec, JSObject* json, const CryptoK
     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 @@ static void addJWKAlgorithmToJSON(ExecState* exec, JSObject* json, const CryptoK
         }
         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 @@ static void addJWKAlgorithmToJSON(ExecState* exec, JSObject* json, const CryptoK
         }
         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 @@ static void addJWKAlgorithmToJSON(ExecState* exec, JSObject* json, const CryptoK
         }
         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 @@ static void addJWKAlgorithmToJSON(ExecState* exec, JSObject* json, const CryptoK
         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)
index a549a4c..97b82ec 100644 (file)
@@ -1173,19 +1173,19 @@ private:
         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);
index 3a1be69..7df9e1a 100644 (file)
 #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 @@ private:
     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
index 9fea3b8..41e0441 100644 (file)
@@ -60,7 +60,7 @@ bool CryptoAlgorithmAES_CBC::keyAlgorithmMatches(const CryptoAlgorithmAesCbcPara
 {
     if (key.algorithmIdentifier() != s_identifier)
         return false;
-    ASSERT(isCryptoKeyAES(key));
+    ASSERT(is<CryptoKeyAES>(key));
 
     return true;
 }
@@ -74,7 +74,7 @@ void CryptoAlgorithmAES_CBC::encrypt(const CryptoAlgorithmParameters& parameters
         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 @@ void CryptoAlgorithmAES_CBC::decrypt(const CryptoAlgorithmParameters& parameters
         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&)
index 87d99d6..e997aed 100644 (file)
@@ -59,7 +59,7 @@ bool CryptoAlgorithmAES_KW::keyAlgorithmMatches(const CryptoKey& key) const
 {
     if (key.algorithmIdentifier() != s_identifier)
         return false;
-    ASSERT(isCryptoKeyAES(key));
+    ASSERT(is<CryptoKeyAES>(key));
 
     return true;
 }
@@ -71,7 +71,7 @@ void CryptoAlgorithmAES_KW::encryptForWrapKey(const CryptoAlgorithmParameters&,
         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 @@ void CryptoAlgorithmAES_KW::decryptForUnwrapKey(const CryptoAlgorithmParameters&
         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&)
index 4cf3cda..c5fce49 100644 (file)
@@ -60,9 +60,8 @@ bool CryptoAlgorithmHMAC::keyAlgorithmMatches(const CryptoAlgorithmHmacParams& p
 {
     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 @@ void CryptoAlgorithmHMAC::sign(const CryptoAlgorithmParameters& parameters, cons
         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 @@ void CryptoAlgorithmHMAC::verify(const CryptoAlgorithmParameters& parameters, co
         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&)
index 6a2dd63..e5da7a0 100644 (file)
@@ -59,7 +59,7 @@ bool CryptoAlgorithmRSAES_PKCS1_v1_5::keyAlgorithmMatches(const CryptoKey& key)
 {
     if (key.algorithmIdentifier() != s_identifier)
         return false;
-    ASSERT(isCryptoKeyRSA(key));
+    ASSERT(is<CryptoKeyRSA>(key));
 
     return true;
 }
@@ -71,7 +71,7 @@ void CryptoAlgorithmRSAES_PKCS1_v1_5::encrypt(const CryptoAlgorithmParameters&,
         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 @@ void CryptoAlgorithmRSAES_PKCS1_v1_5::decrypt(const CryptoAlgorithmParameters&,
         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&)
index c9fd1b4..0a477ff 100644 (file)
@@ -61,10 +61,9 @@ bool CryptoAlgorithmRSASSA_PKCS1_v1_5::keyAlgorithmMatches(const CryptoAlgorithm
 {
     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 @@ void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(const CryptoAlgorithmParameters& par
         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 @@ void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(const CryptoAlgorithmParameters& p
         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&)
index 343bd4c..22176fb 100644 (file)
@@ -61,10 +61,9 @@ bool CryptoAlgorithmRSA_OAEP::keyAlgorithmMatches(const CryptoAlgorithmRsaOaepPa
 {
     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 @@ void CryptoAlgorithmRSA_OAEP::encrypt(const CryptoAlgorithmParameters& parameter
         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 @@ void CryptoAlgorithmRSA_OAEP::decrypt(const CryptoAlgorithmParameters& parameter
         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&)
index 4e0d5f7..0b7bb61 100644 (file)
@@ -59,16 +59,10 @@ private:
     Vector<uint8_t> m_key;
 };
 
-inline bool isCryptoKeyAES(const CryptoKey& key)
-{
-    return key.keyClass() == CryptoKeyClass::AES;
-}
-
-CRYPTO_KEY_TYPE_CASTS(CryptoKeyAES)
-
 } // namespace WebCore
 
-#endif // ENABLE(SUBTLE_CRYPTO)
+SPECIALIZE_TYPE_TRAITS_CRYPTO_KEY(CryptoKeyAES, CryptoKeyClass::AES)
 
+#endif // ENABLE(SUBTLE_CRYPTO)
 
 #endif // CryptoKeyAES_h
index 6e5b359..b783c66 100644 (file)
@@ -60,14 +60,9 @@ private:
     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
index 1c5e7bd..51dd3f6 100644 (file)
@@ -81,14 +81,9 @@ private:
     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