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

Side by Side 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, 8 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 unified diff | Download patch
« no previous file with comments | « Source/platform/Crypto.h ('k') | Source/platform/blink_platform.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "platform/Crypto.h"
7
8 #include "public/platform/Platform.h"
9 #include "public/platform/WebArrayBuffer.h"
10 #include "public/platform/WebCrypto.h"
11 #include "public/platform/WebCryptoAlgorithm.h"
12 #include "wtf/Vector.h"
13 #include "wtf/text/CString.h"
14
15 namespace WebCore {
16
17 static blink::WebCryptoAlgorithmId toWebCryptoAlgorithmId(HashAlgorithm algorith m)
18 {
19 switch (algorithm) {
20 case HashAlgorithmSha1:
21 return blink::WebCryptoAlgorithmIdSha1;
22 case HashAlgorithmSha256:
23 return blink::WebCryptoAlgorithmIdSha256;
24 case HashAlgorithmSha384:
25 return blink::WebCryptoAlgorithmIdSha384;
26 case HashAlgorithmSha512:
27 return blink::WebCryptoAlgorithmIdSha512;
28 };
29
30 ASSERT_NOT_REACHED();
31 return blink::WebCryptoAlgorithmIdSha256;
32 }
33
34 void computeDigest(HashAlgorithm algorithm, const char* digestable, size_t lengt h, DigestValue& digestResult)
35 {
36 blink::WebCryptoAlgorithmId algorithmId = toWebCryptoAlgorithmId(algorithm);
37 blink::WebCrypto* crypto = blink::Platform::current()->crypto();
38 blink::WebArrayBuffer result;
39
40 ASSERT(crypto);
41
42 crypto->digestSynchronous(algorithmId, reinterpret_cast<const unsigned char* >(digestable), length, result);
43
44 ASSERT(!result.isNull());
45
46 digestResult.append(static_cast<uint8_t*>(result.data()), result.byteLength( ));
47 }
48
49 PassOwnPtr<blink::WebCryptoDigestor> createDigestor(HashAlgorithm algorithm)
50 {
51 return adoptPtr(blink::Platform::current()->crypto()->createDigestor(toWebCr yptoAlgorithmId(algorithm)));
52 }
53
54 void finishDigestor(blink::WebCryptoDigestor* digestor, DigestValue& digestResul t)
55 {
56 unsigned char* result = 0;
57 unsigned resultSize = 0;
58
59 if (!digestor->finish(result, resultSize))
60 return;
61
62 ASSERT(result);
63
64 digestResult.append(static_cast<uint8_t*>(result), resultSize);
65 }
66
67 } // namespace WebCore
OLDNEW
« 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