Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_SYNC_UTIL_CRYPTOGRAPHER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_UTIL_CRYPTOGRAPHER_H_ |
| 6 #define CHROME_BROWSER_SYNC_UTIL_CRYPTOGRAPHER_H_ | 6 #define CHROME_BROWSER_SYNC_UTIL_CRYPTOGRAPHER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 void Bootstrap(const std::string& restored_bootstrap_token); | 96 void Bootstrap(const std::string& restored_bootstrap_token); |
| 97 | 97 |
| 98 // Returns whether we can decrypt |encrypted| using the keys we currently know | 98 // Returns whether we can decrypt |encrypted| using the keys we currently know |
| 99 // about. | 99 // about. |
| 100 bool CanDecrypt(const sync_pb::EncryptedData& encrypted) const; | 100 bool CanDecrypt(const sync_pb::EncryptedData& encrypted) const; |
| 101 | 101 |
| 102 // Returns whether |encrypted| can be decrypted using the default encryption | 102 // Returns whether |encrypted| can be decrypted using the default encryption |
| 103 // key. | 103 // key. |
| 104 bool CanDecryptUsingDefaultKey(const sync_pb::EncryptedData& encrypted) const; | 104 bool CanDecryptUsingDefaultKey(const sync_pb::EncryptedData& encrypted) const; |
| 105 | 105 |
| 106 // Encrypts |message| into |encrypted|. Returns true unless encryption fails. | 106 // Same as Encrypt(..), except exits early and returns true if |message| |
| 107 // matches the decrypted data within |encrypted| and |encrypted| was encrypted | |
| 108 // with the current default key. This avoids unnecessarily modifying | |
| 109 // |encrypted| if the change had no practical effect. | |
| 110 bool EncryptIfDifferent(const ::google::protobuf::MessageLite& message, | |
| 111 sync_pb::EncryptedData* encrypted) const; | |
| 112 | |
| 113 // Encrypts |message| into |encrypted|, irregardless of what was previously | |
|
akalin
2011/12/09 23:52:42
irregardless -> regardless
( see http://en.wikipe
Nicolas Zea
2011/12/12 20:12:26
Done.
| |
| 114 // in |encrypted| (as opposed to EncryptIfDifferent). Returns true unless | |
| 115 // encryption fails. | |
| 107 // Note that encryption will fail if |message| isn't valid (eg. a required | 116 // Note that encryption will fail if |message| isn't valid (eg. a required |
| 108 // field isn't set). | 117 // field isn't set). |
| 109 bool Encrypt(const ::google::protobuf::MessageLite& message, | 118 bool Encrypt(const ::google::protobuf::MessageLite& message, |
| 110 sync_pb::EncryptedData* encrypted) const; | 119 sync_pb::EncryptedData* encrypted) const; |
| 111 | 120 |
| 112 // Decrypts |encrypted| into |message|. Returns true unless decryption fails, | 121 // Decrypts |encrypted| into |message|. Returns true unless decryption fails, |
| 113 // or |message| fails to parse the decrypted data. | 122 // or |message| fails to parse the decrypted data. |
| 114 bool Decrypt(const sync_pb::EncryptedData& encrypted, | 123 bool Decrypt(const sync_pb::EncryptedData& encrypted, |
| 115 ::google::protobuf::MessageLite* message) const; | 124 ::google::protobuf::MessageLite* message) const; |
| 116 | 125 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 syncable::ModelTypeSet GetEncryptedTypes() const; | 192 syncable::ModelTypeSet GetEncryptedTypes() const; |
| 184 | 193 |
| 185 // Forwards to MergeEncryptedTypes. | 194 // Forwards to MergeEncryptedTypes. |
| 186 void MergeEncryptedTypesForTest( | 195 void MergeEncryptedTypesForTest( |
| 187 const syncable::ModelTypeSet& encrypted_types); | 196 const syncable::ModelTypeSet& encrypted_types); |
| 188 | 197 |
| 189 private: | 198 private: |
| 190 FRIEND_TEST_ALL_PREFIXES(CryptographerTest, PackUnpack); | 199 FRIEND_TEST_ALL_PREFIXES(CryptographerTest, PackUnpack); |
| 191 typedef std::map<std::string, linked_ptr<const Nigori> > NigoriMap; | 200 typedef std::map<std::string, linked_ptr<const Nigori> > NigoriMap; |
| 192 | 201 |
| 202 bool EncryptImpl(const std::string& serialized, | |
| 203 const NigoriMap::value_type* nigori, | |
| 204 sync_pb::EncryptedData* encrypted) const; | |
| 205 | |
| 193 // Merges the given set of encrypted types with the existing set and emits a | 206 // Merges the given set of encrypted types with the existing set and emits a |
| 194 // notification if necessary. | 207 // notification if necessary. |
| 195 void MergeEncryptedTypes(const syncable::ModelTypeSet& encrypted_types); | 208 void MergeEncryptedTypes(const syncable::ModelTypeSet& encrypted_types); |
| 196 | 209 |
| 197 void EmitEncryptedTypesChangedNotification(); | 210 void EmitEncryptedTypesChangedNotification(); |
| 198 | 211 |
| 199 // Helper method to instantiate Nigori instances for each set of key | 212 // Helper method to instantiate Nigori instances for each set of key |
| 200 // parameters in |bag| and setting the default encryption key to | 213 // parameters in |bag| and setting the default encryption key to |
| 201 // |default_key_name|. | 214 // |default_key_name|. |
| 202 void InstallKeys(const std::string& default_key_name, | 215 void InstallKeys(const std::string& default_key_name, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 218 | 231 |
| 219 syncable::ModelTypeSet encrypted_types_; | 232 syncable::ModelTypeSet encrypted_types_; |
| 220 bool encrypt_everything_; | 233 bool encrypt_everything_; |
| 221 | 234 |
| 222 DISALLOW_COPY_AND_ASSIGN(Cryptographer); | 235 DISALLOW_COPY_AND_ASSIGN(Cryptographer); |
| 223 }; | 236 }; |
| 224 | 237 |
| 225 } // namespace browser_sync | 238 } // namespace browser_sync |
| 226 | 239 |
| 227 #endif // CHROME_BROWSER_SYNC_UTIL_CRYPTOGRAPHER_H_ | 240 #endif // CHROME_BROWSER_SYNC_UTIL_CRYPTOGRAPHER_H_ |
| OLD | NEW |