OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "sync/test/fake_sync_encryption_handler.h" | |
6 | |
7 #include "sync/protocol/nigori_specifics.pb.h" | |
8 #include "sync/syncable/nigori_util.h" | |
9 #include "sync/util/cryptographer.h" | |
10 | |
11 namespace syncer { | |
12 | |
13 FakeSyncEncryptionHandler::FakeSyncEncryptionHandler() | |
14 : encrypted_types_(SensitiveTypes()), | |
15 encrypt_everything_(false), | |
16 explicit_passphrase_(false), | |
17 cryptographer_(NULL) { | |
18 } | |
19 FakeSyncEncryptionHandler::~FakeSyncEncryptionHandler() {} | |
20 | |
21 | |
tim (not reviewing)
2012/08/14 02:32:20
nit - extra newline
Nicolas Zea
2012/08/14 23:24:51
Done.
| |
22 void FakeSyncEncryptionHandler::ReloadNigori() { | |
23 // Do nothing. | |
24 } | |
25 | |
26 void FakeSyncEncryptionHandler::UpdateFromNigori( | |
27 const sync_pb::NigoriSpecifics& nigori) { | |
28 if (nigori.encrypt_everything()) | |
29 EnableEncryptEverything(); | |
30 if (nigori.using_explicit_passphrase()) | |
31 explicit_passphrase_ = true; | |
32 | |
33 if (!cryptographer_) | |
34 return; | |
35 | |
36 if (cryptographer_->CanDecrypt(nigori.encrypted())) | |
37 cryptographer_->InstallKeys(nigori.encrypted()); | |
38 else | |
39 cryptographer_->SetPendingKeys(nigori.encrypted()); | |
40 | |
41 if (cryptographer_->has_pending_keys()) { | |
42 DVLOG(1) << "OnPassPhraseRequired Sent"; | |
43 sync_pb::EncryptedData pending_keys = cryptographer_->GetPendingKeys(); | |
44 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, | |
45 OnPassphraseRequired(REASON_DECRYPTION, | |
46 pending_keys)); | |
47 } else if (!cryptographer_->is_ready()) { | |
48 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " | |
49 << "ready"; | |
50 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, | |
51 OnPassphraseRequired(REASON_ENCRYPTION, | |
52 sync_pb::EncryptedData())); | |
53 } | |
54 } | |
55 | |
56 void FakeSyncEncryptionHandler::UpdateNigoriFromEncryptedTypes( | |
57 sync_pb::NigoriSpecifics* nigori) const { | |
58 syncable::UpdateNigoriFromEncryptedTypes(encrypted_types_, | |
59 encrypt_everything_, | |
60 nigori); | |
61 } | |
62 | |
63 void FakeSyncEncryptionHandler::AddObserver(Observer* observer) { | |
64 observers_.AddObserver(observer); | |
65 } | |
66 | |
67 void FakeSyncEncryptionHandler::RemoveObserver(Observer* observer) { | |
68 observers_.RemoveObserver(observer); | |
69 } | |
70 | |
71 void FakeSyncEncryptionHandler::SetEncryptionPassphrase( | |
72 const std::string& passphrase, | |
73 bool is_explicit) { | |
74 if (is_explicit) | |
75 explicit_passphrase_ = true; | |
76 } | |
77 | |
78 void FakeSyncEncryptionHandler::SetDecryptionPassphrase( | |
79 const std::string& passphrase) { | |
80 // Do nothing. | |
81 } | |
82 | |
83 void FakeSyncEncryptionHandler::EnableEncryptEverything() { | |
84 if (encrypt_everything_) | |
85 return; | |
86 encrypt_everything_ = true; | |
87 encrypted_types_ = ModelTypeSet::All(); | |
88 FOR_EACH_OBSERVER( | |
89 Observer, observers_, | |
90 OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_)); | |
91 } | |
92 | |
93 bool FakeSyncEncryptionHandler::EncryptEverythingEnabled() const { | |
94 return encrypt_everything_; | |
95 } | |
96 | |
97 ModelTypeSet FakeSyncEncryptionHandler::GetEncryptedTypes() const { | |
98 return encrypted_types_; | |
99 } | |
100 | |
101 bool FakeSyncEncryptionHandler::IsUsingExplicitPassphrase() const { | |
102 return explicit_passphrase_; | |
103 } | |
104 | |
105 } // namespace syncer | |
OLD | NEW |