| Index: public/platform/WebCrypto.h
|
| diff --git a/public/platform/WebCrypto.h b/public/platform/WebCrypto.h
|
| index 4b091d16929eccbd290a3af61ec04e6ba0eb4b08..f11bcbd940da6cd6377a4a0c8fb9a0f49518814f 100644
|
| --- a/public/platform/WebCrypto.h
|
| +++ b/public/platform/WebCrypto.h
|
| @@ -32,12 +32,14 @@
|
| #define WebCrypto_h
|
|
|
| #include "WebCommon.h"
|
| +#include "WebCryptoKey.h"
|
| +#include "WebPrivatePtr.h"
|
|
|
| namespace WebKit {
|
|
|
| class WebArrayBuffer;
|
| -class WebCryptoAlgorithm;
|
| -class WebCryptoKey;
|
| +class WebCryptoKeyOperation;
|
| +class WebCryptoKeyOperationResult;
|
| class WebCryptoOperation;
|
| class WebCryptoOperationResult;
|
|
|
| @@ -49,17 +51,17 @@ public:
|
| // The following methods begin an asynchronous multi-part cryptographic
|
| // operation.
|
| //
|
| - // Let the WebCryptoOperationResult* be called "result".
|
| + // Let the WebCryptoOperationResult& be called "result".
|
| //
|
| - // Implementations can either:
|
| + // Before returning, implementations can either:
|
| //
|
| // * Synchronously fail initialization by calling:
|
| - // result->initializationFailed(errorDetails)
|
| + // result.initializationFailed(errorDetails)
|
| //
|
| // OR
|
| //
|
| // * Create a new WebCryptoOperation* and return it by calling:
|
| - // result->initializationSucceeded(cryptoOperation)
|
| + // result.initializationSucceeded(cryptoOperation)
|
| //
|
| // If initialization succeeds, then Blink will subsequently call
|
| // methods on cryptoOperation:
|
| @@ -68,10 +70,11 @@ public:
|
| // - 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". 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 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
|
| @@ -79,12 +82,43 @@ public:
|
| //
|
| // - Blink calls cryptoOperation->abort()
|
| // OR
|
| - // - Embedder calls result->completeWithXXX()
|
| + // - Embedder calls result.completeWithXXX()
|
| //
|
| - // Once the cryptoOperation is no longer "in progress" the "result" pointer
|
| - // is no longer valid. At this time the embedder is responsible for freeing
|
| - // the cryptoOperation.
|
| - virtual void digest(const WebCryptoAlgorithm&, WebCryptoOperationResult*) { }
|
| + // Once the cryptoOperation is no longer "in progress" the embedder is
|
| + // responsible for freeing the cryptoOperation.
|
| + virtual void digest(const WebCryptoAlgorithm&, WebCryptoOperationResult&) { }
|
| +
|
| + // 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)
|
| + //
|
| + // 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 importKey(WebCryptoKeyFormat, const unsigned char* keyData, size_t keyDataSize, const WebCryptoAlgorithm&, bool extractable, WebCryptoKeyUsageMask, WebCryptoKeyOperationResult&) { }
|
|
|
| protected:
|
| virtual ~WebCrypto() { }
|
| @@ -109,19 +143,110 @@ protected:
|
| virtual ~WebCryptoOperation() { }
|
| };
|
|
|
| -// FIXME: Add error types.
|
| -class WebCryptoOperationResult {
|
| +// Can be implemented by embedder for unit-testing.
|
| +class WebCryptoOperationResultPrivate {
|
| public:
|
| - // Only one of these should be called.
|
| - virtual void initializationFailed() = 0;
|
| - virtual void initializationSucceded(WebCryptoOperation*) = 0;
|
| + virtual ~WebCryptoOperationResultPrivate() { }
|
|
|
| - // Only one of these should be called to set the result.
|
| + virtual void initializationFailed() = 0;
|
| + virtual void initializationSucceeded(WebCryptoOperation*) = 0;
|
| virtual void completeWithError() = 0;
|
| virtual void completeWithArrayBuffer(const WebArrayBuffer&) = 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&);
|
| +
|
| +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 ~WebCryptoOperationResult() { }
|
| + 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;
|
| };
|
|
|
| } // namespace WebKit
|
|
|