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

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

Issue 1866243002: Convert //sync from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 key->mutable_encryption_key(), 157 key->mutable_encryption_key(),
158 key->mutable_mac_key()); 158 key->mutable_mac_key());
159 } 159 }
160 160
161 // Encrypt the bag with the default Nigori. 161 // Encrypt the bag with the default Nigori.
162 return Encrypt(bag, encrypted); 162 return Encrypt(bag, encrypted);
163 } 163 }
164 164
165 bool Cryptographer::AddKey(const KeyParams& params) { 165 bool Cryptographer::AddKey(const KeyParams& params) {
166 // Create the new Nigori and make it the default encryptor. 166 // Create the new Nigori and make it the default encryptor.
167 scoped_ptr<Nigori> nigori(new Nigori); 167 std::unique_ptr<Nigori> nigori(new Nigori);
168 if (!nigori->InitByDerivation(params.hostname, 168 if (!nigori->InitByDerivation(params.hostname,
169 params.username, 169 params.username,
170 params.password)) { 170 params.password)) {
171 NOTREACHED(); // Invalid username or password. 171 NOTREACHED(); // Invalid username or password.
172 return false; 172 return false;
173 } 173 }
174 return AddKeyImpl(std::move(nigori), true); 174 return AddKeyImpl(std::move(nigori), true);
175 } 175 }
176 176
177 bool Cryptographer::AddNonDefaultKey(const KeyParams& params) { 177 bool Cryptographer::AddNonDefaultKey(const KeyParams& params) {
178 DCHECK(is_initialized()); 178 DCHECK(is_initialized());
179 // Create the new Nigori and add it to the keybag. 179 // Create the new Nigori and add it to the keybag.
180 scoped_ptr<Nigori> nigori(new Nigori); 180 std::unique_ptr<Nigori> nigori(new Nigori);
181 if (!nigori->InitByDerivation(params.hostname, 181 if (!nigori->InitByDerivation(params.hostname,
182 params.username, 182 params.username,
183 params.password)) { 183 params.password)) {
184 NOTREACHED(); // Invalid username or password. 184 NOTREACHED(); // Invalid username or password.
185 return false; 185 return false;
186 } 186 }
187 return AddKeyImpl(std::move(nigori), false); 187 return AddKeyImpl(std::move(nigori), false);
188 } 188 }
189 189
190 bool Cryptographer::AddKeyFromBootstrapToken( 190 bool Cryptographer::AddKeyFromBootstrapToken(
191 const std::string& restored_bootstrap_token) { 191 const std::string& restored_bootstrap_token) {
192 // Create the new Nigori and make it the default encryptor. 192 // Create the new Nigori and make it the default encryptor.
193 std::string serialized_nigori_key = UnpackBootstrapToken( 193 std::string serialized_nigori_key = UnpackBootstrapToken(
194 restored_bootstrap_token); 194 restored_bootstrap_token);
195 return ImportNigoriKey(serialized_nigori_key); 195 return ImportNigoriKey(serialized_nigori_key);
196 } 196 }
197 197
198 bool Cryptographer::AddKeyImpl(scoped_ptr<Nigori> initialized_nigori, 198 bool Cryptographer::AddKeyImpl(std::unique_ptr<Nigori> initialized_nigori,
199 bool set_as_default) { 199 bool set_as_default) {
200 std::string name; 200 std::string name;
201 if (!initialized_nigori->Permute(Nigori::Password, kNigoriKeyName, &name)) { 201 if (!initialized_nigori->Permute(Nigori::Password, kNigoriKeyName, &name)) {
202 NOTREACHED(); 202 NOTREACHED();
203 return false; 203 return false;
204 } 204 }
205 205
206 nigoris_[name] = make_linked_ptr(initialized_nigori.release()); 206 nigoris_[name] = make_linked_ptr(initialized_nigori.release());
207 207
208 // Check if the key we just added can decrypt the pending keys and add them 208 // Check if the key we just added can decrypt the pending keys and add them
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 304 }
305 return unencrypted_token; 305 return unencrypted_token;
306 } 306 }
307 307
308 void Cryptographer::InstallKeyBag(const sync_pb::NigoriKeyBag& bag) { 308 void Cryptographer::InstallKeyBag(const sync_pb::NigoriKeyBag& bag) {
309 int key_size = bag.key_size(); 309 int key_size = bag.key_size();
310 for (int i = 0; i < key_size; ++i) { 310 for (int i = 0; i < key_size; ++i) {
311 const sync_pb::NigoriKey key = bag.key(i); 311 const sync_pb::NigoriKey key = bag.key(i);
312 // Only use this key if we don't already know about it. 312 // Only use this key if we don't already know about it.
313 if (nigoris_.end() == nigoris_.find(key.name())) { 313 if (nigoris_.end() == nigoris_.find(key.name())) {
314 scoped_ptr<Nigori> new_nigori(new Nigori); 314 std::unique_ptr<Nigori> new_nigori(new Nigori);
315 if (!new_nigori->InitByImport(key.user_key(), 315 if (!new_nigori->InitByImport(key.user_key(),
316 key.encryption_key(), 316 key.encryption_key(),
317 key.mac_key())) { 317 key.mac_key())) {
318 NOTREACHED(); 318 NOTREACHED();
319 continue; 319 continue;
320 } 320 }
321 nigoris_[key.name()] = make_linked_ptr(new_nigori.release()); 321 nigoris_[key.name()] = make_linked_ptr(new_nigori.release());
322 } 322 }
323 } 323 }
324 } 324 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 363 }
364 364
365 bool Cryptographer::ImportNigoriKey(const std::string& serialized_nigori_key) { 365 bool Cryptographer::ImportNigoriKey(const std::string& serialized_nigori_key) {
366 if (serialized_nigori_key.empty()) 366 if (serialized_nigori_key.empty())
367 return false; 367 return false;
368 368
369 sync_pb::NigoriKey key; 369 sync_pb::NigoriKey key;
370 if (!key.ParseFromString(serialized_nigori_key)) 370 if (!key.ParseFromString(serialized_nigori_key))
371 return false; 371 return false;
372 372
373 scoped_ptr<Nigori> nigori(new Nigori); 373 std::unique_ptr<Nigori> nigori(new Nigori);
374 if (!nigori->InitByImport(key.user_key(), key.encryption_key(), 374 if (!nigori->InitByImport(key.user_key(), key.encryption_key(),
375 key.mac_key())) { 375 key.mac_key())) {
376 NOTREACHED(); 376 NOTREACHED();
377 return false; 377 return false;
378 } 378 }
379 379
380 if (!AddKeyImpl(std::move(nigori), true)) 380 if (!AddKeyImpl(std::move(nigori), true))
381 return false; 381 return false;
382 return true; 382 return true;
383 } 383 }
384 384
385 } // namespace syncer 385 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698