Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2459)

Unified Diff: Source/platform/Crypto.cpp

Issue 189373010: Get rid of WTF::SHA1. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase on ToT and fixed header guard collision. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/Crypto.h ('k') | Source/platform/blink_platform.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/Crypto.cpp
diff --git a/Source/platform/Crypto.cpp b/Source/platform/Crypto.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d168583acd616be8f4f6b272a9ce20de0ddd148b
--- /dev/null
+++ b/Source/platform/Crypto.cpp
@@ -0,0 +1,67 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "platform/Crypto.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 {
+
+static blink::WebCryptoAlgorithmId toWebCryptoAlgorithmId(HashAlgorithm algorithm)
+{
+ switch (algorithm) {
+ case HashAlgorithmSha1:
+ return blink::WebCryptoAlgorithmIdSha1;
+ case HashAlgorithmSha256:
+ return blink::WebCryptoAlgorithmIdSha256;
+ case HashAlgorithmSha384:
+ return blink::WebCryptoAlgorithmIdSha384;
+ case HashAlgorithmSha512:
+ return blink::WebCryptoAlgorithmIdSha512;
+ };
+
+ ASSERT_NOT_REACHED();
+ return blink::WebCryptoAlgorithmIdSha256;
+}
+
+void computeDigest(HashAlgorithm algorithm, const char* digestable, size_t length, DigestValue& digestResult)
+{
+ blink::WebCryptoAlgorithmId algorithmId = toWebCryptoAlgorithmId(algorithm);
+ blink::WebCrypto* crypto = blink::Platform::current()->crypto();
+ blink::WebArrayBuffer result;
+
+ ASSERT(crypto);
+
+ crypto->digestSynchronous(algorithmId, reinterpret_cast<const unsigned char*>(digestable), length, result);
+
+ ASSERT(!result.isNull());
+
+ digestResult.append(static_cast<uint8_t*>(result.data()), result.byteLength());
+}
+
+PassOwnPtr<blink::WebCryptoDigestor> createDigestor(HashAlgorithm algorithm)
+{
+ return adoptPtr(blink::Platform::current()->crypto()->createDigestor(toWebCryptoAlgorithmId(algorithm)));
+}
+
+void finishDigestor(blink::WebCryptoDigestor* digestor, DigestValue& digestResult)
+{
+ unsigned char* result = 0;
+ unsigned resultSize = 0;
+
+ if (!digestor->finish(result, resultSize))
+ return;
+
+ ASSERT(result);
+
+ digestResult.append(static_cast<uint8_t*>(result), resultSize);
+}
+
+} // namespace WebCore
« no previous file with comments | « Source/platform/Crypto.h ('k') | Source/platform/blink_platform.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698