Index: public/platform/WebCrypto.h |
diff --git a/public/platform/WebCrypto.h b/public/platform/WebCrypto.h |
index 5428e9f20df3fcbe46a94ad550d990ce0512a4cc..f576b2540c8f7eb3970959110a6957113f619a5b 100644 |
--- a/public/platform/WebCrypto.h |
+++ b/public/platform/WebCrypto.h |
@@ -33,227 +33,62 @@ |
#include "WebCommon.h" |
#include "WebCryptoKey.h" |
-#include "WebPrivatePtr.h" |
namespace WebKit { |
class WebArrayBuffer; |
-class WebCryptoKeyOperation; |
-class WebCryptoKeyOperationResult; |
class WebCryptoOperation; |
-class WebCryptoOperationResult; |
+ |
+class WebCryptoOperationResult { |
+public: |
+ virtual void completeWithError() = 0; |
+ virtual void completeWithBuffer(const WebArrayBuffer&) = 0; |
+ virtual void completeWithBoolean(bool) = 0; |
+ virtual void completeWithKey(const WebCryptoKey&) = 0; |
+ |
+ // Helper to create a WebArrayBuffer. |
+ WEBKIT_EXPORT void completeWithBuffer(const void*, size_t); |
+ |
+ virtual void willFinishLater() = 0; |
+ |
+protected: |
+ virtual ~WebCryptoOperationResult() { } |
abarth-chromium
2013/08/16 04:53:07
We can make this destructor public so that the Chr
|
+}; |
class WebCrypto { |
public: |
// FIXME: Deprecated, delete once chromium side is updated. |
virtual WebCryptoOperation* digest(const WebCryptoAlgorithm&) { WEBKIT_ASSERT_NOT_REACHED(); return 0; } |
- // The following methods begin an asynchronous multi-part cryptographic |
- // operation. |
- // |
- // Let the WebCryptoOperationResult& be called "result". |
- // |
- // Before returning, implementations can either: |
- // |
- // * Synchronously fail initialization by calling: |
- // result.initializationFailed(errorDetails) |
- // |
- // OR |
+ // Starts a one-shot cryptographic operation which can complete either |
+ // synchronously, or asynchronously. |
// |
- // * Create a new WebCryptoOperation* and return it by calling: |
- // result.initializationSucceeded(cryptoOperation) |
+ // Let the WebCryptoOperationResult* be called "result". |
// |
- // If initialization succeeds, then Blink will subsequently call |
- // methods on cryptoOperation: |
+ // (A) To complete synchronously, call one of the |
+ // "result->completeWithXXX()" methods before returning. |
// |
- // - cryptoOperation->process() to feed it data |
- // - cryptoOperation->finish() to indicate there is no more data |
- // - cryptoOperation->abort() to cancel. |
- // |
- // The embedder may call result.completeWithXXX() at any time while the |
- // cryptoOperation is "in progress" (can copy the initial "result" object). |
- // Typically completion is set once cryptoOperation->finish() is called, |
- // however it can also be called during cryptoOperation->process() (for |
- // instance to set an error). |
- // |
- // The cryptoOperation pointer MUST remain valid while it is "in progress". |
- // The cryptoOperation is said to be "in progress" from the time after |
- // result->initializationSucceded() has been called, up until either: |
- // |
- // - Blink calls cryptoOperation->abort() |
// OR |
- // - Embedder calls result.completeWithXXX() |
- // |
- // Once the cryptoOperation is no longer "in progress" the embedder is |
- // responsible for freeing the cryptoOperation. |
- virtual void encrypt(const WebCryptoAlgorithm&, const WebCryptoKey&, WebCryptoOperationResult&) { WEBKIT_ASSERT_NOT_REACHED(); } |
- virtual void decrypt(const WebCryptoAlgorithm&, const WebCryptoKey&, WebCryptoOperationResult&) { WEBKIT_ASSERT_NOT_REACHED(); } |
- virtual void sign(const WebCryptoAlgorithm&, const WebCryptoKey&, WebCryptoOperationResult&) { WEBKIT_ASSERT_NOT_REACHED(); } |
- virtual void verifySignature(const WebCryptoAlgorithm&, const WebCryptoKey&, const unsigned char* signature, size_t, WebCryptoOperationResult&) { WEBKIT_ASSERT_NOT_REACHED(); } |
- virtual void digest(const WebCryptoAlgorithm&, WebCryptoOperationResult&) { WEBKIT_ASSERT_NOT_REACHED(); } |
- |
- // The following methods begin an asynchronous single-part key operation. |
- // |
- // Let the WebCryptoKeyOperationResult& be called "result". |
- // |
- // Before returning, implementations can either: |
- // |
- // (a) Synchronously fail initialization by calling: |
- // result.initializationFailed(errorDetails) |
- // (this results in throwing a Javascript exception) |
- // |
- // (b) Synchronously complete the request (success or error) by calling: |
- // result.completeWithXXX() |
// |
- // (c) Defer completion by calling |
- // result.initializationSucceeded(keyOperation) |
+ // (B) To complete asynchronously call result->willFinishLater() before |
+ // returning. Later call one of the "result->completeWithXXX()" methods. |
// |
- // If asynchronous completion (c) was chosen, then the embedder can notify |
- // completion after returning by calling result.completeWithXXX() (can make |
- // a copy of "result"). |
- // |
- // The keyOperation pointer MUST remain valid while it is "in progress". |
- // The keyOperation is said to be "in progress" from the time after |
- // result->initializationSucceded() has been called, up until either: |
- // |
- // - Blink calls keyOperation->abort() |
- // OR |
- // - Embedder calls result.completeWithXXX() |
- // |
- // Once the keyOperation is no longer "in progress" the embedder is |
- // responsible for freeing the cryptoOperation. |
- virtual void generateKey(const WebCryptoAlgorithm&, bool extractable, WebCryptoKeyUsageMask, WebCryptoKeyOperationResult&) { WEBKIT_ASSERT_NOT_REACHED(); } |
- virtual void importKey(WebCryptoKeyFormat, const unsigned char* keyData, size_t keyDataSize, const WebCryptoAlgorithm&, bool extractable, WebCryptoKeyUsageMask, WebCryptoKeyOperationResult&) { WEBKIT_ASSERT_NOT_REACHED(); } |
+ // Note that: |
+ // * The "result" pointer is owned by the caller and should not be deleted. |
+ // * Exactly one of the "result->completeXXX()" methods should be called. |
+ // * "result->completeXXX()" must be called from the same thread which |
+ // started the operation. |
-protected: |
- virtual ~WebCrypto() { } |
-}; |
- |
-class WebCryptoOperation { |
-public: |
- // Feeds data (bytes, size) to the operation. |
- // - |bytes| may be 0 if |size| is 0 |
- // - |bytes| is valid only until process() returns |
- // - process() will not be called after abort() or finish() |
- virtual void process(const unsigned char*, size_t) = 0; |
- |
- // Cancels the in-progress operation. |
- // * Implementations should delete |this| after aborting. |
- virtual void abort() = 0; |
- |
- // Indicates that there is no more data to receive. |
- virtual void finish() = 0; |
+ virtual void encrypt(const WebCryptoAlgorithm&, const WebCryptoKey&, const unsigned char* data, size_t data_size, WebCryptoOperationResult*) { WEBKIT_ASSERT_NOT_REACHED(); } |
+ virtual void decrypt(const WebCryptoAlgorithm&, const WebCryptoKey&, const unsigned char* data, size_t data_size, WebCryptoOperationResult*) { WEBKIT_ASSERT_NOT_REACHED(); } |
+ virtual void sign(const WebCryptoAlgorithm&, const WebCryptoKey&, const unsigned char* data, size_t data_size, WebCryptoOperationResult*) { WEBKIT_ASSERT_NOT_REACHED(); } |
+ virtual void verifySignature(const WebCryptoAlgorithm&, const WebCryptoKey&, const unsigned char* signature, size_t signature_size, const unsigned char* data, size_t data_size, WebCryptoOperationResult*) { WEBKIT_ASSERT_NOT_REACHED(); } |
+ virtual void digest(const WebCryptoAlgorithm&, const unsigned char* data, size_t data_size, WebCryptoOperationResult*) { WEBKIT_ASSERT_NOT_REACHED(); } |
+ virtual void generateKey(const WebCryptoAlgorithm&, bool extractable, WebCryptoKeyUsageMask, WebCryptoOperationResult*) { WEBKIT_ASSERT_NOT_REACHED(); } |
+ virtual void importKey(WebCryptoKeyFormat, const unsigned char* keyData, size_t keyDataSize, const WebCryptoAlgorithm&, bool extractable, WebCryptoKeyUsageMask, WebCryptoOperationResult*) { WEBKIT_ASSERT_NOT_REACHED(); } |
protected: |
- virtual ~WebCryptoOperation() { } |
-}; |
- |
-// Can be implemented by embedder for unit-testing. |
-class WebCryptoOperationResultPrivate { |
-public: |
- virtual ~WebCryptoOperationResultPrivate() { } |
- |
- virtual void initializationFailed() = 0; |
- virtual void initializationSucceeded(WebCryptoOperation*) = 0; |
- virtual void completeWithError() = 0; |
- virtual void completeWithArrayBuffer(const WebArrayBuffer&) = 0; |
- virtual void completeWithBoolean(bool) = 0; |
- |
- virtual void ref() = 0; |
- virtual void deref() = 0; |
-}; |
- |
-// FIXME: Add error types. |
-class WebCryptoOperationResult { |
-public: |
- explicit WebCryptoOperationResult(WebCryptoOperationResultPrivate* impl) |
- { |
- assign(impl); |
- } |
- |
- ~WebCryptoOperationResult() { reset(); } |
- |
- WebCryptoOperationResult(const WebCryptoOperationResult& o) |
- { |
- assign(o); |
- } |
- |
- WebCryptoOperationResult& operator=(const WebCryptoOperationResult& o) |
- { |
- assign(o); |
- return *this; |
- } |
- |
- WEBKIT_EXPORT void initializationFailed(); |
- WEBKIT_EXPORT void initializationSucceeded(WebCryptoOperation*); |
- WEBKIT_EXPORT void completeWithError(); |
- WEBKIT_EXPORT void completeWithArrayBuffer(const WebArrayBuffer&); |
- WEBKIT_EXPORT void completeWithBoolean(bool); |
- |
-private: |
- WEBKIT_EXPORT void reset(); |
- WEBKIT_EXPORT void assign(const WebCryptoOperationResult&); |
- WEBKIT_EXPORT void assign(WebCryptoOperationResultPrivate*); |
- |
- WebPrivatePtr<WebCryptoOperationResultPrivate> m_impl; |
-}; |
- |
-class WebCryptoKeyOperation { |
-public: |
- // Cancels the in-progress operation. |
- // * Implementations should delete |this| after aborting. |
- virtual void abort() = 0; |
- |
-protected: |
- virtual ~WebCryptoKeyOperation() { } |
-}; |
- |
-// Can be implemented by embedder for unit-testing. |
-class WebCryptoKeyOperationResultPrivate { |
-public: |
- virtual ~WebCryptoKeyOperationResultPrivate() { } |
- |
- virtual void initializationFailed() = 0; |
- virtual void initializationSucceeded(WebCryptoKeyOperation*) = 0; |
- virtual void completeWithError() = 0; |
- virtual void completeWithKey(const WebCryptoKey&) = 0; |
- |
- virtual void ref() = 0; |
- virtual void deref() = 0; |
-}; |
- |
-class WebCryptoKeyOperationResult { |
-public: |
- explicit WebCryptoKeyOperationResult(WebCryptoKeyOperationResultPrivate* impl) |
- { |
- assign(impl); |
- } |
- |
- ~WebCryptoKeyOperationResult() { reset(); } |
- |
- WebCryptoKeyOperationResult(const WebCryptoKeyOperationResult& o) |
- { |
- assign(o); |
- } |
- |
- WebCryptoKeyOperationResult& operator=(const WebCryptoKeyOperationResult& o) |
- { |
- assign(o); |
- return *this; |
- } |
- |
- WEBKIT_EXPORT void initializationFailed(); |
- WEBKIT_EXPORT void initializationSucceeded(WebCryptoKeyOperation*); |
- |
- WEBKIT_EXPORT void completeWithError(); |
- WEBKIT_EXPORT void completeWithKey(const WebCryptoKey&); |
- |
-private: |
- WEBKIT_EXPORT void reset(); |
- WEBKIT_EXPORT void assign(const WebCryptoKeyOperationResult&); |
- WEBKIT_EXPORT void assign(WebCryptoKeyOperationResultPrivate*); |
- |
- WebPrivatePtr<WebCryptoKeyOperationResultPrivate> m_impl; |
+ virtual ~WebCrypto() { } |
}; |
} // namespace WebKit |