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

Side by Side Diff: third_party/WebKit/Source/platform/Crypto.cpp

Issue 2142783002: Use std::unique_ptr to pass around WebCryptoDigestor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/Crypto.h" 5 #include "platform/Crypto.h"
6 6
7 #include "public/platform/Platform.h" 7 #include "public/platform/Platform.h"
8 #include "public/platform/WebCrypto.h" 8 #include "public/platform/WebCrypto.h"
9 #include "public/platform/WebCryptoAlgorithm.h" 9 #include "public/platform/WebCryptoAlgorithm.h"
10 #include "wtf/PtrUtil.h"
11 #include <memory> 10 #include <memory>
12 11
13 namespace blink { 12 namespace blink {
14 13
15 static WebCryptoAlgorithmId toWebCryptoAlgorithmId(HashAlgorithm algorithm) 14 static WebCryptoAlgorithmId toWebCryptoAlgorithmId(HashAlgorithm algorithm)
16 { 15 {
17 switch (algorithm) { 16 switch (algorithm) {
18 case HashAlgorithmSha1: 17 case HashAlgorithmSha1:
19 return WebCryptoAlgorithmIdSha1; 18 return WebCryptoAlgorithmIdSha1;
20 case HashAlgorithmSha256: 19 case HashAlgorithmSha256:
(...skipping 10 matching lines...) Expand all
31 30
32 bool computeDigest(HashAlgorithm algorithm, const char* digestable, size_t lengt h, DigestValue& digestResult) 31 bool computeDigest(HashAlgorithm algorithm, const char* digestable, size_t lengt h, DigestValue& digestResult)
33 { 32 {
34 WebCryptoAlgorithmId algorithmId = toWebCryptoAlgorithmId(algorithm); 33 WebCryptoAlgorithmId algorithmId = toWebCryptoAlgorithmId(algorithm);
35 WebCrypto* crypto = Platform::current()->crypto(); 34 WebCrypto* crypto = Platform::current()->crypto();
36 unsigned char* result; 35 unsigned char* result;
37 unsigned resultSize; 36 unsigned resultSize;
38 37
39 ASSERT(crypto); 38 ASSERT(crypto);
40 39
41 std::unique_ptr<WebCryptoDigestor> digestor = wrapUnique(crypto->createDiges tor(algorithmId)); 40 std::unique_ptr<WebCryptoDigestor> digestor = crypto->createDigestor(algorit hmId);
42 if (!digestor.get() || !digestor->consume(reinterpret_cast<const unsigned ch ar*>(digestable), length) || !digestor->finish(result, resultSize)) 41 DCHECK(digestor);
42 if (!digestor->consume(reinterpret_cast<const unsigned char*>(digestable), l ength) || !digestor->finish(result, resultSize))
43 return false; 43 return false;
44 44
45 digestResult.append(static_cast<uint8_t*>(result), resultSize); 45 digestResult.append(static_cast<uint8_t*>(result), resultSize);
46 return true; 46 return true;
47 } 47 }
48 48
49 std::unique_ptr<WebCryptoDigestor> createDigestor(HashAlgorithm algorithm) 49 std::unique_ptr<WebCryptoDigestor> createDigestor(HashAlgorithm algorithm)
50 { 50 {
51 return wrapUnique(Platform::current()->crypto()->createDigestor(toWebCryptoA lgorithmId(algorithm))); 51 return Platform::current()->crypto()->createDigestor(toWebCryptoAlgorithmId( algorithm));
52 } 52 }
53 53
54 void finishDigestor(WebCryptoDigestor* digestor, DigestValue& digestResult) 54 void finishDigestor(WebCryptoDigestor* digestor, DigestValue& digestResult)
55 { 55 {
56 unsigned char* result = 0; 56 unsigned char* result = 0;
57 unsigned resultSize = 0; 57 unsigned resultSize = 0;
58 58
59 if (!digestor->finish(result, resultSize)) 59 if (!digestor->finish(result, resultSize))
60 return; 60 return;
61 61
62 ASSERT(result); 62 ASSERT(result);
63 63
64 digestResult.append(static_cast<uint8_t*>(result), resultSize); 64 digestResult.append(static_cast<uint8_t*>(result), resultSize);
65 } 65 }
66 66
67 } // namespace blink 67 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/Crypto.h ('k') | third_party/WebKit/public/platform/WebCrypto.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698