Changeset 159578 in webkit
- Timestamp:
- Nov 20, 2013, 1:18:26 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r159575 r159578 1 2013-11-20 Alexey Proskuryakov <ap@apple.com> 2 3 Use std::function callbacks in CryptoAlgorithm instead of JS promises 4 https://bugs.webkit.org/show_bug.cgi?id=124673 5 6 Reviewed by Anders Carlsson. 7 8 To implement key wrapping/unwrapping, we'll need to chain existing operations. 9 It's much easier to do with C++ callbacks than with functions fulfilling JS 10 promises directly. 11 12 Also, this will decouple CryptoAlgorithm from JS, which is nice. 13 14 SubtleCrypto IDL says that all functions return Promise<any>, but in reality, 15 there is very little polymorphism, the only function whose return type depends 16 on algorithm is generateKey (it can create a Key or a KeyPair). 17 18 * bindings/js/JSDOMPromise.cpp: 19 (WebCore::PromiseWrapper::PromiseWrapper): 20 (WebCore::PromiseWrapper::operator=): 21 * bindings/js/JSDOMPromise.h: 22 Made it copyable, as each crypto function wraps the promise in success and failure 23 functional objects now. 24 25 * bindings/js/JSSubtleCryptoCustom.cpp: 26 (WebCore::JSSubtleCrypto::encrypt): 27 (WebCore::JSSubtleCrypto::decrypt): 28 (WebCore::JSSubtleCrypto::sign): 29 (WebCore::JSSubtleCrypto::verify): 30 (WebCore::JSSubtleCrypto::digest): 31 (WebCore::JSSubtleCrypto::generateKey): 32 (WebCore::JSSubtleCrypto::importKey): 33 (WebCore::JSSubtleCrypto::exportKey): 34 * crypto/CryptoAlgorithm.cpp: 35 (WebCore::CryptoAlgorithm::encrypt): 36 (WebCore::CryptoAlgorithm::decrypt): 37 (WebCore::CryptoAlgorithm::sign): 38 (WebCore::CryptoAlgorithm::verify): 39 (WebCore::CryptoAlgorithm::digest): 40 (WebCore::CryptoAlgorithm::generateKey): 41 (WebCore::CryptoAlgorithm::deriveKey): 42 (WebCore::CryptoAlgorithm::deriveBits): 43 (WebCore::CryptoAlgorithm::importKey): 44 * crypto/CryptoAlgorithm.h: 45 * crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp: 46 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::sign): 47 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::verify): 48 * crypto/algorithms/CryptoAlgorithmAES_CBC.cpp: 49 (WebCore::CryptoAlgorithmAES_CBC::generateKey): 50 (WebCore::CryptoAlgorithmAES_CBC::importKey): 51 * crypto/algorithms/CryptoAlgorithmAES_CBC.h: 52 * crypto/algorithms/CryptoAlgorithmHMAC.cpp: 53 (WebCore::CryptoAlgorithmHMAC::generateKey): 54 (WebCore::CryptoAlgorithmHMAC::importKey): 55 * crypto/algorithms/CryptoAlgorithmHMAC.h: 56 * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp: 57 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey): 58 (WebCore::CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey): 59 * crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h: 60 * crypto/algorithms/CryptoAlgorithmSHA1.cpp: 61 (WebCore::CryptoAlgorithmSHA1::digest): 62 * crypto/algorithms/CryptoAlgorithmSHA1.h: 63 * crypto/algorithms/CryptoAlgorithmSHA224.cpp: 64 (WebCore::CryptoAlgorithmSHA224::digest): 65 * crypto/algorithms/CryptoAlgorithmSHA224.h: 66 * crypto/algorithms/CryptoAlgorithmSHA256.cpp: 67 (WebCore::CryptoAlgorithmSHA256::digest): 68 * crypto/algorithms/CryptoAlgorithmSHA256.h: 69 * crypto/algorithms/CryptoAlgorithmSHA384.cpp: 70 (WebCore::CryptoAlgorithmSHA384::digest): 71 * crypto/algorithms/CryptoAlgorithmSHA384.h: 72 * crypto/algorithms/CryptoAlgorithmSHA512.cpp: 73 (WebCore::CryptoAlgorithmSHA512::digest): 74 * crypto/algorithms/CryptoAlgorithmSHA512.h: 75 * crypto/keys/CryptoKeyRSA.h: 76 * crypto/mac/CryptoAlgorithmAES_CBCMac.cpp: 77 (WebCore::transformAES_CBC): 78 (WebCore::CryptoAlgorithmAES_CBC::encrypt): 79 (WebCore::CryptoAlgorithmAES_CBC::decrypt): 80 * crypto/mac/CryptoAlgorithmHMACMac.cpp: 81 (WebCore::CryptoAlgorithmHMAC::sign): 82 (WebCore::CryptoAlgorithmHMAC::verify): 83 * crypto/mac/CryptoKeyRSAMac.cpp: 84 (WebCore::CryptoKeyRSA::generatePair): 85 1 86 2013-11-20 Robert Hogan <robert@webkit.org> 2 87 -
trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp
r158317 r159578 35 35 } 36 36 37 PromiseWrapper::PromiseWrapper(const PromiseWrapper& other) 38 : m_globalObject(other.m_globalObject) 39 , m_promise(other.m_promise) 40 { 37 41 } 42 43 PromiseWrapper& PromiseWrapper::operator=(const PromiseWrapper& other) 44 { 45 m_globalObject = other.m_globalObject; 46 m_promise = other.m_promise; 47 return *this; 48 } 49 50 } -
trunk/Source/WebCore/bindings/js/JSDOMPromise.h
r159068 r159578 34 34 #include <runtime/JSPromiseResolver.h> 35 35 #include <heap/StrongInlines.h> 36 #include <wtf/Noncopyable.h>37 36 38 37 namespace WebCore { 39 38 40 // FIXME: Using this class in DOM code makes it dependent on JS bindings.41 39 class PromiseWrapper { 42 WTF_MAKE_NONCOPYABLE(PromiseWrapper)43 40 public: 44 static std::unique_ptr<PromiseWrapper> create(JSDOMGlobalObject* globalObject, JSC::JSPromise* promise)45 { 46 return std::unique_ptr<PromiseWrapper>(new PromiseWrapper(globalObject, promise));47 }41 PromiseWrapper(JSDOMGlobalObject*, JSC::JSPromise*); 42 43 PromiseWrapper(const PromiseWrapper&); 44 PromiseWrapper& operator=(const PromiseWrapper&); 48 45 49 46 template<class FulfillResultType> … … 54 51 55 52 private: 56 PromiseWrapper(JSDOMGlobalObject*, JSC::JSPromise*);57 58 53 JSC::Strong<JSDOMGlobalObject> m_globalObject; 59 54 JSC::Strong<JSC::JSPromise> m_promise; -
trunk/Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
r159392 r159578 163 163 164 164 JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject()); 165 auto promiseWrapper = PromiseWrapper::create(globalObject(), promise); 165 PromiseWrapper promiseWrapper(globalObject(), promise); 166 auto successCallback = [promiseWrapper](const Vector<uint8_t>& result) mutable { 167 promiseWrapper.fulfill(result); 168 }; 169 auto failureCallback = [promiseWrapper]() mutable { 170 promiseWrapper.reject(nullptr); 171 }; 166 172 167 173 ExceptionCode ec = 0; 168 algorithm->encrypt(*parameters, *key, data, std::move( promiseWrapper), ec);174 algorithm->encrypt(*parameters, *key, data, std::move(successCallback), std::move(failureCallback), ec); 169 175 if (ec) { 170 176 setDOMException(exec, ec); … … 209 215 210 216 JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject()); 211 auto promiseWrapper = PromiseWrapper::create(globalObject(), promise); 217 PromiseWrapper promiseWrapper(globalObject(), promise); 218 auto successCallback = [promiseWrapper](const Vector<uint8_t>& result) mutable { 219 promiseWrapper.fulfill(result); 220 }; 221 auto failureCallback = [promiseWrapper]() mutable { 222 promiseWrapper.reject(nullptr); 223 }; 212 224 213 225 ExceptionCode ec = 0; 214 algorithm->decrypt(*parameters, *key, data, std::move( promiseWrapper), ec);226 algorithm->decrypt(*parameters, *key, data, std::move(successCallback), std::move(failureCallback), ec); 215 227 if (ec) { 216 228 setDOMException(exec, ec); … … 255 267 256 268 JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject()); 257 auto promiseWrapper = PromiseWrapper::create(globalObject(), promise); 269 PromiseWrapper promiseWrapper(globalObject(), promise); 270 auto successCallback = [promiseWrapper](const Vector<uint8_t>& result) mutable { 271 promiseWrapper.fulfill(result); 272 }; 273 auto failureCallback = [promiseWrapper]() mutable { 274 promiseWrapper.reject(nullptr); 275 }; 258 276 259 277 ExceptionCode ec = 0; 260 algorithm->sign(*parameters, *key, data, std::move( promiseWrapper), ec);278 algorithm->sign(*parameters, *key, data, std::move(successCallback), std::move(failureCallback), ec); 261 279 if (ec) { 262 280 setDOMException(exec, ec); … … 307 325 308 326 JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject()); 309 auto promiseWrapper = PromiseWrapper::create(globalObject(), promise); 327 PromiseWrapper promiseWrapper(globalObject(), promise); 328 auto successCallback = [promiseWrapper](bool result) mutable { 329 promiseWrapper.fulfill(result); 330 }; 331 auto failureCallback = [promiseWrapper]() mutable { 332 promiseWrapper.reject(nullptr); 333 }; 310 334 311 335 ExceptionCode ec = 0; 312 algorithm->verify(*parameters, *key, signature, data, std::move( promiseWrapper), ec);336 algorithm->verify(*parameters, *key, signature, data, std::move(successCallback), std::move(failureCallback), ec); 313 337 if (ec) { 314 338 setDOMException(exec, ec); … … 343 367 344 368 JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject()); 345 std::unique_ptr<PromiseWrapper> promiseWrapper = PromiseWrapper::create(globalObject(), promise); 369 PromiseWrapper promiseWrapper(globalObject(), promise); 370 auto successCallback = [promiseWrapper](const Vector<uint8_t>& result) mutable { 371 promiseWrapper.fulfill(result); 372 }; 373 auto failureCallback = [promiseWrapper]() mutable { 374 promiseWrapper.reject(nullptr); 375 }; 346 376 347 377 ExceptionCode ec = 0; 348 algorithm->digest(*parameters, data, std::move( promiseWrapper), ec);378 algorithm->digest(*parameters, data, std::move(successCallback), std::move(failureCallback), ec); 349 379 if (ec) { 350 380 setDOMException(exec, ec); … … 388 418 389 419 JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject()); 390 auto promiseWrapper = PromiseWrapper::create(globalObject(), promise); 420 PromiseWrapper promiseWrapper(globalObject(), promise); 421 auto successCallback = [promiseWrapper](CryptoKey* key, CryptoKeyPair* keyPair) mutable { 422 ASSERT(key || keyPair); 423 ASSERT(!key || !keyPair); 424 if (key) 425 promiseWrapper.fulfill(key); 426 else 427 promiseWrapper.fulfill(keyPair); 428 }; 429 auto failureCallback = [promiseWrapper]() mutable { 430 promiseWrapper.reject(nullptr); 431 }; 391 432 392 433 ExceptionCode ec = 0; 393 algorithm->generateKey(*parameters, extractable, keyUsages, std::move( promiseWrapper), ec);434 algorithm->generateKey(*parameters, extractable, keyUsages, std::move(successCallback), std::move(failureCallback), ec); 394 435 if (ec) { 395 436 setDOMException(exec, ec); … … 495 536 496 537 JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject()); 497 auto promiseWrapper = PromiseWrapper::create(globalObject(), promise); 538 PromiseWrapper promiseWrapper(globalObject(), promise); 539 auto successCallback = [promiseWrapper](CryptoKey& result) mutable { 540 promiseWrapper.fulfill(&result); 541 }; 542 auto failureCallback = [promiseWrapper]() mutable { 543 promiseWrapper.reject(nullptr); 544 }; 498 545 499 546 ExceptionCode ec = 0; 500 algorithm->importKey(*parameters, *keyData, extractable, keyUsages, std::move( promiseWrapper), ec);547 algorithm->importKey(*parameters, *keyData, extractable, keyUsages, std::move(successCallback), std::move(failureCallback), ec); 501 548 if (ec) { 502 549 setDOMException(exec, ec); … … 523 570 524 571 JSPromise* promise = JSPromise::createWithResolver(exec->vm(), globalObject()); 525 auto promiseWrapper = PromiseWrapper::create(globalObject(), promise);572 PromiseWrapper promiseWrapper(globalObject(), promise); 526 573 527 574 if (!key->extractable()) { 528 575 m_impl->document()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, "Key is not extractable"); 529 promiseWrapper ->reject(nullptr);576 promiseWrapper.reject(nullptr); 530 577 return promise; 531 578 } … … 535 582 Vector<unsigned char> result; 536 583 if (CryptoKeySerializationRaw::serialize(*key, result)) 537 promiseWrapper ->fulfill(result);584 promiseWrapper.fulfill(result); 538 585 else { 539 586 m_impl->document()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, "Key cannot be exported to raw format"); 540 promiseWrapper ->reject(nullptr);587 promiseWrapper.reject(nullptr); 541 588 } 542 589 break; … … 549 596 Vector<unsigned char> resultBuffer; 550 597 resultBuffer.append(utf8String.data(), utf8String.length()); 551 promiseWrapper ->fulfill(resultBuffer);598 promiseWrapper.fulfill(resultBuffer); 552 599 break; 553 600 } -
trunk/Source/WebCore/crypto/CryptoAlgorithm.cpp
r159379 r159578 41 41 } 42 42 43 void CryptoAlgorithm::encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)43 void CryptoAlgorithm::encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback, VoidCallback, ExceptionCode& ec) 44 44 { 45 45 ec = NOT_SUPPORTED_ERR; 46 46 } 47 47 48 void CryptoAlgorithm::decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)48 void CryptoAlgorithm::decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback, VoidCallback, ExceptionCode& ec) 49 49 { 50 50 ec = NOT_SUPPORTED_ERR; 51 51 } 52 52 53 void CryptoAlgorithm::sign(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)53 void CryptoAlgorithm::sign(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback, VoidCallback, ExceptionCode& ec) 54 54 { 55 55 ec = NOT_SUPPORTED_ERR; 56 56 } 57 57 58 void CryptoAlgorithm::verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)58 void CryptoAlgorithm::verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, const CryptoOperationData&, BoolCallback, VoidCallback, ExceptionCode& ec) 59 59 { 60 60 ec = NOT_SUPPORTED_ERR; 61 61 } 62 62 63 void CryptoAlgorithm::digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)63 void CryptoAlgorithm::digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, VectorCallback, VoidCallback, ExceptionCode& ec) 64 64 { 65 65 ec = NOT_SUPPORTED_ERR; 66 66 } 67 67 68 void CryptoAlgorithm::generateKey(const CryptoAlgorithmParameters&, bool, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)68 void CryptoAlgorithm::generateKey(const CryptoAlgorithmParameters&, bool, CryptoKeyUsage, KeyOrKeyPairCallback, VoidCallback, ExceptionCode& ec) 69 69 { 70 70 ec = NOT_SUPPORTED_ERR; 71 71 } 72 72 73 void CryptoAlgorithm::deriveKey(const CryptoAlgorithmParameters&, const CryptoKey&, CryptoAlgorithm*, bool, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)73 void CryptoAlgorithm::deriveKey(const CryptoAlgorithmParameters&, const CryptoKey&, CryptoAlgorithm*, bool, CryptoKeyUsage, KeyCallback, VoidCallback, ExceptionCode& ec) 74 74 { 75 75 ec = NOT_SUPPORTED_ERR; 76 76 } 77 77 78 void CryptoAlgorithm::deriveBits(const CryptoAlgorithmParameters&, const CryptoKey&, unsigned long, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)78 void CryptoAlgorithm::deriveBits(const CryptoAlgorithmParameters&, const CryptoKey&, unsigned long, VectorCallback, VoidCallback, ExceptionCode& ec) 79 79 { 80 80 ec = NOT_SUPPORTED_ERR; 81 81 } 82 82 83 void CryptoAlgorithm::importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode& ec)83 void CryptoAlgorithm::importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool, CryptoKeyUsage, KeyCallback, VoidCallback, ExceptionCode& ec) 84 84 { 85 85 ec = NOT_SUPPORTED_ERR; -
trunk/Source/WebCore/crypto/CryptoAlgorithm.h
r159379 r159578 29 29 #include "CryptoAlgorithmIdentifier.h" 30 30 #include "CryptoKeyUsage.h" 31 #include <functional> 31 32 #include <wtf/Noncopyable.h> 33 #include <wtf/Vector.h> 32 34 33 35 #if ENABLE(SUBTLE_CRYPTO) … … 39 41 class CryptoAlgorithmParameters; 40 42 class CryptoKey; 43 class CryptoKeyPair; 41 44 class CryptoKeyData; 42 class PromiseWrapper;43 45 44 46 // Data is mutable, so async operations should copy it first. … … 52 54 virtual CryptoAlgorithmIdentifier identifier() const = 0; 53 55 54 virtual void encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&); 55 virtual void decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&); 56 virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&); 57 virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper>, ExceptionCode&); 58 virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&); 59 virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&); 60 virtual void deriveKey(const CryptoAlgorithmParameters&, const CryptoKey& baseKey, CryptoAlgorithm* derivedKeyType, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&); 61 virtual void deriveBits(const CryptoAlgorithmParameters&, const CryptoKey& baseKey, unsigned long length, std::unique_ptr<PromiseWrapper>, ExceptionCode&); 62 virtual void importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&); 56 typedef std::function<void(bool)> BoolCallback; 57 typedef std::function<void(CryptoKey&)> KeyCallback; 58 typedef std::function<void(CryptoKey*, CryptoKeyPair*)> KeyOrKeyPairCallback; 59 typedef std::function<void(const Vector<uint8_t>&)> VectorCallback; 60 typedef std::function<void()> VoidCallback; 61 62 virtual void encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&); 63 virtual void decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&); 64 virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&); 65 virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const CryptoOperationData& data, BoolCallback, VoidCallback failureCallback, ExceptionCode&); 66 virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&); 67 virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, KeyOrKeyPairCallback, VoidCallback failureCallback, ExceptionCode&); 68 virtual void deriveKey(const CryptoAlgorithmParameters&, const CryptoKey& baseKey, CryptoAlgorithm* derivedKeyType, bool extractable, CryptoKeyUsage, KeyCallback, VoidCallback failureCallback, ExceptionCode&); 69 virtual void deriveBits(const CryptoAlgorithmParameters&, const CryptoKey& baseKey, unsigned long length, VectorCallback, VoidCallback failureCallback, ExceptionCode&); 70 virtual void importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool extractable, CryptoKeyUsage, KeyCallback, VoidCallback failureCallback, ExceptionCode&); 63 71 64 72 protected: -
trunk/Source/WebCore/crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp
r159390 r159578 33 33 #include "CryptoKeyRSA.h" 34 34 #include "ExceptionCode.h" 35 #include "JSDOMPromise.h"36 35 #include <CommonCrypto/CommonCryptor.h> 37 36 … … 90 89 } 91 90 92 void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)91 void CryptoAlgorithmRSASSA_PKCS1_v1_5::sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec) 93 92 { 94 93 const CryptoAlgorithmRsaSsaParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaParams(parameters); … … 121 120 CCCryptorStatus status = CCRSACryptorSign(rsaKey.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.data(), &signatureSize); 122 121 if (status) { 123 promise->reject(nullptr);122 failureCallback(); 124 123 return; 125 124 } 126 125 127 126 signature.resize(signatureSize); 128 promise->fulfill(signature);127 callback(signature); 129 128 } 130 129 131 void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& signature, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)130 void CryptoAlgorithmRSASSA_PKCS1_v1_5::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& signature, const CryptoOperationData& data, BoolCallback callback, VoidCallback failureCallback, ExceptionCode& ec) 132 131 { 133 132 const CryptoAlgorithmRsaSsaParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaParams(parameters); … … 157 156 CCCryptorStatus status = CCRSACryptorVerify(rsaKey.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.first, signature.second); 158 157 if (!status) 159 promise->fulfill(true);158 callback(true); 160 159 else if (status == kCCNotVerified || kCCDecodeError) // <rdar://problem/15464982> CCRSACryptorVerify returns kCCDecodeError instead of kCCNotVerified sometimes 161 promise->fulfill(false);160 callback(false); 162 161 else 163 promise->reject(nullptr);162 failureCallback(); 164 163 } 165 164 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp
r159213 r159578 33 33 #include "CryptoKeyDataOctetSequence.h" 34 34 #include "ExceptionCode.h" 35 #include "JSDOMPromise.h"36 35 37 36 namespace WebCore { … … 57 56 } 58 57 59 void CryptoAlgorithmAES_CBC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)58 void CryptoAlgorithmAES_CBC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, KeyOrKeyPairCallback callback, VoidCallback failureCallback, ExceptionCode&) 60 59 { 61 60 const CryptoAlgorithmAesKeyGenParams& aesParameters = toCryptoAlgorithmAesKeyGenParams(parameters); … … 63 62 RefPtr<CryptoKeyAES> result = CryptoKeyAES::generate(CryptoAlgorithmIdentifier::AES_CBC, aesParameters.length, extractable, usages); 64 63 if (!result) { 65 promise->reject(nullptr);64 failureCallback(); 66 65 return; 67 66 } 68 67 69 promise->fulfill(result.release());68 callback(result.get(), nullptr); 70 69 } 71 70 72 void CryptoAlgorithmAES_CBC::importKey(const CryptoAlgorithmParameters&, const CryptoKeyData& keyData, bool extractable, CryptoKeyUsage usage, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)71 void CryptoAlgorithmAES_CBC::importKey(const CryptoAlgorithmParameters&, const CryptoKeyData& keyData, bool extractable, CryptoKeyUsage usage, KeyCallback callback, VoidCallback, ExceptionCode& ec) 73 72 { 74 73 if (keyData.format() != CryptoKeyData::Format::OctetSequence) { … … 78 77 const CryptoKeyDataOctetSequence& keyDataOctetSequence = toCryptoKeyDataOctetSequence(keyData); 79 78 RefPtr<CryptoKeyAES> result = CryptoKeyAES::create(CryptoAlgorithmIdentifier::AES_CBC, keyDataOctetSequence.octetSequence(), extractable, usage); 80 promise->fulfill(result.release());79 callback(*result); 81 80 } 82 81 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.h
r159379 r159578 42 42 virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE; 43 43 44 virtual void encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;45 virtual void decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;46 virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;47 virtual void importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;44 virtual void encrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 45 virtual void decrypt(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 46 virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, KeyOrKeyPairCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 47 virtual void importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool extractable, CryptoKeyUsage, KeyCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 48 48 49 49 private: -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp
r159213 r159578 34 34 #include "CryptoKeyHMAC.h" 35 35 #include "ExceptionCode.h" 36 #include "JSDOMPromise.h"37 36 38 37 namespace WebCore { … … 58 57 } 59 58 60 void CryptoAlgorithmHMAC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)59 void CryptoAlgorithmHMAC::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, KeyOrKeyPairCallback callback, VoidCallback failureCallback, ExceptionCode&) 61 60 { 62 61 const CryptoAlgorithmHmacKeyParams& hmacParameters = toCryptoAlgorithmHmacKeyParams(parameters); … … 64 63 RefPtr<CryptoKeyHMAC> result = CryptoKeyHMAC::generate(hmacParameters.hasLength ? hmacParameters.length : 0, hmacParameters.hash, extractable, usages); 65 64 if (!result) { 66 promise->reject(nullptr);65 failureCallback(); 67 66 return; 68 67 } 69 68 70 promise->fulfill(result.release());69 callback(result.get(), nullptr); 71 70 } 72 71 73 void CryptoAlgorithmHMAC::importKey(const CryptoAlgorithmParameters& parameters, const CryptoKeyData& keyData, bool extractable, CryptoKeyUsage usage, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)72 void CryptoAlgorithmHMAC::importKey(const CryptoAlgorithmParameters& parameters, const CryptoKeyData& keyData, bool extractable, CryptoKeyUsage usage, KeyCallback callback, VoidCallback, ExceptionCode& ec) 74 73 { 75 74 if (keyData.format() != CryptoKeyData::Format::OctetSequence) { … … 82 81 83 82 RefPtr<CryptoKeyHMAC> result = CryptoKeyHMAC::create(keyDataOctetSequence.octetSequence(), hmacParameters.hash, extractable, usage); 84 promise->fulfill(result.release());83 callback(*result); 85 84 } 86 85 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.h
r159379 r159578 42 42 virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE; 43 43 44 virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;45 virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;46 virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;47 virtual void importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;44 virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 45 virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const CryptoOperationData& data, BoolCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 46 virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, KeyOrKeyPairCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 47 virtual void importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool extractable, CryptoKeyUsage, KeyCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 48 48 49 49 private: -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp
r159213 r159578 33 33 #include "CryptoKeyDataRSAComponents.h" 34 34 #include "CryptoKeyRSA.h" 35 #include "JSDOMPromise.h"36 35 37 36 namespace WebCore { … … 57 56 } 58 57 59 void CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey(const CryptoAlgorithmParameters& parameters, const CryptoKeyData& keyData, bool extractable, CryptoKeyUsage usage, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&) 58 void CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, KeyOrKeyPairCallback callback, VoidCallback failureCallback, ExceptionCode&) 59 { 60 const CryptoAlgorithmRsaKeyGenParams& rsaParameters = toCryptoAlgorithmRsaKeyGenParams(parameters); 61 62 auto keyPairCallback = [callback](CryptoKeyPair& pair) { 63 callback(nullptr, &pair); 64 }; 65 66 CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5, rsaParameters.modulusLength, rsaParameters.publicExponent, extractable, usages, std::move(keyPairCallback), std::move(failureCallback)); 67 } 68 69 void CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey(const CryptoAlgorithmParameters& parameters, const CryptoKeyData& keyData, bool extractable, CryptoKeyUsage usage, KeyCallback callback, VoidCallback failureCallback, ExceptionCode&) 60 70 { 61 71 const CryptoAlgorithmRsaSsaKeyParams& rsaSSAParameters = toCryptoAlgorithmRsaSsaKeyParams(parameters); … … 64 74 RefPtr<CryptoKeyRSA> result = CryptoKeyRSA::create(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5, rsaComponents, extractable, usage); 65 75 if (!result) { 66 promise->reject(nullptr);76 failureCallback(); 67 77 return; 68 78 } … … 71 81 result->restrictToHash(rsaSSAParameters.hash); 72 82 73 promise->fulfill(result.release()); 74 } 75 76 void CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey(const CryptoAlgorithmParameters& parameters, bool extractable, CryptoKeyUsage usages, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&) 77 { 78 const CryptoAlgorithmRsaKeyGenParams& rsaParameters = toCryptoAlgorithmRsaKeyGenParams(parameters); 79 80 CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5, rsaParameters.modulusLength, rsaParameters.publicExponent, extractable, usages, std::move(promise)); 83 callback(*result); 81 84 } 82 85 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h
r159379 r159578 42 42 virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE; 43 43 44 virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;45 virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;46 virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;47 virtual void importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;44 virtual void sign(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 45 virtual void verify(const CryptoAlgorithmParameters&, const CryptoKey&, const CryptoOperationData& signature, const CryptoOperationData& data, BoolCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 46 virtual void generateKey(const CryptoAlgorithmParameters&, bool extractable, CryptoKeyUsage, KeyOrKeyPairCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 47 virtual void importKey(const CryptoAlgorithmParameters&, const CryptoKeyData&, bool extractable, CryptoKeyUsage, KeyCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 48 48 49 49 private: -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA1.cpp
r159379 r159578 30 30 31 31 #include "CryptoDigest.h" 32 #include "JSDOMPromise.h"33 32 34 33 namespace WebCore { … … 54 53 } 55 54 56 void CryptoAlgorithmSHA1::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)55 void CryptoAlgorithmSHA1::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode&) 57 56 { 58 57 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_1); 59 58 if (!digest) { 60 promise->reject(nullptr);59 failureCallback(); 61 60 return; 62 61 } … … 64 63 digest->addBytes(data.first, data.second); 65 64 66 promise->fulfill(digest->computeHash());65 callback(digest->computeHash()); 67 66 } 68 67 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA1.h
r159379 r159578 42 42 virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE; 43 43 44 virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;44 virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 45 45 46 46 private: -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA224.cpp
r159379 r159578 30 30 31 31 #include "CryptoDigest.h" 32 #include "JSDOMPromise.h"33 32 34 33 namespace WebCore { … … 54 53 } 55 54 56 void CryptoAlgorithmSHA224::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)55 void CryptoAlgorithmSHA224::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode&) 57 56 { 58 57 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_224); 59 58 if (!digest) { 60 promise->reject(nullptr);59 failureCallback(); 61 60 return; 62 61 } … … 64 63 digest->addBytes(data.first, data.second); 65 64 66 promise->fulfill(digest->computeHash());65 callback(digest->computeHash()); 67 66 } 68 67 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA224.h
r159379 r159578 42 42 virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE; 43 43 44 virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;44 virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 45 45 46 46 private: -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA256.cpp
r159379 r159578 30 30 31 31 #include "CryptoDigest.h" 32 #include "JSDOMPromise.h"33 32 34 33 namespace WebCore { … … 54 53 } 55 54 56 void CryptoAlgorithmSHA256::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)55 void CryptoAlgorithmSHA256::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode&) 57 56 { 58 57 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_256); 59 58 if (!digest) { 60 promise->reject(nullptr);59 failureCallback(); 61 60 return; 62 61 } … … 64 63 digest->addBytes(data.first, data.second); 65 64 66 promise->fulfill(digest->computeHash());65 callback(digest->computeHash()); 67 66 } 68 67 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA256.h
r159379 r159578 42 42 virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE; 43 43 44 virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;44 virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 45 45 46 46 private: -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA384.cpp
r159379 r159578 30 30 31 31 #include "CryptoDigest.h" 32 #include "JSDOMPromise.h"33 32 34 33 namespace WebCore { … … 54 53 } 55 54 56 void CryptoAlgorithmSHA384::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)55 void CryptoAlgorithmSHA384::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode&) 57 56 { 58 57 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_384); 59 58 if (!digest) { 60 promise->reject(nullptr);59 failureCallback(); 61 60 return; 62 61 } … … 64 63 digest->addBytes(data.first, data.second); 65 64 66 promise->fulfill(digest->computeHash());65 callback(digest->computeHash()); 67 66 } 68 67 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA384.h
r159379 r159578 42 42 virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE; 43 43 44 virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;44 virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 45 45 46 46 private: -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA512.cpp
r159379 r159578 30 30 31 31 #include "CryptoDigest.h" 32 #include "JSDOMPromise.h"33 32 34 33 namespace WebCore { … … 54 53 } 55 54 56 void CryptoAlgorithmSHA512::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode&)55 void CryptoAlgorithmSHA512::digest(const CryptoAlgorithmParameters&, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode&) 57 56 { 58 57 std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(CryptoAlgorithmIdentifier::SHA_512); 59 58 if (!digest) { 60 promise->reject(nullptr);59 failureCallback(); 61 60 return; 62 61 } … … 64 63 digest->addBytes(data.first, data.second); 65 64 66 promise->fulfill(digest->computeHash());65 callback(digest->computeHash()); 67 66 } 68 67 -
trunk/Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA512.h
r159379 r159578 42 42 virtual CryptoAlgorithmIdentifier identifier() const OVERRIDE; 43 43 44 virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, std::unique_ptr<PromiseWrapper>, ExceptionCode&) OVERRIDE;44 virtual void digest(const CryptoAlgorithmParameters&, const CryptoOperationData&, VectorCallback, VoidCallback failureCallback, ExceptionCode&) OVERRIDE; 45 45 46 46 private: -
trunk/Source/WebCore/crypto/keys/CryptoKeyRSA.h
r159403 r159578 28 28 29 29 #include "CryptoKey.h" 30 #include <functional> 30 31 31 32 #if ENABLE(SUBTLE_CRYPTO) … … 56 57 size_t keySizeInBits() const; 57 58 58 static void generatePair(CryptoAlgorithmIdentifier, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage, std::unique_ptr<PromiseWrapper>); 59 typedef std::function<void(CryptoKeyPair&)> KeyPairCallback; 60 typedef std::function<void()> VoidCallback; 61 static void generatePair(CryptoAlgorithmIdentifier, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage, KeyPairCallback, VoidCallback failureCallback); 59 62 60 63 PlatformRSAKey platformKey() const { return m_platformKey; } -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp
r159390 r159578 32 32 #include "CryptoKeyAES.h" 33 33 #include "ExceptionCode.h" 34 #include "JSDOMPromise.h"35 34 #include <CommonCrypto/CommonCrypto.h> 36 35 37 36 namespace WebCore { 38 37 39 static void transformAES_CBC(CCOperation operation, const CryptoAlgorithmAesCbcParams& parameters, const CryptoKeyAES& key, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise)38 static void transformAES_CBC(CCOperation operation, const CryptoAlgorithmAesCbcParams& parameters, const CryptoKeyAES& key, const CryptoOperationData& data, CryptoAlgorithm::VectorCallback callback, CryptoAlgorithm::VoidCallback failureCallback) 40 39 { 41 40 static_assert(sizeof(parameters.iv) == kCCBlockSizeAES128, "Initialization vector size must be the same as algorithm block size"); … … 43 42 size_t keyLengthInBytes = key.key().size(); 44 43 if (keyLengthInBytes != 16 && keyLengthInBytes != 24 && keyLengthInBytes != 32) { 45 promise->reject(nullptr);44 failureCallback(); 46 45 return; 47 46 } … … 55 54 CCCryptorStatus status = CCCryptorCreate(operation, aesAlgorithm, kCCOptionPKCS7Padding, key.key().data(), keyLengthInBytes, parameters.iv.data(), &cryptor); 56 55 if (status) { 57 promise->reject(nullptr);56 failureCallback(); 58 57 return; 59 58 } … … 64 63 status = CCCryptorUpdate(cryptor, data.first, data.second, result.data(), result.size(), &bytesWritten); 65 64 if (status) { 66 promise->reject(nullptr);65 failureCallback(); 67 66 return; 68 67 } … … 72 71 p += bytesWritten; 73 72 if (status) { 74 promise->reject(nullptr);73 failureCallback(); 75 74 return; 76 75 } … … 81 80 CCCryptorRelease(cryptor); 82 81 83 promise->fulfill(result);82 callback(result); 84 83 } 85 84 86 void CryptoAlgorithmAES_CBC::encrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)85 void CryptoAlgorithmAES_CBC::encrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec) 87 86 { 88 87 const CryptoAlgorithmAesCbcParams& aesCBCParameters = toCryptoAlgorithmAesCbcParams(parameters); … … 94 93 const CryptoKeyAES& aesKey = toCryptoKeyAES(key); 95 94 96 transformAES_CBC(kCCEncrypt, aesCBCParameters, aesKey, data, std::move( promise));95 transformAES_CBC(kCCEncrypt, aesCBCParameters, aesKey, data, std::move(callback), std::move(failureCallback)); 97 96 } 98 97 99 void CryptoAlgorithmAES_CBC::decrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)98 void CryptoAlgorithmAES_CBC::decrypt(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec) 100 99 { 101 100 const CryptoAlgorithmAesCbcParams& aesCBCParameters = toCryptoAlgorithmAesCbcParams(parameters); … … 107 106 const CryptoKeyAES& aesKey = toCryptoKeyAES(key); 108 107 109 transformAES_CBC(kCCDecrypt, aesCBCParameters, aesKey, data, std::move( promise));108 transformAES_CBC(kCCDecrypt, aesCBCParameters, aesKey, data, std::move(callback), std::move(failureCallback)); 110 109 } 111 110 -
trunk/Source/WebCore/crypto/mac/CryptoAlgorithmHMACMac.cpp
r159390 r159578 32 32 #include "CryptoKeyHMAC.h" 33 33 #include "ExceptionCode.h" 34 #include "JSDOMPromise.h"35 34 #include <CommonCrypto/CommonHMAC.h> 36 35 … … 90 89 } 91 90 92 void CryptoAlgorithmHMAC::sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)91 void CryptoAlgorithmHMAC::sign(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback, ExceptionCode& ec) 93 92 { 94 93 const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters); … … 108 107 Vector<uint8_t> signature = calculateSignature(algorithm, hmacKey.key(), data); 109 108 110 promise->fulfill(signature);109 callback(signature); 111 110 } 112 111 113 void CryptoAlgorithmHMAC::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& expectedSignature, const CryptoOperationData& data, std::unique_ptr<PromiseWrapper> promise, ExceptionCode& ec)112 void CryptoAlgorithmHMAC::verify(const CryptoAlgorithmParameters& parameters, const CryptoKey& key, const CryptoOperationData& expectedSignature, const CryptoOperationData& data, BoolCallback callback, VoidCallback, ExceptionCode& ec) 114 113 { 115 114 const CryptoAlgorithmHmacParams& hmacParameters = toCryptoAlgorithmHmacParams(parameters); … … 131 130 bool result = signature.size() == expectedSignature.second && !memcmp(signature.data(), expectedSignature.first, signature.size()); 132 131 133 promise->fulfill(result);132 callback(result); 134 133 } 135 134 -
trunk/Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp
r159403 r159578 33 33 #include "CryptoKeyDataRSAComponents.h" 34 34 #include "CryptoKeyPair.h" 35 #include "JSDOMPromise.h"36 35 #include <CommonCrypto/CommonCryptor.h> 37 36 … … 210 209 } 211 210 212 void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier algorithm, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage usage, std::unique_ptr<PromiseWrapper> promise)211 void CryptoKeyRSA::generatePair(CryptoAlgorithmIdentifier algorithm, unsigned modulusLength, const Vector<uint8_t>& publicExponent, bool extractable, CryptoKeyUsage usage, KeyPairCallback callback, VoidCallback failureCallback) 213 212 { 214 213 uint32_t e; … … 216 215 // Adding support is tracked as <rdar://problem/15444034>. 217 216 WTFLogAlways("Public exponent is too big, not supported"); 218 promise->reject(nullptr);217 failureCallback(); 219 218 return; 220 219 } 221 220 222 PromiseWrapper* localPromise = promise.release(); 221 // We only use the callback functions when back on the main thread, but captured variables are copied on a secondary thread too. 222 KeyPairCallback* localCallback = new KeyPairCallback(std::move(callback)); 223 VoidCallback* localFailureCallback = new VoidCallback(std::move(failureCallback)); 223 224 224 225 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ … … 229 230 WTFLogAlways("Could not generate a key pair, status %d", status); 230 231 dispatch_async(dispatch_get_main_queue(), ^{ 231 localPromise->reject(nullptr);232 delete local Promise;232 (*localFailureCallback)(); 233 delete localFailureCallback; 233 234 }); 234 235 return; … … 237 238 RefPtr<CryptoKeyRSA> publicKey = CryptoKeyRSA::create(algorithm, CryptoKeyType::Public, ccPublicKey, extractable, usage); 238 239 RefPtr<CryptoKeyRSA> privateKey = CryptoKeyRSA::create(algorithm, CryptoKeyType::Private, ccPrivateKey, extractable, usage); 239 localPromise->fulfill(CryptoKeyPair::create(publicKey.release(), privateKey.release()));240 delete local Promise;240 (*localCallback)(*CryptoKeyPair::create(publicKey.release(), privateKey.release())); 241 delete localCallback; 241 242 }); 242 243 });
Note:
See TracChangeset
for help on using the changeset viewer.