Bug 124673

Summary: Use std::function callbacks in CryptoAlgorithm instead of JS promises
Product: WebKit Reporter: Alexey Proskuryakov <ap>
Component: WebCore JavaScriptAssignee: Alexey Proskuryakov <ap>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, commit-queue, sam
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 122679    
Attachments:
Description Flags
proposed patch andersca: review+

Description Alexey Proskuryakov 2013-11-20 12:02:46 PST
To implement key wrapping/unwrapping, we'll need to chain existing operations. It's much easier to do with C++ callbacks than with functions fulfilling JS promises directly.

Also, this will decouple CryptoAlgorithm from JS, which is nice.
Comment 1 Alexey Proskuryakov 2013-11-20 12:19:16 PST
Created attachment 217463 [details]
proposed patch
Comment 2 WebKit Commit Bot 2013-11-20 12:20:47 PST
Attachment 217463 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/ChangeLog', u'Source/WebCore/bindings/js/JSDOMPromise.cpp', u'Source/WebCore/bindings/js/JSDOMPromise.h', u'Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp', u'Source/WebCore/crypto/CryptoAlgorithm.cpp', u'Source/WebCore/crypto/CryptoAlgorithm.h', u'Source/WebCore/crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.h', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.cpp', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.h', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA1.cpp', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA1.h', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA224.cpp', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA224.h', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA256.cpp', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA256.h', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA384.cpp', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA384.h', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA512.cpp', u'Source/WebCore/crypto/algorithms/CryptoAlgorithmSHA512.h', u'Source/WebCore/crypto/keys/CryptoKeyRSA.h', u'Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp', u'Source/WebCore/crypto/mac/CryptoAlgorithmHMACMac.cpp', u'Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp']" exit_code: 1
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.h:45:  The parameter name "data" adds no information, so it should be removed.  [readability/parameter_name] [5]
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:58:  CryptoAlgorithmAES_CBC::generateKey is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:71:  CryptoAlgorithmAES_CBC::importKey is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:58:  CryptoAlgorithmRSASSA_PKCS1_v1_5::generateKey is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:62:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:69:  CryptoAlgorithmRSASSA_PKCS1_v1_5::importKey is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Source/WebCore/crypto/algorithms/CryptoAlgorithmHMAC.h:45:  The parameter name "data" adds no information, so it should be removed.  [readability/parameter_name] [5]
Source/WebCore/crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:91:  CryptoAlgorithmRSASSA_PKCS1_v1_5::sign is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Source/WebCore/crypto/CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp:130:  CryptoAlgorithmRSASSA_PKCS1_v1_5::verify is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:38:  transformAES_CBC is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:85:  CryptoAlgorithmAES_CBC::encrypt is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Source/WebCore/crypto/mac/CryptoAlgorithmAES_CBCMac.cpp:98:  CryptoAlgorithmAES_CBC::decrypt is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Source/WebCore/crypto/CryptoAlgorithm.h:65:  The parameter name "data" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 13 in 27 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Anders Carlsson 2013-11-20 12:23:16 PST
Comment on attachment 217463 [details]
proposed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=217463&action=review

> Source/WebCore/crypto/algorithms/CryptoAlgorithmAES_CBC.cpp:68
> +    callback(result.get(), 0);

nullptr?

> Source/WebCore/crypto/algorithms/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp:63
> +        callback(0, &pair);

nullptr?

> Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp:222
> +    KeyPairCallback* localCallback = new KeyPairCallback(callback);

Can std::move callback here to avoid a copy.

> Source/WebCore/crypto/mac/CryptoKeyRSAMac.cpp:223
> +    VoidCallback* localFailureCallback = new VoidCallback(failureCallback);

Ditto for failureCallback.
Comment 4 Alexey Proskuryakov 2013-11-20 13:16:16 PST
Committed <http://trac.webkit.org/r159578>.
Comment 5 Darin Adler 2013-11-20 15:20:42 PST
Comment on attachment 217463 [details]
proposed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=217463&action=review

> Source/WebCore/bindings/js/JSDOMPromise.h:44
> +    PromiseWrapper(const PromiseWrapper&);
> +    PromiseWrapper& operator=(const PromiseWrapper&);

Why don’t we just let the compiler generate these? The hand-written functions look the same as what the compiler would generate if we didn’t say anything.