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

Side by Side Diff: components/client_update_protocol/ecdsa.cc

Issue 1921973002: Convert //components/[a-e]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/client_update_protocol/ecdsa.h" 5 #include "components/client_update_protocol/ecdsa.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "crypto/random.h" 14 #include "crypto/random.h"
15 #include "crypto/sha2.h" 15 #include "crypto/sha2.h"
16 #include "crypto/signature_verifier.h" 16 #include "crypto/signature_verifier.h"
17 17
18 namespace client_update_protocol { 18 namespace client_update_protocol {
19 19
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 } // namespace 85 } // namespace
86 86
87 Ecdsa::Ecdsa(int key_version, const base::StringPiece& public_key) 87 Ecdsa::Ecdsa(int key_version, const base::StringPiece& public_key)
88 : pub_key_version_(key_version), 88 : pub_key_version_(key_version),
89 public_key_(public_key.begin(), public_key.end()) {} 89 public_key_(public_key.begin(), public_key.end()) {}
90 90
91 Ecdsa::~Ecdsa() {} 91 Ecdsa::~Ecdsa() {}
92 92
93 scoped_ptr<Ecdsa> Ecdsa::Create(int key_version, 93 std::unique_ptr<Ecdsa> Ecdsa::Create(int key_version,
94 const base::StringPiece& public_key) { 94 const base::StringPiece& public_key) {
95 DCHECK_GT(key_version, 0); 95 DCHECK_GT(key_version, 0);
96 DCHECK(!public_key.empty()); 96 DCHECK(!public_key.empty());
97 97
98 return make_scoped_ptr(new Ecdsa(key_version, public_key)); 98 return base::WrapUnique(new Ecdsa(key_version, public_key));
99 } 99 }
100 100
101 void Ecdsa::SignRequest(const base::StringPiece& request_body, 101 void Ecdsa::SignRequest(const base::StringPiece& request_body,
102 std::string* query_params) { 102 std::string* query_params) {
103 DCHECK(!request_body.empty()); 103 DCHECK(!request_body.empty());
104 DCHECK(query_params); 104 DCHECK(query_params);
105 105
106 // Generate a random nonce to use for freshness, build the cup2key query 106 // Generate a random nonce to use for freshness, build the cup2key query
107 // string, and compute the SHA-256 hash of the request body. Set these 107 // string, and compute the SHA-256 hash of the request body. Set these
108 // two pieces of data aside to use during ValidateResponse(). 108 // two pieces of data aside to use during ValidateResponse().
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // * The signature was modified 178 // * The signature was modified
179 // * The buffer that the server signed does not match the buffer that the 179 // * The buffer that the server signed does not match the buffer that the
180 // client assembled -- implying that either request body or response body 180 // client assembled -- implying that either request body or response body
181 // was modified, or a different nonce value was used. 181 // was modified, or a different nonce value was used.
182 verifier.VerifyUpdate(&signed_message_hash.front(), 182 verifier.VerifyUpdate(&signed_message_hash.front(),
183 static_cast<int>(signed_message_hash.size())); 183 static_cast<int>(signed_message_hash.size()));
184 return verifier.VerifyFinal(); 184 return verifier.VerifyFinal();
185 } 185 }
186 186
187 } // namespace client_update_protocol 187 } // namespace client_update_protocol
OLDNEW
« no previous file with comments | « components/client_update_protocol/ecdsa.h ('k') | components/client_update_protocol/ecdsa_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698