Passwordfile library
3.2.0
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 (PasswordFile &&other) | |
Moves the password file. More... | |
~PasswordFile () | |
Closes the file if still opened and destroys the instance. More... | |
IoUtilities::NativeFileStream & | fileStream () |
Returns the underlying file stream. More... | |
void | open (bool readOnly=false) |
Opens the file. More... | |
void | opened () |
Handles the file being opened. 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 under path() replacing its previous contents. More... | |
void | write (bool useEncryption=true, bool useCompression=true) |
Writes the current root entry to the file which is assumed to be opened and writeable. 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... | |
std::size_t | size () |
Returns the size of the file if the file is open; otherwise returns zero. 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 19 of file passwordfile.h.
|
explicit |
Constructs a new password file.
Definition at line 39 of file passwordfile.cpp.
|
explicit |
Constructs a new password file with the specified path and password.
Definition at line 50 of file passwordfile.cpp.
Io::PasswordFile::PasswordFile | ( | const PasswordFile & | other | ) |
Constructs a copy of another password file.
Definition at line 62 of file passwordfile.cpp.
Io::PasswordFile::PasswordFile | ( | PasswordFile && | other | ) |
Moves the password file.
Definition at line 77 of file passwordfile.cpp.
Io::PasswordFile::~PasswordFile | ( | ) |
Closes the file if still opened and destroys the instance.
Definition at line 92 of file passwordfile.cpp.
void Io::PasswordFile::clear | ( | ) |
Closes the file if opened.
Removes path, password and entries and additional information.
Definition at line 447 of file passwordfile.cpp.
void Io::PasswordFile::clearEntries | ( | ) |
Removes the root element if one is present.
Definition at line 439 of file passwordfile.cpp.
void Io::PasswordFile::clearPassword | ( | ) |
Clears the current password.
Definition at line 609 of file passwordfile.cpp.
void Io::PasswordFile::clearPath | ( | ) |
Clears the current path.
Causes the file to be closed if currently opened.
Definition at line 583 of file passwordfile.cpp.
void Io::PasswordFile::close | ( | ) |
Closes the file if currently opened.
Definition at line 550 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 139 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 503 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 463 of file passwordfile.cpp.
|
inline |
Returns the underlying file stream.
Definition at line 67 of file passwordfile.h.
void Io::PasswordFile::generateRootEntry | ( | ) |
Generates a new root entry for the file.
Definition at line 128 of file passwordfile.cpp.
bool Io::PasswordFile::hasRootEntry | ( | ) | const |
Returns an indication whether a root entry is present.
Definition at line 526 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 617 of file passwordfile.cpp.
bool Io::PasswordFile::isOpen | ( | ) | const |
Returns an indication whether the file is open.
Definition at line 643 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 156 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 100 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 115 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 592 of file passwordfile.cpp.
const string & Io::PasswordFile::path | ( | ) | const |
Returns the current file path.
Definition at line 561 of file passwordfile.cpp.
const NodeEntry * Io::PasswordFile::rootEntry | ( | ) | const |
Returns the root entry if present or nullptr otherwise.
Definition at line 534 of file passwordfile.cpp.
NodeEntry * Io::PasswordFile::rootEntry | ( | ) |
Returns the root entry if present or nullptr otherwise.
Definition at line 542 of file passwordfile.cpp.
void Io::PasswordFile::save | ( | bool | useEncryption = true , |
bool | useCompression = true |
||
) |
Writes the current root entry to the file under path() replacing its previous contents.
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 or a compression error occurs. |
Throws | Io::CryptoException when an encryption error occurs. |
Definition at line 300 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 600 of file passwordfile.cpp.
void Io::PasswordFile::setPath | ( | const std::string & | value | ) |
Sets the current file path.
Closes the file if currently opened.
Definition at line 569 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 651 of file passwordfile.cpp.
void Io::PasswordFile::write | ( | bool | useEncryption = true , |
bool | useCompression = true |
||
) |
Writes the current root entry to the file which is assumed to be opened and writeable.
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 or a compression error occurs. |
Throws | Io::CryptoException when an encryption error occurs. |
Definition at line 327 of file passwordfile.cpp.