32 #ifndef LEDGER_CORE_PREFERENCESBACKEND_HPP 33 #define LEDGER_CORE_PREFERENCESBACKEND_HPP 35 #include "../api/Preferences.hpp" 36 #include "../api/PreferencesEditor.hpp" 37 #include <leveldb/db.h> 39 #include "../api/ThreadDispatcher.hpp" 40 #include "../api/ExecutionContext.hpp" 41 #include "../api/PathResolver.hpp" 42 #include "../api/Lock.hpp" 45 #include "../utils/optional.hpp" 46 #include "Preferences.hpp" 47 #include <unordered_map> 49 #include <api/RandomNumberGenerator.hpp> 50 #include <utils/Option.hpp> 51 #include <crypto/AESCipher.hpp> 57 enum PreferencesChangeType {
62 PreferencesChangeType type;
63 std::vector<uint8_t> key;
64 std::vector<uint8_t> value;
67 PreferencesChange(PreferencesChangeType t, std::vector<uint8_t> k, std::vector<uint8_t> v);
73 const std::string& path,
74 const std::shared_ptr<api::ExecutionContext>& writingContext,
75 const std::shared_ptr<api::PathResolver>& resolver
80 std::shared_ptr<Preferences> getPreferences(
const std::string& name);
81 void iterate(
const std::vector<uint8_t>& keyPrefix, std::function<
bool (leveldb::Slice&&, leveldb::Slice&&)>);
86 bool commit(
const std::vector<PreferencesChange>& changes);
94 const std::shared_ptr<api::RandomNumberGenerator>& rng,
95 const std::string& password
104 void unsetEncryption();
114 bool resetEncryption(
115 const std::shared_ptr<api::RandomNumberGenerator>& rng,
116 const std::string& oldPassword,
117 const std::string& newPassword
121 std::string getEncryptionSalt();
127 std::shared_ptr<api::ExecutionContext> _context;
128 std::weak_ptr<leveldb::DB> _db;
136 void dropInstance(
const std::string &path);
139 void putPreferencesChange(
140 leveldb::WriteBatch& batch,
146 std::string createNewSalt(
const std::shared_ptr<api::RandomNumberGenerator>& rng);
149 std::vector<uint8_t> encrypt_preferences_change(
155 std::vector<uint8_t> decrypt_preferences_change(
156 const std::vector<uint8_t>& data,
161 static std::unordered_map<std::string, std::shared_ptr<leveldb::DB>> LEVELDB_INSTANCE_POOL;
162 static std::mutex LEVELDB_INSTANCE_POOL_MUTEX;
164 static std::weak_ptr<leveldb::DB> obtainInstance(
const std::string& path);
169 #endif //LEDGER_CORE_PREFERENCESBACKEND_HPP Definition: Option.hpp:49
Definition: PreferencesBackend.hpp:61
Definition: PreferencesBackend.hpp:70
Definition: AESCipher.hpp:44
Definition: Account.cpp:8
Definition: optional.hpp:177