Index: Source/modules/crypto/SubtleCrypto.cpp |
diff --git a/Source/modules/crypto/SubtleCrypto.cpp b/Source/modules/crypto/SubtleCrypto.cpp |
index cf30ddd50fa4b77964f14a94c0749893c7d31525..ee6d07461ae1dafbd7b285a9e016ef75dd738a36 100644 |
--- a/Source/modules/crypto/SubtleCrypto.cpp |
+++ b/Source/modules/crypto/SubtleCrypto.cpp |
@@ -26,18 +26,70 @@ |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
- |
#include "config.h" |
#include "modules/crypto/SubtleCrypto.h" |
#include "core/dom/ExceptionCode.h" |
#include "modules/crypto/CryptoOperation.h" |
#include "modules/crypto/NormalizeAlgorithm.h" |
+#include "public/platform/WebArrayBuffer.h" // FIXME: temporary |
+#include "public/platform/WebCrypto.h" |
#include "wtf/ArrayBuffer.h" |
#include "wtf/ArrayBufferView.h" |
+#include "wtf/SHA1.h" // FIXME: temporary |
+ |
namespace WebCore { |
+namespace { |
+ |
+// FIXME: The following are temporary implementations of what *should* go on the |
+// embedder's side. Since SHA1 is easily implemented, this serves as |
+// a useful proof of concept to get layout tests up and running and |
+// returning correct results, until the embedder's side is implemented. |
+//------------------------------------------------------------------------------ |
+class DummyOperation : public WebKit::WebCryptoOperation { |
+public: |
+ virtual void process(const unsigned char* bytes, size_t size) OVERRIDE |
+ { |
+ ASSERT_NOT_REACHED(); |
+ } |
+ virtual void abort() OVERRIDE |
+ { |
+ delete this; |
+ } |
+ virtual void finish(WebKit::WebCryptoOperationResult* result) OVERRIDE |
+ { |
+ ASSERT_NOT_REACHED(); |
+ } |
+}; |
+ |
+class MockSha1Operation : public DummyOperation { |
+public: |
+ virtual void process(const unsigned char* bytes, size_t size) OVERRIDE |
+ { |
+ m_sha1.addBytes(bytes, size); |
+ } |
+ |
+ virtual void finish(WebKit::WebCryptoOperationResult* result) OVERRIDE |
+ { |
+ Vector<uint8_t, 20> hash; |
+ m_sha1.computeHash(hash); |
+ |
+ WebKit::WebArrayBuffer buffer = WebKit::WebArrayBuffer::create(hash.size(), 1); |
+ memcpy(buffer.data(), hash.data(), hash.size()); |
+ |
+ result->setArrayBuffer(buffer); |
+ delete this; |
+ } |
+ |
+private: |
+ SHA1 m_sha1; |
+}; |
+//------------------------------------------------------------------------------ |
+ |
+} // namespace |
+ |
SubtleCrypto::SubtleCrypto() |
{ |
ScriptWrappable::init(this); |
@@ -48,7 +100,7 @@ PassRefPtr<CryptoOperation> SubtleCrypto::encrypt(const Dictionary& rawAlgorithm |
WebKit::WebCryptoAlgorithm algorithm; |
if (!normalizeAlgorithm(rawAlgorithm, Encrypt, algorithm, ec)) |
return 0; |
- return CryptoOperation::create(algorithm); |
+ return CryptoOperation::create(algorithm, new DummyOperation); |
} |
PassRefPtr<CryptoOperation> SubtleCrypto::decrypt(const Dictionary& rawAlgorithm, ExceptionCode& ec) |
@@ -56,7 +108,7 @@ PassRefPtr<CryptoOperation> SubtleCrypto::decrypt(const Dictionary& rawAlgorithm |
WebKit::WebCryptoAlgorithm algorithm; |
if (!normalizeAlgorithm(rawAlgorithm, Decrypt, algorithm, ec)) |
return 0; |
- return CryptoOperation::create(algorithm); |
+ return CryptoOperation::create(algorithm, new DummyOperation); |
} |
PassRefPtr<CryptoOperation> SubtleCrypto::sign(const Dictionary& rawAlgorithm, ExceptionCode& ec) |
@@ -64,7 +116,7 @@ PassRefPtr<CryptoOperation> SubtleCrypto::sign(const Dictionary& rawAlgorithm, E |
WebKit::WebCryptoAlgorithm algorithm; |
if (!normalizeAlgorithm(rawAlgorithm, Sign, algorithm, ec)) |
return 0; |
- return CryptoOperation::create(algorithm); |
+ return CryptoOperation::create(algorithm, new DummyOperation); |
} |
PassRefPtr<CryptoOperation> SubtleCrypto::verifySignature(const Dictionary& rawAlgorithm, ExceptionCode& ec) |
@@ -72,7 +124,7 @@ PassRefPtr<CryptoOperation> SubtleCrypto::verifySignature(const Dictionary& rawA |
WebKit::WebCryptoAlgorithm algorithm; |
if (!normalizeAlgorithm(rawAlgorithm, Verify, algorithm, ec)) |
return 0; |
- return CryptoOperation::create(algorithm); |
+ return CryptoOperation::create(algorithm, new DummyOperation); |
} |
PassRefPtr<CryptoOperation> SubtleCrypto::digest(const Dictionary& rawAlgorithm, ExceptionCode& ec) |
@@ -80,7 +132,12 @@ PassRefPtr<CryptoOperation> SubtleCrypto::digest(const Dictionary& rawAlgorithm, |
WebKit::WebCryptoAlgorithm algorithm; |
if (!normalizeAlgorithm(rawAlgorithm, Digest, algorithm, ec)) |
return 0; |
- return CryptoOperation::create(algorithm); |
+ |
+ // FIXME: Create the WebCryptoImplementation by calling out to |
+ // Platform::crypto() instead. |
+ WebKit::WebCryptoOperation* operationImpl = algorithm.id() == WebKit::WebCryptoAlgorithmIdSha1 ? new MockSha1Operation : new DummyOperation; |
+ |
+ return CryptoOperation::create(algorithm, operationImpl); |
} |
} // namespace WebCore |