blob: c3ba20d61534023347a307ac0b89a9720dcc09d9 [file] [log] [blame]
[email protected]4cda78882012-08-16 02:34:161// 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#ifndef SYNC_SYNCABLE_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_
6#define SYNC_SYNCABLE_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_
7
8#include <string>
9
10#include "base/compiler_specific.h"
11#include "base/observer_list.h"
12#include "sync/internal_api/public/sync_encryption_handler.h"
13#include "sync/syncable/nigori_handler.h"
[email protected]69b3b8f2012-08-24 22:54:1914#include "sync/test/fake_encryptor.h"
15#include "sync/util/cryptographer.h"
[email protected]4cda78882012-08-16 02:34:1616
17namespace syncer {
18
[email protected]4cda78882012-08-16 02:34:1619// A fake sync encryption handler capable of keeping track of the encryption
20// state without opening any transactions or interacting with the nigori node.
21// Note that this only performs basic interactions with the cryptographer
22// (setting pending keys, installing keys).
23// Note: NOT thread safe. If threads attempt to check encryption state
24// while another thread is modifying it, races can occur.
25class FakeSyncEncryptionHandler : public SyncEncryptionHandler,
26 public syncable::NigoriHandler {
27 public:
28 FakeSyncEncryptionHandler();
dcheng393acf282014-10-21 16:44:4629 ~FakeSyncEncryptionHandler() override;
[email protected]4cda78882012-08-16 02:34:1630
[email protected]4cda78882012-08-16 02:34:1631 // SyncEncryptionHandler implementation.
dcheng393acf282014-10-21 16:44:4632 void AddObserver(Observer* observer) override;
33 void RemoveObserver(Observer* observer) override;
34 void Init() override;
35 void SetEncryptionPassphrase(const std::string& passphrase,
36 bool is_explicit) override;
37 void SetDecryptionPassphrase(const std::string& passphrase) override;
38 void EnableEncryptEverything() override;
39 bool EncryptEverythingEnabled() const override;
40 PassphraseType GetPassphraseType() const override;
[email protected]4cda78882012-08-16 02:34:1641
42 // NigoriHandler implemenation.
dcheng393acf282014-10-21 16:44:4643 void ApplyNigoriUpdate(const sync_pb::NigoriSpecifics& nigori,
44 syncable::BaseTransaction* const trans) override;
45 void UpdateNigoriFromEncryptedTypes(
[email protected]4cda78882012-08-16 02:34:1646 sync_pb::NigoriSpecifics* nigori,
mostynb44fdf5d02014-10-06 20:30:5047 syncable::BaseTransaction* const trans) const override;
dcheng393acf282014-10-21 16:44:4648 bool NeedKeystoreKey(syncable::BaseTransaction* const trans) const override;
49 bool SetKeystoreKeys(
[email protected]9a3072c2012-12-19 01:56:5250 const google::protobuf::RepeatedPtrField<google::protobuf::string>& keys,
mostynb44fdf5d02014-10-06 20:30:5051 syncable::BaseTransaction* const trans) override;
dcheng393acf282014-10-21 16:44:4652 ModelTypeSet GetEncryptedTypes(
mostynb44fdf5d02014-10-06 20:30:5053 syncable::BaseTransaction* const trans) const override;
[email protected]69b3b8f2012-08-24 22:54:1954
55 Cryptographer* cryptographer() { return &cryptographer_; }
[email protected]4cda78882012-08-16 02:34:1656
57 private:
brettw236d3172015-06-03 16:31:4358 base::ObserverList<SyncEncryptionHandler::Observer> observers_;
[email protected]4cda78882012-08-16 02:34:1659 ModelTypeSet encrypted_types_;
60 bool encrypt_everything_;
[email protected]19fb9092012-09-13 21:52:2861 PassphraseType passphrase_type_;
[email protected]4cda78882012-08-16 02:34:1662
[email protected]69b3b8f2012-08-24 22:54:1963 FakeEncryptor encryptor_;
64 Cryptographer cryptographer_;
[email protected]de71c082012-08-29 23:48:1265 std::string keystore_key_;
[email protected]4cda78882012-08-16 02:34:1666};
67
68} // namespace syncer
69
70#endif // SYNC_INTERNAL_API_PUBLIC_TEST_FAKE_SYNC_ENCRYPTION_HANDLER_H_