Title: [221293] trunk/Source/WebCore
Revision
221293
Author
zandober...@gmail.com
Date
2017-08-29 04:29:56 -0700 (Tue, 29 Aug 2017)

Log Message

[WebCrypto] Push WorkQueue dispatches for EC algorithms into shared code
https://bugs.webkit.org/show_bug.cgi?id=175619

Reviewed by Jiewen Tan.

Push the WorkQueue dispatch code duplicated between the Mac and libgcrypt
implementations of Web Crypto into the shared layer. This patch focuses on
the EC-based algorithms.

Functions with platform-specific implementations that are invoked from
these asynchronous dispatches are made static and return an ExceptionOr or
std::optional value. CryptoKey and CryptoAlgorithmParameters objects are
passed to those through const references. Input data is passed through
const references to the original Vector objects.

No new tests -- no changes in behavior that's covered by existing tests.

* crypto/algorithms/CryptoAlgorithmECDH.cpp:
(WebCore::CryptoAlgorithmECDH::deriveBits):
* crypto/algorithms/CryptoAlgorithmECDH.h:
* crypto/algorithms/CryptoAlgorithmECDSA.cpp:
(WebCore::CryptoAlgorithmECDSA::sign):
(WebCore::CryptoAlgorithmECDSA::verify):
* crypto/algorithms/CryptoAlgorithmECDSA.h:
* crypto/gcrypt/CryptoAlgorithmECDHGCrypt.cpp:
(WebCore::CryptoAlgorithmECDH::platformDeriveBits):
* crypto/gcrypt/CryptoAlgorithmECDSAGCrypt.cpp:
(WebCore::CryptoAlgorithmECDSA::platformSign):
(WebCore::CryptoAlgorithmECDSA::platformVerify):
* crypto/keys/CryptoKeyEC.h:
* crypto/mac/CryptoAlgorithmECDHMac.cpp:
(WebCore::CryptoAlgorithmECDH::platformDeriveBits):
* crypto/mac/CryptoAlgorithmECDSAMac.cpp:
(WebCore::CryptoAlgorithmECDSA::platformSign):
(WebCore::CryptoAlgorithmECDSA::platformVerify):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (221292 => 221293)


--- trunk/Source/WebCore/ChangeLog	2017-08-29 09:32:34 UTC (rev 221292)
+++ trunk/Source/WebCore/ChangeLog	2017-08-29 11:29:56 UTC (rev 221293)
@@ -1,3 +1,41 @@
+2017-08-29  Zan Dobersek  <zdober...@igalia.com>
+
+        [WebCrypto] Push WorkQueue dispatches for EC algorithms into shared code
+        https://bugs.webkit.org/show_bug.cgi?id=175619
+
+        Reviewed by Jiewen Tan.
+
+        Push the WorkQueue dispatch code duplicated between the Mac and libgcrypt
+        implementations of Web Crypto into the shared layer. This patch focuses on
+        the EC-based algorithms.
+
+        Functions with platform-specific implementations that are invoked from
+        these asynchronous dispatches are made static and return an ExceptionOr or
+        std::optional value. CryptoKey and CryptoAlgorithmParameters objects are
+        passed to those through const references. Input data is passed through
+        const references to the original Vector objects.
+
+        No new tests -- no changes in behavior that's covered by existing tests.
+
+        * crypto/algorithms/CryptoAlgorithmECDH.cpp:
+        (WebCore::CryptoAlgorithmECDH::deriveBits):
+        * crypto/algorithms/CryptoAlgorithmECDH.h:
+        * crypto/algorithms/CryptoAlgorithmECDSA.cpp:
+        (WebCore::CryptoAlgorithmECDSA::sign):
+        (WebCore::CryptoAlgorithmECDSA::verify):
+        * crypto/algorithms/CryptoAlgorithmECDSA.h:
+        * crypto/gcrypt/CryptoAlgorithmECDHGCrypt.cpp:
+        (WebCore::CryptoAlgorithmECDH::platformDeriveBits):
+        * crypto/gcrypt/CryptoAlgorithmECDSAGCrypt.cpp:
+        (WebCore::CryptoAlgorithmECDSA::platformSign):
+        (WebCore::CryptoAlgorithmECDSA::platformVerify):
+        * crypto/keys/CryptoKeyEC.h:
+        * crypto/mac/CryptoAlgorithmECDHMac.cpp:
+        (WebCore::CryptoAlgorithmECDH::platformDeriveBits):
+        * crypto/mac/CryptoAlgorithmECDSAMac.cpp:
+        (WebCore::CryptoAlgorithmECDSA::platformSign):
+        (WebCore::CryptoAlgorithmECDSA::platformVerify):
+
 2017-08-19  Sergio Villar Senin  <svil...@igalia.com>
 
         [SVG] Leak in SVGAnimatedListPropertyTearOff

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.cpp (221292 => 221293)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.cpp	2017-08-29 09:32:34 UTC (rev 221292)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.cpp	2017-08-29 11:29:56 UTC (rev 221293)
@@ -31,6 +31,7 @@
 #include "CryptoAlgorithmEcKeyParams.h"
 #include "CryptoAlgorithmEcdhKeyDeriveParams.h"
 #include "CryptoKeyEC.h"
+#include "ScriptExecutionContext.h"
 
 namespace WebCore {
 
@@ -112,7 +113,19 @@
         (*derivedKey).shrink(length / 8);
         callback(WTFMove(*derivedKey));
     };
-    platformDeriveBits(WTFMove(baseKey), ecParameters.publicKey.releaseNonNull(), length, WTFMove(unifiedCallback), context, workQueue);
+
+    // This is a special case that can't use dispatchOperation() because it bundles
+    // the result validation and callback dispatch into unifiedCallback.
+    context.ref();
+    workQueue.dispatch(
+        [baseKey = WTFMove(baseKey), publicKey = ecParameters.publicKey.releaseNonNull(), length, unifiedCallback = WTFMove(unifiedCallback), &context]() mutable {
+            auto derivedKey = platformDeriveBits(baseKey, publicKey);
+            context.postTask(
+                [derivedKey = WTFMove(derivedKey), length, unifiedCallback = WTFMove(unifiedCallback)](ScriptExecutionContext& context) mutable {
+                    unifiedCallback(WTFMove(derivedKey), length);
+                    context.deref();
+                });
+        });
 }
 
 void CryptoAlgorithmECDH::importKey(CryptoKeyFormat format, KeyData&& data, const std::unique_ptr<CryptoAlgorithmParameters>&& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyCallback&& callback, ExceptionCallback&& exceptionCallback)

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.h (221292 => 221293)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.h	2017-08-29 09:32:34 UTC (rev 221292)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDH.h	2017-08-29 11:29:56 UTC (rev 221293)
@@ -46,8 +46,7 @@
     void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
 
-    using Callback = Function<void(std::optional<Vector<uint8_t>>&&, size_t)>;
-    void platformDeriveBits(Ref<CryptoKey>&& baseKey, Ref<CryptoKey>&& publicKey, size_t length, Callback&&, ScriptExecutionContext&, WorkQueue&);
+    static std::optional<Vector<uint8_t>> platformDeriveBits(const CryptoKey&, const CryptoKey&);
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDSA.cpp (221292 => 221293)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDSA.cpp	2017-08-29 09:32:34 UTC (rev 221292)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDSA.cpp	2017-08-29 11:29:56 UTC (rev 221293)
@@ -54,7 +54,11 @@
         exceptionCallback(InvalidAccessError);
         return;
     }
-    platformSign(WTFMove(parameters), WTFMove(key), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+
+    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = WTFMove(parameters), key = WTFMove(key), data = "" {
+            return platformSign(*parameters, key, data);
+        });
 }
 
 void CryptoAlgorithmECDSA::verify(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
@@ -63,7 +67,11 @@
         exceptionCallback(InvalidAccessError);
         return;
     }
-    platformVerify(WTFMove(parameters), WTFMove(key), WTFMove(signature), WTFMove(data), WTFMove(callback), WTFMove(exceptionCallback), context, workQueue);
+
+    dispatchOperation(workQueue, context, WTFMove(callback), WTFMove(exceptionCallback),
+        [parameters = WTFMove(parameters), key = WTFMove(key), signature = WTFMove(signature), data = "" {
+            return platformVerify(*parameters, key, signature, data);
+        });
 }
 
 void CryptoAlgorithmECDSA::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsageBitmap usages, KeyOrKeyPairCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext&)

Modified: trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDSA.h (221292 => 221293)


--- trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDSA.h	2017-08-29 09:32:34 UTC (rev 221292)
+++ trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmECDSA.h	2017-08-29 11:29:56 UTC (rev 221293)
@@ -47,8 +47,8 @@
     void importKey(CryptoKeyFormat, KeyData&&, const std::unique_ptr<CryptoAlgorithmParameters>&&, bool extractable, CryptoKeyUsageBitmap, KeyCallback&&, ExceptionCallback&&) final;
     void exportKey(CryptoKeyFormat, Ref<CryptoKey>&&, KeyDataCallback&&, ExceptionCallback&&) final;
 
-    void platformSign(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&&, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
-    void platformVerify(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, Vector<uint8_t>&& signature, Vector<uint8_t>&&, BoolCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&);
+    static ExceptionOr<Vector<uint8_t>> platformSign(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<uint8_t>&);
+    static ExceptionOr<bool> platformVerify(const CryptoAlgorithmParameters&, const CryptoKey&, const Vector<uint8_t>&, const Vector<uint8_t>&);
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmECDHGCrypt.cpp (221292 => 221293)


--- trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmECDHGCrypt.cpp	2017-08-29 09:32:34 UTC (rev 221292)
+++ trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmECDHGCrypt.cpp	2017-08-29 11:29:56 UTC (rev 221293)
@@ -31,7 +31,6 @@
 #if ENABLE(SUBTLE_CRYPTO)
 
 #include "CryptoKeyEC.h"
-#include "ScriptExecutionContext.h"
 #include <pal/crypto/gcrypt/Handle.h>
 #include <pal/crypto/gcrypt/Utilities.h>
 
@@ -116,21 +115,9 @@
     return output;
 }
 
-void CryptoAlgorithmECDH::platformDeriveBits(Ref<CryptoKey>&& baseKey, Ref<CryptoKey>&& publicKey, size_t length, Callback&& callback, ScriptExecutionContext& context, WorkQueue& workQueue)
+std::optional<Vector<uint8_t>> CryptoAlgorithmECDH::platformDeriveBits(const CryptoKey& baseKey, const CryptoKey& publicKey)
 {
-    context.ref();
-    workQueue.dispatch(
-        [baseKey = WTFMove(baseKey), publicKey = WTFMove(publicKey), length, callback = WTFMove(callback), &context]() mutable {
-            auto& ecBaseKey = downcast<CryptoKeyEC>(baseKey.get());
-            auto& ecPublicKey = downcast<CryptoKeyEC>(publicKey.get());
-
-            auto output = gcryptDerive(ecBaseKey.platformKey(), ecPublicKey.platformKey());
-            context.postTask(
-                [output = WTFMove(output), length, callback = WTFMove(callback)](ScriptExecutionContext& context) mutable {
-                    callback(WTFMove(output), length);
-                    context.deref();
-                });
-        });
+    return gcryptDerive(downcast<CryptoKeyEC>(baseKey).platformKey(), downcast<CryptoKeyEC>(publicKey).platformKey());
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmECDSAGCrypt.cpp (221292 => 221293)


--- trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmECDSAGCrypt.cpp	2017-08-29 09:32:34 UTC (rev 221292)
+++ trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmECDSAGCrypt.cpp	2017-08-29 11:29:56 UTC (rev 221293)
@@ -33,7 +33,6 @@
 #include "CryptoAlgorithmEcdsaParams.h"
 #include "CryptoKeyEC.h"
 #include "GCryptUtilities.h"
-#include "ScriptExecutionContext.h"
 #include <pal/crypto/CryptoDigest.h>
 
 namespace WebCore {
@@ -171,60 +170,26 @@
     return { error == GPG_ERR_NO_ERROR };
 }
 
-void CryptoAlgorithmECDSA::platformSign(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmECDSA::platformSign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& data)
 {
-    context.ref();
-    workQueue.dispatch(
-        [parameters = WTFMove(parameters), key = WTFMove(key), data = "" callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
-            auto& ecKey = downcast<CryptoKeyEC>(key.get());
-            auto& ecParameters = downcast<CryptoAlgorithmEcdsaParams>(*parameters);
+    auto& ecParameters = downcast<CryptoAlgorithmEcdsaParams>(parameters);
+    auto& ecKey = downcast<CryptoKeyEC>(key);
 
-            auto output = gcryptSign(ecKey.platformKey(), data, ecParameters.hashIdentifier, ecKey.keySizeInBits() / 8);
-            if (!output) {
-                // We should only dereference callbacks after being back to the Document/Worker threads.
-                context.postTask(
-                    [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
-                        exceptionCallback(OperationError);
-                        context.deref();
-                    });
-                return;
-            }
-
-            // We should only dereference callbacks after being back to the Document/Worker threads.
-            context.postTask(
-                [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
-                    callback(output);
-                    context.deref();
-                });
-        });
+    auto output = gcryptSign(ecKey.platformKey(), data, ecParameters.hashIdentifier, ecKey.keySizeInBits() / 8);
+    if (!output)
+        return Exception { OperationError };
+    return WTFMove(*output);
 }
 
-void CryptoAlgorithmECDSA::platformVerify(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<bool> CryptoAlgorithmECDSA::platformVerify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
 {
-    context.ref();
-    workQueue.dispatch(
-        [parameters = WTFMove(parameters), key = WTFMove(key), signature = WTFMove(signature), data = "" callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
-            auto& ecKey = downcast<CryptoKeyEC>(key.get());
-            auto& ecParameters = downcast<CryptoAlgorithmEcdsaParams>(*parameters);
+    auto& ecParameters = downcast<CryptoAlgorithmEcdsaParams>(parameters);
+    auto& ecKey = downcast<CryptoKeyEC>(key);
 
-            auto output = gcryptVerify(ecKey.platformKey(), signature, data, ecParameters.hashIdentifier, ecKey.keySizeInBits() / 8);
-            if (!output) {
-                // We should only dereference callbacks after being back to the Document/Worker threads.
-                context.postTask(
-                    [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
-                        exceptionCallback(OperationError);
-                        context.deref();
-                    });
-                return;
-            }
-
-            // We should only dereference callbacks after being back to the Document/Worker threads.
-            context.postTask(
-                [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
-                    callback(output);
-                    context.deref();
-                });
-        });
+    auto output = gcryptVerify(ecKey.platformKey(), signature, data, ecParameters.hashIdentifier, ecKey.keySizeInBits() / 8);
+    if (!output)
+        return Exception { OperationError };
+    return WTFMove(*output);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/crypto/keys/CryptoKeyEC.h (221292 => 221293)


--- trunk/Source/WebCore/crypto/keys/CryptoKeyEC.h	2017-08-29 09:32:34 UTC (rev 221292)
+++ trunk/Source/WebCore/crypto/keys/CryptoKeyEC.h	2017-08-29 11:29:56 UTC (rev 221293)
@@ -75,7 +75,7 @@
     size_t keySizeInBits() const;
     NamedCurve namedCurve() const { return m_curve; }
     String namedCurveString() const;
-    PlatformECKey platformKey() { return m_platformKey; }
+    PlatformECKey platformKey() const { return m_platformKey; }
     static bool isValidECAlgorithm(CryptoAlgorithmIdentifier);
 
 private:

Modified: trunk/Source/WebCore/crypto/mac/CryptoAlgorithmECDHMac.cpp (221292 => 221293)


--- trunk/Source/WebCore/crypto/mac/CryptoAlgorithmECDHMac.cpp	2017-08-29 09:32:34 UTC (rev 221292)
+++ trunk/Source/WebCore/crypto/mac/CryptoAlgorithmECDHMac.cpp	2017-08-29 11:29:56 UTC (rev 221293)
@@ -30,28 +30,20 @@
 
 #include "CommonCryptoUtilities.h"
 #include "CryptoKeyEC.h"
-#include "ScriptExecutionContext.h"
 
 namespace WebCore {
 
-void CryptoAlgorithmECDH::platformDeriveBits(Ref<CryptoKey>&& baseKey, Ref<CryptoKey>&& publicKey, size_t length, Callback&& callback, ScriptExecutionContext& context, WorkQueue& workQueue)
+std::optional<Vector<uint8_t>> CryptoAlgorithmECDH::platformDeriveBits(const CryptoKey& baseKey, const CryptoKey& publicKey)
 {
-    context.ref();
-    workQueue.dispatch([baseKey = WTFMove(baseKey), publicKey = WTFMove(publicKey), length, callback = WTFMove(callback), &context]() mutable {
-        auto& ecBaseKey = downcast<CryptoKeyEC>(baseKey.get());
-        auto& ecPublicKey = downcast<CryptoKeyEC>(publicKey.get());
+    auto& ecBaseKey = downcast<CryptoKeyEC>(baseKey);
+    auto& ecPublicKey = downcast<CryptoKeyEC>(publicKey);
 
-        std::optional<Vector<uint8_t>> result = std::nullopt;
-        Vector<uint8_t> derivedKey(ecBaseKey.keySizeInBits() / 8); // Per https://tools.ietf.org/html/rfc6090#section-4.
-        size_t size = derivedKey.size();
-        if (!CCECCryptorComputeSharedSecret(ecBaseKey.platformKey(), ecPublicKey.platformKey(), derivedKey.data(), &size))
-            result = WTFMove(derivedKey);
-
-        context.postTask([result = WTFMove(result), length, callback = WTFMove(callback)](ScriptExecutionContext& context) mutable {
-            callback(WTFMove(result), length);
-            context.deref();
-        });
-    });
+    std::optional<Vector<uint8_t>> result = std::nullopt;
+    Vector<uint8_t> derivedKey(ecBaseKey.keySizeInBits() / 8); // Per https://tools.ietf.org/html/rfc6090#section-4.
+    size_t size = derivedKey.size();
+    if (!CCECCryptorComputeSharedSecret(ecBaseKey.platformKey(), ecPublicKey.platformKey(), derivedKey.data(), &size))
+        result = WTFMove(derivedKey);
+    return result;
 }
 
 }

Modified: trunk/Source/WebCore/crypto/mac/CryptoAlgorithmECDSAMac.cpp (221292 => 221293)


--- trunk/Source/WebCore/crypto/mac/CryptoAlgorithmECDSAMac.cpp	2017-08-29 09:32:34 UTC (rev 221292)
+++ trunk/Source/WebCore/crypto/mac/CryptoAlgorithmECDSAMac.cpp	2017-08-29 11:29:56 UTC (rev 221293)
@@ -33,7 +33,6 @@
 #include "CryptoAlgorithmEcdsaParams.h"
 #include "CryptoDigestAlgorithm.h"
 #include "CryptoKeyEC.h"
-#include "ScriptExecutionContext.h"
 
 namespace WebCore {
 
@@ -152,52 +151,18 @@
     return valid;
 }
 
-void CryptoAlgorithmECDSA::platformSign(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& data, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<Vector<uint8_t>> CryptoAlgorithmECDSA::platformSign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& data)
 {
-    context.ref();
-    workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), data = "" callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
-        auto& ecKey = downcast<CryptoKeyEC>(key.get());
-        auto& ecParameters = downcast<CryptoAlgorithmEcdsaParams>(*parameters);
-
-        auto result = signECDSA(ecParameters.hashIdentifier, ecKey.platformKey(), ecKey.keySizeInBits() / 8, data);
-        if (result.hasException()) {
-            // We should only dereference callbacks after being back to the Document/Worker threads.
-            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
-                exceptionCallback(ec);
-                context.deref();
-            });
-            return;
-        }
-        // We should only dereference callbacks after being back to the Document/Worker threads.
-        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
-            callback(result);
-            context.deref();
-        });
-    });
+    auto& ecKey = downcast<CryptoKeyEC>(key);
+    auto& ecParameters = downcast<CryptoAlgorithmEcdsaParams>(parameters);
+    return signECDSA(ecParameters.hashIdentifier, ecKey.platformKey(), ecKey.keySizeInBits() / 8, data);
 }
 
-void CryptoAlgorithmECDSA::platformVerify(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& signature, Vector<uint8_t>&& data, BoolCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
+ExceptionOr<bool> CryptoAlgorithmECDSA::platformVerify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const Vector<uint8_t>& signature, const Vector<uint8_t>& data)
 {
-    context.ref();
-    workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), signature = WTFMove(signature), data = "" callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
-        auto& ecKey = downcast<CryptoKeyEC>(key.get());
-        auto& ecParameters = downcast<CryptoAlgorithmEcdsaParams>(*parameters);
-
-        auto result = verifyECDSA(ecParameters.hashIdentifier, ecKey.platformKey(), ecKey.keySizeInBits() / 8, signature, data);
-        if (result.hasException()) {
-            // We should only dereference callbacks after being back to the Document/Worker threads.
-            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code(), callback = WTFMove(callback)](ScriptExecutionContext& context) {
-                exceptionCallback(ec);
-                context.deref();
-            });
-            return;
-        }
-        // We should only dereference callbacks after being back to the Document/Worker threads.
-        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue(), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
-            callback(result);
-            context.deref();
-        });
-    });
+    auto& ecKey = downcast<CryptoKeyEC>(key);
+    auto& ecParameters = downcast<CryptoAlgorithmEcdsaParams>(parameters);
+    return verifyECDSA(ecParameters.hashIdentifier, ecKey.platformKey(), ecKey.keySizeInBits() / 8, signature, data);
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to