| 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 <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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 ::google::protobuf::MessageLite* message) const { | 120 ::google::protobuf::MessageLite* message) const { |
| 121 DCHECK(message); | 121 DCHECK(message); |
| 122 std::string plaintext = DecryptToString(encrypted); | 122 std::string plaintext = DecryptToString(encrypted); |
| 123 return message->ParseFromString(plaintext); | 123 return message->ParseFromString(plaintext); |
| 124 } | 124 } |
| 125 | 125 |
| 126 std::string Cryptographer::DecryptToString( | 126 std::string Cryptographer::DecryptToString( |
| 127 const sync_pb::EncryptedData& encrypted) const { | 127 const sync_pb::EncryptedData& encrypted) const { |
| 128 NigoriMap::const_iterator it = nigoris_.find(encrypted.key_name()); | 128 NigoriMap::const_iterator it = nigoris_.find(encrypted.key_name()); |
| 129 if (nigoris_.end() == it) { | 129 if (nigoris_.end() == it) { |
| 130 NOTREACHED() << "Cannot decrypt message"; | 130 // The key used to encrypt the blob is not part of the set of installed |
| 131 return std::string(); // Caller should have called CanDecrypt(encrypt). | 131 // nigoris. |
| 132 LOG(ERROR) << "Cannot decrypt message"; |
| 133 return std::string(); |
| 132 } | 134 } |
| 133 | 135 |
| 134 std::string plaintext; | 136 std::string plaintext; |
| 135 if (!it->second->Decrypt(encrypted.blob(), &plaintext)) { | 137 if (!it->second->Decrypt(encrypted.blob(), &plaintext)) { |
| 136 return std::string(); | 138 return std::string(); |
| 137 } | 139 } |
| 138 | 140 |
| 139 return plaintext; | 141 return plaintext; |
| 140 } | 142 } |
| 141 | 143 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 NOTREACHED(); | 376 NOTREACHED(); |
| 375 return false; | 377 return false; |
| 376 } | 378 } |
| 377 | 379 |
| 378 if (!AddKeyImpl(nigori.Pass(), true)) | 380 if (!AddKeyImpl(nigori.Pass(), true)) |
| 379 return false; | 381 return false; |
| 380 return true; | 382 return true; |
| 381 } | 383 } |
| 382 | 384 |
| 383 } // namespace syncer | 385 } // namespace syncer |
| OLD | NEW |