Passwordfile library 5.0.12
C++ library to read/write passwords from/to encrypted files
|
The PasswordFile class holds account information in the form of Entry and Field instances and provides methods to read and write these information to encrypted files using OpenSSL. More...
#include <passwordfile.h>
Public Member Functions | |
PasswordFile () | |
Constructs a new password file. | |
PasswordFile (const std::string &path, const std::string &password) | |
Constructs a new password file with the specified path and password. | |
PasswordFile (const PasswordFile &other) | |
Constructs a copy of another password file. | |
PasswordFile (PasswordFile &&other) | |
Moves the password file. | |
~PasswordFile () | |
Closes the file if still opened and destroys the instance. | |
CppUtilities::NativeFileStream & | fileStream () |
Returns the underlying file stream. | |
void | open (PasswordFileOpenFlags options=PasswordFileOpenFlags::Default) |
Opens the file. | |
void | opened () |
Handles the file being opened. | |
void | generateRootEntry () |
Generates a new root entry for the file. | |
void | create () |
Creates the file. | |
void | close () |
Closes the file if currently opened. | |
void | load () |
Reads the contents of the file. | |
std::uint32_t | mininumVersion (PasswordFileSaveFlags options) const |
Returns the minimum file version required to write the current instance with the specified options. | |
void | save (PasswordFileSaveFlags options=PasswordFileSaveFlags::Default) |
Writes the current root entry to the file under path() replacing its previous contents. | |
void | write (PasswordFileSaveFlags options=PasswordFileSaveFlags::Default) |
Writes the current root entry to the file which is assumed to be opened and writeable. | |
void | clearEntries () |
Removes the root element if one is present. | |
void | clear () |
Closes the file if opened. | |
void | exportToTextfile (const std::string &targetPath) const |
Writes the current root entry to a plain text file. | |
void | doBackup () |
Creates a backup of the file. | |
bool | hasRootEntry () const |
Returns an indication whether a root entry is present. | |
const NodeEntry * | rootEntry () const |
Returns the root entry if present or nullptr otherwise. | |
NodeEntry * | rootEntry () |
Returns the root entry if present or nullptr otherwise. | |
const std::string & | path () const |
Returns the current file path. | |
const std::string & | password () const |
Returns the current password. | |
void | setPath (const std::string &value) |
Sets the current file path. | |
void | clearPath () |
Clears the current path. | |
void | setPassword (const std::string &password) |
Sets the current password. | |
void | setPassword (const char *password, const std::size_t passwordSize) |
void | clearPassword () |
Clears the current password. | |
bool | isEncryptionUsed () |
Returns an indication whether encryption is used and the file is open; returns always false otherwise. | |
bool | isOpen () const |
Returns an indication whether the file is open. | |
std::string & | extendedHeader () |
Returns the extended header. | |
const std::string & | extendedHeader () const |
Returns the extended header. | |
std::string & | encryptedExtendedHeader () |
Returns the encrypted extended header. | |
const std::string & | encryptedExtendedHeader () const |
Returns the encrypted extended header. | |
std::size_t | size () |
Returns the size of the file if the file is open; otherwise returns zero. | |
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 the disk). | |
PasswordFileOpenFlags | openOptions () const |
Returns the options used to open the file. | |
PasswordFileSaveFlags | saveOptions () const |
Returns the save options used the last time when saving the file. | |
std::string | summary (PasswordFileSaveFlags saveOptions) const |
Returns a summary about the file (version, used features, statistics). | |
The PasswordFile class holds account information in the form of Entry and Field instances and provides methods to read and write these information to encrypted files using OpenSSL.
Definition at line 40 of file passwordfile.h.
|
explicit |
Constructs a new password file.
Definition at line 46 of file passwordfile.cpp.
|
explicit |
Constructs a new password file with the specified path and password.
Definition at line 60 of file passwordfile.cpp.
Io::PasswordFile::PasswordFile | ( | const PasswordFile & | other | ) |
Constructs a copy of another password file.
Definition at line 75 of file passwordfile.cpp.
Io::PasswordFile::PasswordFile | ( | PasswordFile && | other | ) |
Moves the password file.
Definition at line 93 of file passwordfile.cpp.
Io::PasswordFile::~PasswordFile | ( | ) |
Closes the file if still opened and destroys the instance.
Definition at line 111 of file passwordfile.cpp.
void Io::PasswordFile::clear | ( | ) |
Closes the file if opened.
Removes path, password and entries and additional information.
Definition at line 596 of file passwordfile.cpp.
void Io::PasswordFile::clearEntries | ( | ) |
Removes the root element if one is present.
Definition at line 588 of file passwordfile.cpp.
|
inline |
Clears the current password.
Definition at line 149 of file passwordfile.h.
|
inline |
Clears the current path.
Causes the file to be closed if currently opened.
Definition at line 116 of file passwordfile.h.
void Io::PasswordFile::close | ( | ) |
Closes the file if currently opened.
Definition at line 701 of file passwordfile.cpp.
void Io::PasswordFile::create | ( | ) |
Creates the file.
Does not generate a new root element (see generateRootElement()).
Throws | ios_base::failure when an IO error occurs. |
Definition at line 160 of file passwordfile.cpp.
void Io::PasswordFile::doBackup | ( | ) |
Creates a backup of the file.
Replaces an existent backup file.
Throws | ios_base::failure when an IO error occurs. |
Definition at line 654 of file passwordfile.cpp.
|
inline |
Returns the encrypted extended header.
Definition at line 181 of file passwordfile.h.
|
inline |
Returns the encrypted extended header.
Definition at line 189 of file passwordfile.h.
void Io::PasswordFile::exportToTextfile | ( | const std::string & | targetPath | ) | const |
Writes the current root entry to a plain text file.
No encryption is used.
targetPath | Specifies the path of the text file. |
Throws | std::ios_base::failure when an IO error occurs and std::runtime_error when no root entry is present. |
Definition at line 612 of file passwordfile.cpp.
|
inline |
Returns the extended header.
Definition at line 165 of file passwordfile.h.
|
inline |
Returns the extended header.
Definition at line 173 of file passwordfile.h.
|
inline |
Returns the underlying file stream.
Definition at line 100 of file passwordfile.h.
void Io::PasswordFile::generateRootEntry | ( | ) |
Generates a new root entry for the file.
Definition at line 149 of file passwordfile.cpp.
bool Io::PasswordFile::hasRootEntry | ( | ) | const |
Returns an indication whether a root entry is present.
Definition at line 677 of file passwordfile.cpp.
bool Io::PasswordFile::isEncryptionUsed | ( | ) |
Returns an indication whether encryption is used and the file is open; returns always false otherwise.
Definition at line 728 of file passwordfile.cpp.
|
inline |
Returns an indication whether the file is open.
Definition at line 157 of file passwordfile.h.
void Io::PasswordFile::load | ( | ) |
Reads the contents of the file.
Opens the file if not already opened. Replaces the current root entry with the new one constructed from the file contents.
Throws | ios_base::failure when an IO error occurs. |
Throws | Io::ParsingException when a parsing error occurs. |
Throws | Io::CryptoException when a decryption error occurs. |
Throws | CppUtilities::ConversionException when a conversion error occurs. |
Definition at line 177 of file passwordfile.cpp.
std::uint32_t Io::PasswordFile::mininumVersion | ( | PasswordFileSaveFlags | options | ) | const |
Returns the minimum file version required to write the current instance with the specified options.
Definition at line 379 of file passwordfile.cpp.
void Io::PasswordFile::open | ( | PasswordFileOpenFlags | options = PasswordFileOpenFlags::Default | ) |
Opens the file.
Does not load the contents (see load()).
Throws | ios_base::failure when an IO error occurs. |
Definition at line 119 of file passwordfile.cpp.
void Io::PasswordFile::opened | ( | ) |
Handles the file being opened.
Call this method after opening a file directly via the underlying fileStream().
Definition at line 136 of file passwordfile.cpp.
|
inline |
Returns the options used to open the file.
Definition at line 206 of file passwordfile.h.
|
inline |
Returns the current password.
It will be used when loading or saving using encryption.
Definition at line 125 of file passwordfile.h.
|
inline |
Returns the current file path.
Definition at line 108 of file passwordfile.h.
NodeEntry * Io::PasswordFile::rootEntry | ( | ) |
Returns the root entry if present or nullptr otherwise.
Definition at line 693 of file passwordfile.cpp.
const NodeEntry * Io::PasswordFile::rootEntry | ( | ) | const |
Returns the root entry if present or nullptr otherwise.
Definition at line 685 of file passwordfile.cpp.
void Io::PasswordFile::save | ( | PasswordFileSaveFlags | options = PasswordFileSaveFlags::Default | ) |
Writes the current root entry to the file under path() replacing its previous contents.
options | Specify the features (like encryption and compression) to be used. |
Throws | std::ios_base::failure when an IO error occurs. |
Throws | std::filesystem::filesystem_error when a filesystem error occurs. |
Throws | Io::CryptoException when an encryption error occurs. |
Throws | std::runtime_error when no root entry is present or a compression error occurs. |
Definition at line 399 of file passwordfile.cpp.
|
inline |
Returns the save options used the last time when saving the file.
Definition at line 214 of file passwordfile.h.
void Io::PasswordFile::setPassword | ( | const char * | password, |
const std::size_t | passwordSize ) |
|
inline |
Sets the current password.
It will be used when loading an encrypted file or when saving using encryption.
Definition at line 133 of file passwordfile.h.
void Io::PasswordFile::setPath | ( | const std::string & | value | ) |
Sets the current file path.
Closes the file if currently opened.
Definition at line 712 of file passwordfile.cpp.
size_t Io::PasswordFile::size | ( | ) |
Returns the size of the file if the file is open; otherwise returns zero.
Definition at line 754 of file passwordfile.cpp.
string Io::PasswordFile::summary | ( | PasswordFileSaveFlags | saveOptions | ) | const |
Returns a summary about the file (version, used features, statistics).
Definition at line 766 of file passwordfile.cpp.
|
inline |
Returns the file version used the last time when saving the file (the version of the file as it is on the disk).
Definition at line 198 of file passwordfile.h.
void Io::PasswordFile::write | ( | PasswordFileSaveFlags | options = PasswordFileSaveFlags::Default | ) |
Writes the current root entry to the file which is assumed to be opened and writeable.
options | Specify the features (like encryption and compression) to be used. |
Throws | std::ios_base::failure when an IO error occurs. |
Throws | Io::CryptoException when an encryption error occurs. |
Throws | std::runtime_error when no root entry is present, a compression error occurs. |
Definition at line 445 of file passwordfile.cpp.