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