ledger-core
Public Member Functions | List of all members
ledger::core::PreferencesBackend Class Reference

Public Member Functions

 PreferencesBackend (const std::string &path, const std::shared_ptr< api::ExecutionContext > &writingContext, const std::shared_ptr< api::PathResolver > &resolver)
 
std::shared_ptr< PreferencesgetPreferences (const std::string &name)
 
void iterate (const std::vector< uint8_t > &keyPrefix, std::function< bool(leveldb::Slice &&, leveldb::Slice &&)>)
 
optional< std::string > get (const std::vector< uint8_t > &key)
 
bool commit (const std::vector< PreferencesChange > &changes)
 
void setEncryption (const std::shared_ptr< api::RandomNumberGenerator > &rng, const std::string &password)
 
void unsetEncryption ()
 
bool resetEncryption (const std::shared_ptr< api::RandomNumberGenerator > &rng, const std::string &oldPassword, const std::string &newPassword)
 
std::string getEncryptionSalt ()
 Get encryption salt, if any.
 
void clear ()
 Clear all preferences.
 

Member Function Documentation

◆ commit()

bool ledger::core::PreferencesBackend::commit ( const std::vector< PreferencesChange > &  changes)

Commit a change. Return false if unsuccessful (might happen if the underlying DB was destroyed).

◆ resetEncryption()

bool ledger::core::PreferencesBackend::resetEncryption ( const std::shared_ptr< api::RandomNumberGenerator > &  rng,
const std::string &  oldPassword,
const std::string &  newPassword 
)

Reset the encryption with a new password by first decrypting on the fly with the old password the data present.

If the new password is an empty string, after this method is called, the database is completely unciphered and no password is required to read from it.

Return true if the reset occurred correctly, false otherwise (e.g. trying to change password with an old password but without a proper salt already persisted).

◆ setEncryption()

void ledger::core::PreferencesBackend::setEncryption ( const std::shared_ptr< api::RandomNumberGenerator > &  rng,
const std::string &  password 
)

Turn encryption on for all future uses.

This method will set encryption on for all future values that will be persisted. If this function is called on a plaintext storage (i.e. first encryption for instance), it will also encrypt all data already present.

◆ unsetEncryption()

void ledger::core::PreferencesBackend::unsetEncryption ( )

Turn off encryption by disabling the use of the internal cipher. Data is left untouched.

This method is suitable when you want to get back raw, encrypted data. If you want to disable encryption in order to read clear data back without password, consider the resetEncryption method instead.


The documentation for this class was generated from the following files: