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

Side by Side Diff: sync/util/cryptographer.cc

Issue 1349783006: Cleanup: Pass std::string as const reference if possible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert third_party changes Created 5 years, 3 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 (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 "sync/util/cryptographer.h" 5 #include "sync/util/cryptographer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 if (!nigori->InitByDerivation(params.hostname, 180 if (!nigori->InitByDerivation(params.hostname,
181 params.username, 181 params.username,
182 params.password)) { 182 params.password)) {
183 NOTREACHED(); // Invalid username or password. 183 NOTREACHED(); // Invalid username or password.
184 return false; 184 return false;
185 } 185 }
186 return AddKeyImpl(nigori.Pass(), false); 186 return AddKeyImpl(nigori.Pass(), false);
187 } 187 }
188 188
189 bool Cryptographer::AddKeyFromBootstrapToken( 189 bool Cryptographer::AddKeyFromBootstrapToken(
190 const std::string restored_bootstrap_token) { 190 const std::string& restored_bootstrap_token) {
191 // Create the new Nigori and make it the default encryptor. 191 // Create the new Nigori and make it the default encryptor.
192 std::string serialized_nigori_key = UnpackBootstrapToken( 192 std::string serialized_nigori_key = UnpackBootstrapToken(
193 restored_bootstrap_token); 193 restored_bootstrap_token);
194 return ImportNigoriKey(serialized_nigori_key); 194 return ImportNigoriKey(serialized_nigori_key);
195 } 195 }
196 196
197 bool Cryptographer::AddKeyImpl(scoped_ptr<Nigori> initialized_nigori, 197 bool Cryptographer::AddKeyImpl(scoped_ptr<Nigori> initialized_nigori,
198 bool set_as_default) { 198 bool set_as_default) {
199 std::string name; 199 std::string name;
200 if (!initialized_nigori->Permute(Nigori::Password, kNigoriKeyName, &name)) { 200 if (!initialized_nigori->Permute(Nigori::Password, kNigoriKeyName, &name)) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 if (iter == nigoris_.end()) 354 if (iter == nigoris_.end())
355 return std::string(); 355 return std::string();
356 sync_pb::NigoriKey key; 356 sync_pb::NigoriKey key;
357 if (!iter->second->ExportKeys(key.mutable_user_key(), 357 if (!iter->second->ExportKeys(key.mutable_user_key(),
358 key.mutable_encryption_key(), 358 key.mutable_encryption_key(),
359 key.mutable_mac_key())) 359 key.mutable_mac_key()))
360 return std::string(); 360 return std::string();
361 return key.SerializeAsString(); 361 return key.SerializeAsString();
362 } 362 }
363 363
364 bool Cryptographer::ImportNigoriKey(const std::string serialized_nigori_key) { 364 bool Cryptographer::ImportNigoriKey(const std::string& serialized_nigori_key) {
365 if (serialized_nigori_key.empty()) 365 if (serialized_nigori_key.empty())
366 return false; 366 return false;
367 367
368 sync_pb::NigoriKey key; 368 sync_pb::NigoriKey key;
369 if (!key.ParseFromString(serialized_nigori_key)) 369 if (!key.ParseFromString(serialized_nigori_key))
370 return false; 370 return false;
371 371
372 scoped_ptr<Nigori> nigori(new Nigori); 372 scoped_ptr<Nigori> nigori(new Nigori);
373 if (!nigori->InitByImport(key.user_key(), key.encryption_key(), 373 if (!nigori->InitByImport(key.user_key(), key.encryption_key(),
374 key.mac_key())) { 374 key.mac_key())) {
375 NOTREACHED(); 375 NOTREACHED();
376 return false; 376 return false;
377 } 377 }
378 378
379 if (!AddKeyImpl(nigori.Pass(), true)) 379 if (!AddKeyImpl(nigori.Pass(), true))
380 return false; 380 return false;
381 return true; 381 return true;
382 } 382 }
383 383
384 } // namespace syncer 384 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/util/cryptographer.h ('k') | testing/multiprocess_func_list.h » ('j') | url/gurl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698