OLD | NEW |
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 | |
9 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <utility> |
10 | 10 |
11 #include "base/base64.h" | 11 #include "base/base64.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "sync/protocol/nigori_specifics.pb.h" | 13 #include "sync/protocol/nigori_specifics.pb.h" |
14 #include "sync/util/encryptor.h" | 14 #include "sync/util/encryptor.h" |
15 | 15 |
16 namespace syncer { | 16 namespace syncer { |
17 | 17 |
18 const char kNigoriTag[] = "google_chrome_nigori"; | 18 const char kNigoriTag[] = "google_chrome_nigori"; |
19 | 19 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 scoped_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(nigori.Pass(), 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 scoped_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(nigori.Pass(), 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 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 scoped_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(nigori.Pass(), 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 |
OLD | NEW |