Chromium Code Reviews| Index: Source/platform/CryptoUtilities.cpp |
| diff --git a/Source/modules/crypto/Crypto.h b/Source/platform/CryptoUtilities.cpp |
| similarity index 52% |
| copy from Source/modules/crypto/Crypto.h |
| copy to Source/platform/CryptoUtilities.cpp |
| index d78d9de1e6f3bda38ea495729ef9ea7385afb5a7..9ba049ed1f14ddbb31f1b5d300878782044a40ac 100644 |
| --- a/Source/modules/crypto/Crypto.h |
| +++ b/Source/platform/CryptoUtilities.cpp |
| @@ -1,5 +1,5 @@ |
| /* |
| - * Copyright (C) 2011 Google Inc. All rights reserved. |
| + * Copyright (C) 2014 Google Inc. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions |
| @@ -26,36 +26,49 @@ |
| * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| -#ifndef Crypto_h |
| -#define Crypto_h |
| +#include "config.h" |
| +#include "platform/CryptoUtilities.h" |
| -#include "bindings/v8/ScriptWrappable.h" |
| -#include "heap/Handle.h" |
| -#include "modules/crypto/SubtleCrypto.h" |
| -#include "wtf/Forward.h" |
| -#include "wtf/RefCounted.h" |
| -#include "wtf/RefPtr.h" |
| +#include "public/platform/Platform.h" |
| +#include "public/platform/WebArrayBuffer.h" |
| +#include "public/platform/WebCrypto.h" |
| +#include "public/platform/WebCryptoAlgorithm.h" |
| +#include "wtf/Vector.h" |
| +#include "wtf/text/CString.h" |
| namespace WebCore { |
| +namespace CryptoUtil { |
| -class ExceptionState; |
| +static blink::WebCryptoAlgorithmId convertHashAlgorithm(HashAlgorithm algorithm) |
| +{ |
| + switch (algorithm) { |
| + case HashAlgorithmSha1: |
| + return blink::WebCryptoAlgorithmIdSha1; |
| + case HashAlgorithmSha256: |
| + return blink::WebCryptoAlgorithmIdSha256; |
| + case HashAlgorithmSha384: |
| + return blink::WebCryptoAlgorithmIdSha384; |
| + case HashAlgorithmSha512: |
| + return blink::WebCryptoAlgorithmIdSha512; |
| + }; |
| -class Crypto : public RefCountedWillBeGarbageCollectedFinalized<Crypto>, public ScriptWrappable { |
| -public: |
| - static PassRefPtrWillBeRawPtr<Crypto> create() { return adoptRefWillBeNoop(new Crypto()); } |
| - |
| - static void getRandomValues(ArrayBufferView*, ExceptionState&); |
| + ASSERT_NOT_REACHED(); |
| +} |
| - SubtleCrypto* subtle(); |
| +void computeDigest(HashAlgorithm algorithm, const char* digestable, size_t length, DigestValue& digestResult) |
| +{ |
| + blink::WebCryptoAlgorithmId algorithmId = convertHashAlgorithm(algorithm); |
| + blink::WebCrypto* crypto = blink::Platform::current()->crypto(); |
| + blink::WebArrayBuffer result; |
| - void trace(Visitor*); |
| + ASSERT(crypto); |
| -private: |
| - Crypto(); |
| + crypto->digestSynchronous(algorithmId, reinterpret_cast<const unsigned char*>(digestable), length, result); |
| - RefPtrWillBeMember<SubtleCrypto> m_subtleCrypto; |
| -}; |
| + ASSERT(!result.isNull()); |
| + digestResult.append(reinterpret_cast<uint8_t*>(result.data()), result.byteLength()); |
|
eseidel
2014/03/12 06:50:29
Do we need this reinterpret_cast?
jww
2014/04/01 23:29:09
It actually can be a static_cast, which I assume i
|
| } |
| -#endif |
| +} // namespace CryptoUtil |
| +} // namespace WebCore |