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

Side by Side Diff: crypto/secure_hash.cc

Issue 2095523002: Make //crypto factories return std::unique_ptr<>s (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: I'm blind 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
« no previous file with comments | « crypto/secure_hash.h ('k') | crypto/signature_creator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "crypto/secure_hash.h" 5 #include "crypto/secure_hash.h"
6 6
7 #include <openssl/mem.h> 7 #include <openssl/mem.h>
8 #include <openssl/sha.h> 8 #include <openssl/sha.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h"
12 #include "base/pickle.h" 13 #include "base/pickle.h"
13 #include "crypto/openssl_util.h" 14 #include "crypto/openssl_util.h"
14 15
15 namespace crypto { 16 namespace crypto {
16 17
17 namespace { 18 namespace {
18 19
19 class SecureHashSHA256 : public SecureHash { 20 class SecureHashSHA256 : public SecureHash {
20 public: 21 public:
21 SecureHashSHA256() { 22 SecureHashSHA256() {
(...skipping 11 matching lines...) Expand all
33 void Update(const void* input, size_t len) override { 34 void Update(const void* input, size_t len) override {
34 SHA256_Update(&ctx_, static_cast<const unsigned char*>(input), len); 35 SHA256_Update(&ctx_, static_cast<const unsigned char*>(input), len);
35 } 36 }
36 37
37 void Finish(void* output, size_t len) override { 38 void Finish(void* output, size_t len) override {
38 ScopedOpenSSLSafeSizeBuffer<SHA256_DIGEST_LENGTH> result( 39 ScopedOpenSSLSafeSizeBuffer<SHA256_DIGEST_LENGTH> result(
39 static_cast<unsigned char*>(output), len); 40 static_cast<unsigned char*>(output), len);
40 SHA256_Final(result.safe_buffer(), &ctx_); 41 SHA256_Final(result.safe_buffer(), &ctx_);
41 } 42 }
42 43
43 SecureHash* Clone() const override { 44 std::unique_ptr<SecureHash> Clone() const override {
44 return new SecureHashSHA256(*this); 45 return base::MakeUnique<SecureHashSHA256>(*this);
45 } 46 }
46 47
47 size_t GetHashLength() const override { return SHA256_DIGEST_LENGTH; } 48 size_t GetHashLength() const override { return SHA256_DIGEST_LENGTH; }
48 49
49 private: 50 private:
50 SHA256_CTX ctx_; 51 SHA256_CTX ctx_;
51 }; 52 };
52 53
53 } // namespace 54 } // namespace
54 55
55 SecureHash* SecureHash::Create(Algorithm algorithm) { 56 std::unique_ptr<SecureHash> SecureHash::Create(Algorithm algorithm) {
56 switch (algorithm) { 57 switch (algorithm) {
57 case SHA256: 58 case SHA256:
58 return new SecureHashSHA256(); 59 return base::MakeUnique<SecureHashSHA256>();
59 default: 60 default:
60 NOTIMPLEMENTED(); 61 NOTIMPLEMENTED();
61 return NULL; 62 return nullptr;
62 } 63 }
63 } 64 }
64 65
65 } // namespace crypto 66 } // namespace crypto
OLDNEW
« no previous file with comments | « crypto/secure_hash.h ('k') | crypto/signature_creator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698