| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Various utility methods for nigori-based multi-type encryption. | 5 // Various utility methods for nigori-based multi-type encryption. |
| 6 | 6 |
| 7 #ifndef SYNC_SYNCABLE_NIGORI_UTIL_H_ | 7 #ifndef SYNC_SYNCABLE_NIGORI_UTIL_H_ |
| 8 #define SYNC_SYNCABLE_NIGORI_UTIL_H_ | 8 #define SYNC_SYNCABLE_NIGORI_UTIL_H_ |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "sync/base/sync_export.h" |
| 11 #include "sync/internal_api/public/base/model_type.h" | 12 #include "sync/internal_api/public/base/model_type.h" |
| 12 #include "sync/protocol/nigori_specifics.pb.h" | 13 #include "sync/protocol/nigori_specifics.pb.h" |
| 13 | 14 |
| 14 namespace sync_pb { | 15 namespace sync_pb { |
| 15 class EntitySpecifics; | 16 class EntitySpecifics; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace syncer { | 19 namespace syncer { |
| 19 class Cryptographer; | 20 class Cryptographer; |
| 20 | 21 |
| 21 namespace syncable { | 22 namespace syncable { |
| 22 | 23 |
| 23 const char kEncryptedString[] = "encrypted"; | 24 const char kEncryptedString[] = "encrypted"; |
| 24 | 25 |
| 25 class BaseTransaction; | 26 class BaseTransaction; |
| 26 class Entry; | 27 class Entry; |
| 27 class MutableEntry; | 28 class MutableEntry; |
| 28 class WriteTransaction; | 29 class WriteTransaction; |
| 29 | 30 |
| 30 // Check if our unsyced changes are encrypted if they need to be based on | 31 // Check if our unsyced changes are encrypted if they need to be based on |
| 31 // |encrypted_types|. | 32 // |encrypted_types|. |
| 32 // Returns: true if all unsynced data that should be encrypted is. | 33 // Returns: true if all unsynced data that should be encrypted is. |
| 33 // false if some unsynced changes need to be encrypted. | 34 // false if some unsynced changes need to be encrypted. |
| 34 // This method is similar to ProcessUnsyncedChangesForEncryption but does not | 35 // This method is similar to ProcessUnsyncedChangesForEncryption but does not |
| 35 // modify the data and does not care if data is unnecessarily encrypted. | 36 // modify the data and does not care if data is unnecessarily encrypted. |
| 36 bool VerifyUnsyncedChangesAreEncrypted( | 37 SYNC_EXPORT_PRIVATE bool VerifyUnsyncedChangesAreEncrypted( |
| 37 BaseTransaction* const trans, | 38 BaseTransaction* const trans, |
| 38 ModelTypeSet encrypted_types); | 39 ModelTypeSet encrypted_types); |
| 39 | 40 |
| 40 // Processes all unsynced changes and ensures they are appropriately encrypted | 41 // Processes all unsynced changes and ensures they are appropriately encrypted |
| 41 // or unencrypted, based on |encrypted_types|. | 42 // or unencrypted, based on |encrypted_types|. |
| 42 bool ProcessUnsyncedChangesForEncryption( | 43 bool ProcessUnsyncedChangesForEncryption( |
| 43 WriteTransaction* const trans); | 44 WriteTransaction* const trans); |
| 44 | 45 |
| 45 // Returns true if the entry requires encryption but is not encrypted, false | 46 // Returns true if the entry requires encryption but is not encrypted, false |
| 46 // otherwise. Note: this does not check that already encrypted entries are | 47 // otherwise. Note: this does not check that already encrypted entries are |
| 47 // encrypted with the proper key. | 48 // encrypted with the proper key. |
| 48 bool EntryNeedsEncryption(ModelTypeSet encrypted_types, | 49 bool EntryNeedsEncryption(ModelTypeSet encrypted_types, |
| 49 const Entry& entry); | 50 const Entry& entry); |
| 50 | 51 |
| 51 // Same as EntryNeedsEncryption, but looks at specifics. | 52 // Same as EntryNeedsEncryption, but looks at specifics. |
| 52 bool SpecificsNeedsEncryption(ModelTypeSet encrypted_types, | 53 SYNC_EXPORT_PRIVATE bool SpecificsNeedsEncryption( |
| 53 const sync_pb::EntitySpecifics& specifics); | 54 ModelTypeSet encrypted_types, |
| 55 const sync_pb::EntitySpecifics& specifics); |
| 54 | 56 |
| 55 // Verifies all data of type |type| is encrypted appropriately. | 57 // Verifies all data of type |type| is encrypted appropriately. |
| 56 bool VerifyDataTypeEncryptionForTest( | 58 SYNC_EXPORT_PRIVATE bool VerifyDataTypeEncryptionForTest( |
| 57 BaseTransaction* const trans, | 59 BaseTransaction* const trans, |
| 58 ModelType type, | 60 ModelType type, |
| 59 bool is_encrypted) WARN_UNUSED_RESULT; | 61 bool is_encrypted) WARN_UNUSED_RESULT; |
| 60 | 62 |
| 61 // Stores |new_specifics| into |entry|, encrypting if necessary. | 63 // Stores |new_specifics| into |entry|, encrypting if necessary. |
| 62 // Returns false if an error encrypting occurred (does not modify |entry|). | 64 // Returns false if an error encrypting occurred (does not modify |entry|). |
| 63 // Note: gracefully handles new_specifics aliasing with entry->Get(SPECIFICS). | 65 // Note: gracefully handles new_specifics aliasing with entry->Get(SPECIFICS). |
| 64 bool UpdateEntryWithEncryption( | 66 bool UpdateEntryWithEncryption( |
| 65 BaseTransaction* const trans, | 67 BaseTransaction* const trans, |
| 66 const sync_pb::EntitySpecifics& new_specifics, | 68 const sync_pb::EntitySpecifics& new_specifics, |
| 67 MutableEntry* entry); | 69 MutableEntry* entry); |
| 68 | 70 |
| 69 // Updates |nigori| to match the encryption state specified by |encrypted_types| | 71 // Updates |nigori| to match the encryption state specified by |encrypted_types| |
| 70 // and |encrypt_everything|. | 72 // and |encrypt_everything|. |
| 71 void UpdateNigoriFromEncryptedTypes(ModelTypeSet encrypted_types, | 73 SYNC_EXPORT_PRIVATE void UpdateNigoriFromEncryptedTypes( |
| 72 bool encrypt_everything, | 74 ModelTypeSet encrypted_types, |
| 73 sync_pb::NigoriSpecifics* nigori); | 75 bool encrypt_everything, |
| 76 sync_pb::NigoriSpecifics* nigori); |
| 74 | 77 |
| 75 // Extracts the set of encrypted types from a nigori node. | 78 // Extracts the set of encrypted types from a nigori node. |
| 76 ModelTypeSet GetEncryptedTypesFromNigori( | 79 ModelTypeSet GetEncryptedTypesFromNigori( |
| 77 const sync_pb::NigoriSpecifics& nigori); | 80 const sync_pb::NigoriSpecifics& nigori); |
| 78 | 81 |
| 79 } // namespace syncable | 82 } // namespace syncable |
| 80 } // namespace syncer | 83 } // namespace syncer |
| 81 | 84 |
| 82 #endif // SYNC_SYNCABLE_NIGORI_UTIL_H_ | 85 #endif // SYNC_SYNCABLE_NIGORI_UTIL_H_ |
| OLD | NEW |