Passwordfile library
3.1.3
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. More... | |
PasswordFile (const std::string &path, const std::string &password) | |
Constructs a new password file with the specified path and password. More... | |
PasswordFile (const PasswordFile &other) | |
Constructs a copy of another password file. More... | |
~PasswordFile () | |
Closes the file if still opened and destroys the instance. More... | |
void | open (bool readOnly=false) |
Opens the file. More... | |
void | generateRootEntry () |
Generates a new root entry for the file. More... | |
void | create () |
Creates the file. More... | |
void | close () |
Closes the file if currently opened. More... | |
void | load () |
Reads the contents of the file. More... | |
void | save (bool useEncryption=true, bool useCompression=true) |
Writes the current root entry to the file. More... | |
void | clearEntries () |
Removes the root element if one is present. More... | |
void | clear () |
Closes the file if opened. More... | |
void | exportToTextfile (const std::string &targetPath) const |
Writes the current root entry to a plain text file. More... | |
void | doBackup () |
Creates a backup of the file. More... | |
bool | hasRootEntry () const |
Returns an indication whether a root entry is present. More... | |
const NodeEntry * | rootEntry () const |
Returns the root entry if present or nullptr otherwise. More... | |
NodeEntry * | rootEntry () |
Returns the root entry if present or nullptr otherwise. More... | |
const std::string & | path () const |
Returns the current file path. More... | |
const char * | password () const |
Returns the current password. More... | |
void | setPath (const std::string &value) |
Sets the current file path. More... | |
void | clearPath () |
Clears the current path. More... | |
void | setPassword (const std::string &value) |
Sets the current password. More... | |
void | clearPassword () |
Clears the current password. More... | |
bool | isEncryptionUsed () |
Returns an indication whether encryption is used if the file is open; returns always false otherwise. More... | |
bool | isOpen () const |
Returns an indication whether the file is open. More... | |
size_t | size () |
Returns the size of the file if the file is open; returns always zero otherwise. More... | |
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 18 of file passwordfile.h.
|
explicit |
Constructs a new password file.
Definition at line 37 of file passwordfile.cpp.
|
explicit |
Constructs a new password file with the specified path and password.
Definition at line 48 of file passwordfile.cpp.
Io::PasswordFile::PasswordFile | ( | const PasswordFile & | other | ) |
Constructs a copy of another password file.
Definition at line 60 of file passwordfile.cpp.
Io::PasswordFile::~PasswordFile | ( | ) |
Closes the file if still opened and destroys the instance.
Definition at line 73 of file passwordfile.cpp.
void Io::PasswordFile::clear | ( | ) |
Closes the file if opened.
Removes path, password and entries and additional information.
Definition at line 365 of file passwordfile.cpp.
void Io::PasswordFile::clearEntries | ( | ) |
Removes the root element if one is present.
Definition at line 357 of file passwordfile.cpp.
void Io::PasswordFile::clearPassword | ( | ) |
Clears the current password.
Definition at line 521 of file passwordfile.cpp.
void Io::PasswordFile::clearPath | ( | ) |
Clears the current path.
Causes the file to be closed if currently opened.
Definition at line 495 of file passwordfile.cpp.
void Io::PasswordFile::close | ( | ) |
Closes the file if currently opened.
Definition at line 467 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 111 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 421 of file passwordfile.cpp.
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 | ios_base::failure when an IO error occurs. |
Throws | runtime_error when no root entry is present. |
Definition at line 381 of file passwordfile.cpp.
void Io::PasswordFile::generateRootEntry | ( | ) |
Generates a new root entry for the file.
Definition at line 100 of file passwordfile.cpp.
bool Io::PasswordFile::hasRootEntry | ( | ) | const |
Returns an indication whether a root entry is present.
Definition at line 443 of file passwordfile.cpp.
bool Io::PasswordFile::isEncryptionUsed | ( | ) |
Returns an indication whether encryption is used if the file is open; returns always false otherwise.
Definition at line 529 of file passwordfile.cpp.
bool Io::PasswordFile::isOpen | ( | ) | const |
Returns an indication whether the file is open.
Definition at line 553 of file passwordfile.cpp.
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 | ConversionUtilities::ConversionException when a conversion error occurs. |
Definition at line 128 of file passwordfile.cpp.
void Io::PasswordFile::open | ( | bool | readOnly = false | ) |
Opens the file.
Does not load the contents (see load()).
Throws | ios_base::failure when an IO error occurs. |
Definition at line 82 of file passwordfile.cpp.
const char * Io::PasswordFile::password | ( | ) | const |
Returns the current password.
It will be used when loading or saving using encryption.
Definition at line 504 of file passwordfile.cpp.
const string & Io::PasswordFile::path | ( | ) | const |
Returns the current file path.
Definition at line 478 of file passwordfile.cpp.
const NodeEntry * Io::PasswordFile::rootEntry | ( | ) | const |
Returns the root entry if present or nullptr otherwise.
Definition at line 451 of file passwordfile.cpp.
NodeEntry * Io::PasswordFile::rootEntry | ( | ) |
Returns the root entry if present or nullptr otherwise.
Definition at line 459 of file passwordfile.cpp.
void Io::PasswordFile::save | ( | bool | useEncryption = true , |
bool | useCompression = true |
||
) |
Writes the current root entry to the file.
useEncryption | Specifies whether encryption should be used. |
useCompression | Specifies whether compression should be used. |
Throws | ios_base::failure when an IO error occurs. |
Throws | runtime_error when no root entry is present. |
Throws | Io::CryptoException when a decryption error occurs. |
Definition at line 255 of file passwordfile.cpp.
void Io::PasswordFile::setPassword | ( | const std::string & | value | ) |
Sets the current password.
It will be used when loading or saving using encryption.
Definition at line 512 of file passwordfile.cpp.
void Io::PasswordFile::setPath | ( | const std::string & | value | ) |
Sets the current file path.
Causes the file to be closed if currently opened.
Definition at line 486 of file passwordfile.cpp.
size_t Io::PasswordFile::size | ( | ) |
Returns the size of the file if the file is open; returns always zero otherwise.
Definition at line 561 of file passwordfile.cpp.