| 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 "components/sync/base/cryptographer.h" | 5 #include "components/sync/base/cryptographer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 return default_nigori_name_; | 341 return default_nigori_name_; |
| 342 } | 342 } |
| 343 | 343 |
| 344 std::string Cryptographer::GetDefaultNigoriKeyData() const { | 344 std::string Cryptographer::GetDefaultNigoriKeyData() const { |
| 345 if (!is_initialized()) | 345 if (!is_initialized()) |
| 346 return std::string(); | 346 return std::string(); |
| 347 NigoriMap::const_iterator iter = nigoris_.find(default_nigori_name_); | 347 NigoriMap::const_iterator iter = nigoris_.find(default_nigori_name_); |
| 348 if (iter == nigoris_.end()) | 348 if (iter == nigoris_.end()) |
| 349 return std::string(); | 349 return std::string(); |
| 350 sync_pb::NigoriKey key; | 350 sync_pb::NigoriKey key; |
| 351 if (!iter->second->ExportKeys(key.mutable_user_key(), | 351 iter->second->ExportKeys(key.mutable_user_key(), key.mutable_encryption_key(), |
| 352 key.mutable_encryption_key(), | 352 key.mutable_mac_key()); |
| 353 key.mutable_mac_key())) | |
| 354 return std::string(); | |
| 355 return key.SerializeAsString(); | 353 return key.SerializeAsString(); |
| 356 } | 354 } |
| 357 | 355 |
| 358 bool Cryptographer::ImportNigoriKey(const std::string& serialized_nigori_key) { | 356 bool Cryptographer::ImportNigoriKey(const std::string& serialized_nigori_key) { |
| 359 if (serialized_nigori_key.empty()) | 357 if (serialized_nigori_key.empty()) |
| 360 return false; | 358 return false; |
| 361 | 359 |
| 362 sync_pb::NigoriKey key; | 360 sync_pb::NigoriKey key; |
| 363 if (!key.ParseFromString(serialized_nigori_key)) | 361 if (!key.ParseFromString(serialized_nigori_key)) |
| 364 return false; | 362 return false; |
| 365 | 363 |
| 366 std::unique_ptr<Nigori> nigori(new Nigori); | 364 std::unique_ptr<Nigori> nigori(new Nigori); |
| 367 if (!nigori->InitByImport(key.user_key(), key.encryption_key(), | 365 if (!nigori->InitByImport(key.user_key(), key.encryption_key(), |
| 368 key.mac_key())) { | 366 key.mac_key())) { |
| 369 NOTREACHED(); | 367 NOTREACHED(); |
| 370 return false; | 368 return false; |
| 371 } | 369 } |
| 372 | 370 |
| 373 if (!AddKeyImpl(std::move(nigori), true)) | 371 if (!AddKeyImpl(std::move(nigori), true)) |
| 374 return false; | 372 return false; |
| 375 return true; | 373 return true; |
| 376 } | 374 } |
| 377 | 375 |
| 378 } // namespace syncer | 376 } // namespace syncer |
| OLD | NEW |