Chromium Code Reviews| 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 LOG(ERROR) << "Cannot decrypt message"; |
|
stanisc
2015/06/09 00:04:02
Consider adding a comment explaining how this coul
Nicolas Zea
2015/06/09 19:42:03
Done.
| |
| 131 return std::string(); // Caller should have called CanDecrypt(encrypt). | 131 return std::string(); // Caller should have called CanDecrypt(encrypt). |
| 132 } | 132 } |
| 133 | 133 |
| 134 std::string plaintext; | 134 std::string plaintext; |
| 135 if (!it->second->Decrypt(encrypted.blob(), &plaintext)) { | 135 if (!it->second->Decrypt(encrypted.blob(), &plaintext)) { |
| 136 return std::string(); | 136 return std::string(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 return plaintext; | 139 return plaintext; |
| 140 } | 140 } |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 NOTREACHED(); | 374 NOTREACHED(); |
| 375 return false; | 375 return false; |
| 376 } | 376 } |
| 377 | 377 |
| 378 if (!AddKeyImpl(nigori.Pass(), true)) | 378 if (!AddKeyImpl(nigori.Pass(), true)) |
| 379 return false; | 379 return false; |
| 380 return true; | 380 return true; |
| 381 } | 381 } |
| 382 | 382 |
| 383 } // namespace syncer | 383 } // namespace syncer |
| OLD | NEW |