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 #ifndef SYNC_SYNCABLE_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_ | 5 #ifndef SYNC_SYNCABLE_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_ |
6 #define SYNC_SYNCABLE_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_ | 6 #define SYNC_SYNCABLE_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "sync/internal_api/public/sync_encryption_handler.h" | 12 #include "sync/internal_api/public/sync_encryption_handler.h" |
13 #include "sync/syncable/nigori_handler.h" | 13 #include "sync/syncable/nigori_handler.h" |
| 14 #include "sync/test/fake_encryptor.h" |
| 15 #include "sync/util/cryptographer.h" |
14 | 16 |
15 namespace syncer { | 17 namespace syncer { |
16 | 18 |
17 class Cryptographer; | |
18 | |
19 // A fake sync encryption handler capable of keeping track of the encryption | 19 // A fake sync encryption handler capable of keeping track of the encryption |
20 // state without opening any transactions or interacting with the nigori node. | 20 // state without opening any transactions or interacting with the nigori node. |
21 // Note that this only performs basic interactions with the cryptographer | 21 // Note that this only performs basic interactions with the cryptographer |
22 // (setting pending keys, installing keys). | 22 // (setting pending keys, installing keys). |
23 // Note: NOT thread safe. If threads attempt to check encryption state | 23 // Note: NOT thread safe. If threads attempt to check encryption state |
24 // while another thread is modifying it, races can occur. | 24 // while another thread is modifying it, races can occur. |
25 class FakeSyncEncryptionHandler : public SyncEncryptionHandler, | 25 class FakeSyncEncryptionHandler : public SyncEncryptionHandler, |
26 public syncable::NigoriHandler { | 26 public syncable::NigoriHandler { |
27 public: | 27 public: |
28 FakeSyncEncryptionHandler(); | 28 FakeSyncEncryptionHandler(); |
29 virtual ~FakeSyncEncryptionHandler(); | 29 virtual ~FakeSyncEncryptionHandler(); |
30 | 30 |
31 void set_cryptographer(Cryptographer* cryptographer) { | |
32 cryptographer_ = cryptographer; | |
33 } | |
34 | |
35 // SyncEncryptionHandler implementation. | 31 // SyncEncryptionHandler implementation. |
36 virtual void AddObserver(Observer* observer) OVERRIDE; | 32 virtual void AddObserver(Observer* observer) OVERRIDE; |
37 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 33 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
38 virtual void Init() OVERRIDE; | 34 virtual void Init() OVERRIDE; |
39 virtual void SetEncryptionPassphrase(const std::string& passphrase, | 35 virtual void SetEncryptionPassphrase(const std::string& passphrase, |
40 bool is_explicit) OVERRIDE; | 36 bool is_explicit) OVERRIDE; |
41 virtual void SetDecryptionPassphrase(const std::string& passphrase) OVERRIDE; | 37 virtual void SetDecryptionPassphrase(const std::string& passphrase) OVERRIDE; |
42 virtual void EnableEncryptEverything() OVERRIDE; | 38 virtual void EnableEncryptEverything() OVERRIDE; |
43 virtual bool EncryptEverythingEnabled() const OVERRIDE; | 39 virtual bool EncryptEverythingEnabled() const OVERRIDE; |
44 virtual bool IsUsingExplicitPassphrase() const OVERRIDE; | 40 virtual bool IsUsingExplicitPassphrase() const OVERRIDE; |
45 | 41 |
46 // NigoriHandler implemenation. | 42 // NigoriHandler implemenation. |
47 virtual void ApplyNigoriUpdate( | 43 virtual void ApplyNigoriUpdate( |
48 const sync_pb::NigoriSpecifics& nigori, | 44 const sync_pb::NigoriSpecifics& nigori, |
49 syncable::BaseTransaction* const trans) OVERRIDE; | 45 syncable::BaseTransaction* const trans) OVERRIDE; |
50 virtual ModelTypeSet GetEncryptedTypes() const OVERRIDE; | |
51 virtual void UpdateNigoriFromEncryptedTypes( | 46 virtual void UpdateNigoriFromEncryptedTypes( |
52 sync_pb::NigoriSpecifics* nigori, | 47 sync_pb::NigoriSpecifics* nigori, |
53 syncable::BaseTransaction* const trans) const OVERRIDE; | 48 syncable::BaseTransaction* const trans) const OVERRIDE; |
| 49 virtual ModelTypeSet GetEncryptedTypes( |
| 50 syncable::BaseTransaction* const trans) const OVERRIDE; |
| 51 |
| 52 Cryptographer* cryptographer() { return &cryptographer_; } |
54 | 53 |
55 private: | 54 private: |
56 ObserverList<SyncEncryptionHandler::Observer> observers_; | 55 ObserverList<SyncEncryptionHandler::Observer> observers_; |
57 ModelTypeSet encrypted_types_; | 56 ModelTypeSet encrypted_types_; |
58 bool encrypt_everything_; | 57 bool encrypt_everything_; |
59 bool explicit_passphrase_; | 58 bool explicit_passphrase_; |
60 | 59 |
61 Cryptographer* cryptographer_; | 60 FakeEncryptor encryptor_; |
| 61 Cryptographer cryptographer_; |
62 }; | 62 }; |
63 | 63 |
64 } // namespace syncer | 64 } // namespace syncer |
65 | 65 |
66 #endif // SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_ | 66 #endif // SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_ |
OLD | NEW |