1#ifndef PASSWORD_FILE_IO_PASSWORD_FILE_H
2#define PASSWORD_FILE_IO_PASSWORD_FILE_H
6#include <c++utilities/io/binaryreader.h>
7#include <c++utilities/io/binarywriter.h>
8#include <c++utilities/io/nativefilestream.h>
9#include <c++utilities/misc/flagenumclass.h>
62 const std::string &
path()
const;
64 void setPath(
const std::string &value);
83 std::string m_password;
84 std::unique_ptr<NodeEntry> m_rootEntry;
85 std::string m_extendedHeader;
86 std::string m_encryptedExtendedHeader;
87 CppUtilities::NativeFileStream m_file;
88 CppUtilities::BinaryReader m_freader;
89 CppUtilities::BinaryWriter m_fwriter;
90 std::uint32_t m_version;
141 m_password.assign(
password, passwordSize);
157 return m_file.is_open();
165 return m_extendedHeader;
173 return m_extendedHeader;
181 return m_encryptedExtendedHeader;
189 return m_encryptedExtendedHeader;
206 return m_openOptions;
214 return m_saveOptions;
The NodeEntry class acts as parent for other entries.
PasswordFileOpenFlags openOptions() const
Returns the options used to open the file.
const NodeEntry * rootEntry() const
Returns the root entry if present or nullptr otherwise.
bool isOpen() const
Returns an indication whether the file is open.
void clear()
Closes the file if opened.
void opened()
Handles the file being opened.
void clearEntries()
Removes the root element if one is present.
void open(PasswordFileOpenFlags options=PasswordFileOpenFlags::Default)
Opens the file.
bool hasRootEntry() const
Returns an indication whether a root entry is present.
void create()
Creates the file.
void exportToTextfile(const std::string &targetPath) const
Writes the current root entry to a plain text file.
void load()
Reads the contents of the file.
void close()
Closes the file if currently opened.
std::uint32_t version() const
Returns the file version used the last time when saving the file (the version of the file as it is on...
CppUtilities::NativeFileStream & fileStream()
Returns the underlying file stream.
void clearPassword()
Clears the current password.
std::string summary(PasswordFileSaveFlags saveOptions) const
Returns a summary about the file (version, used features, statistics).
PasswordFile()
Constructs a new password file.
const std::string & password() const
Returns the current password.
void setPassword(const std::string &password)
Sets the current password.
const std::string & path() const
Returns the current file path.
bool isEncryptionUsed()
Returns an indication whether encryption is used and the file is open; returns always false otherwise...
std::size_t size()
Returns the size of the file if the file is open; otherwise returns zero.
void setPassword(const char *password, const std::size_t passwordSize)
void save(PasswordFileSaveFlags options=PasswordFileSaveFlags::Default)
Writes the current root entry to the file under path() replacing its previous contents.
std::string & encryptedExtendedHeader()
Returns the encrypted extended header.
void setPath(const std::string &value)
Sets the current file path.
std::uint32_t mininumVersion(PasswordFileSaveFlags options) const
Returns the minimum file version required to write the current instance with the specified options.
std::string & extendedHeader()
Returns the extended header.
void write(PasswordFileSaveFlags options=PasswordFileSaveFlags::Default)
Writes the current root entry to the file which is assumed to be opened and writeable.
void generateRootEntry()
Generates a new root entry for the file.
void clearPath()
Clears the current path.
void doBackup()
Creates a backup of the file.
PasswordFileSaveFlags saveOptions() const
Returns the save options used the last time when saving the file.
#define PASSWORD_FILE_EXPORT
Marks the symbol to be exported by the passwordfile library.
Contains all IO related classes.
PASSWORD_FILE_EXPORT std::string flagsToString(PasswordFileOpenFlags flags)
Returns a comma-separated string for the specified flags.
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(Io, Io::PasswordFileOpenFlags)