Passwordfile library  3.2.0
C++ library to read/write passwords from/to encrypted files
Public Member Functions | List of all members
Io::PasswordFile Class Reference

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 NodeEntryrootEntry () const
 Returns the root entry if present or nullptr otherwise. More...
 
NodeEntryrootEntry ()
 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PasswordFile() [1/4]

Io::PasswordFile::PasswordFile ( )
explicit

Constructs a new password file.

Definition at line 39 of file passwordfile.cpp.

◆ PasswordFile() [2/4]

Io::PasswordFile::PasswordFile ( const std::string &  path,
const std::string &  password 
)
explicit

Constructs a new password file with the specified path and password.

Definition at line 50 of file passwordfile.cpp.

◆ PasswordFile() [3/4]

Io::PasswordFile::PasswordFile ( const PasswordFile other)

Constructs a copy of another password file.

Definition at line 62 of file passwordfile.cpp.

◆ PasswordFile() [4/4]

Io::PasswordFile::PasswordFile ( PasswordFile &&  other)

Moves the password file.

Definition at line 77 of file passwordfile.cpp.

◆ ~PasswordFile()

Io::PasswordFile::~PasswordFile ( )

Closes the file if still opened and destroys the instance.

Definition at line 92 of file passwordfile.cpp.

Member Function Documentation

◆ clear()

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.

◆ clearEntries()

void Io::PasswordFile::clearEntries ( )

Removes the root element if one is present.

Definition at line 439 of file passwordfile.cpp.

◆ clearPassword()

void Io::PasswordFile::clearPassword ( )

Clears the current password.

Definition at line 609 of file passwordfile.cpp.

◆ clearPath()

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.

◆ close()

void Io::PasswordFile::close ( )

Closes the file if currently opened.

Definition at line 550 of file passwordfile.cpp.

◆ create()

void Io::PasswordFile::create ( )

Creates the file.

Does not generate a new root element (see generateRootElement()).

Exceptions
Throwsios_base::failure when an IO error occurs.

Definition at line 139 of file passwordfile.cpp.

◆ doBackup()

void Io::PasswordFile::doBackup ( )

Creates a backup of the file.

Replaces an existent backup file.

Exceptions
Throwsios_base::failure when an IO error occurs.

Definition at line 503 of file passwordfile.cpp.

◆ exportToTextfile()

void Io::PasswordFile::exportToTextfile ( const std::string &  targetPath) const

Writes the current root entry to a plain text file.

No encryption is used.

Parameters
targetPathSpecifies the path of the text file.
Exceptions
Throwsios_base::failure when an IO error occurs.
Throwsruntime_error when no root entry is present.

Definition at line 463 of file passwordfile.cpp.

◆ fileStream()

IoUtilities::NativeFileStream & Io::PasswordFile::fileStream ( )
inline

Returns the underlying file stream.

Definition at line 67 of file passwordfile.h.

◆ generateRootEntry()

void Io::PasswordFile::generateRootEntry ( )

Generates a new root entry for the file.

Definition at line 128 of file passwordfile.cpp.

◆ hasRootEntry()

bool Io::PasswordFile::hasRootEntry ( ) const

Returns an indication whether a root entry is present.

See also
generateRootEntry()
rootEntry()

Definition at line 526 of file passwordfile.cpp.

◆ isEncryptionUsed()

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.

◆ isOpen()

bool Io::PasswordFile::isOpen ( ) const

Returns an indication whether the file is open.

Definition at line 643 of file passwordfile.cpp.

◆ load()

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.

Exceptions
Throwsios_base::failure when an IO error occurs.
ThrowsIo::ParsingException when a parsing error occurs.
ThrowsIo::CryptoException when a decryption error occurs.
ThrowsConversionUtilities::ConversionException when a conversion error occurs.

Definition at line 156 of file passwordfile.cpp.

◆ open()

void Io::PasswordFile::open ( bool  readOnly = false)

Opens the file.

Does not load the contents (see load()).

Exceptions
Throwsios_base::failure when an IO error occurs.

Definition at line 100 of file passwordfile.cpp.

◆ opened()

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.

◆ password()

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.

◆ path()

const string & Io::PasswordFile::path ( ) const

Returns the current file path.

Definition at line 561 of file passwordfile.cpp.

◆ rootEntry() [1/2]

const NodeEntry * Io::PasswordFile::rootEntry ( ) const

Returns the root entry if present or nullptr otherwise.

Definition at line 534 of file passwordfile.cpp.

◆ rootEntry() [2/2]

NodeEntry * Io::PasswordFile::rootEntry ( )

Returns the root entry if present or nullptr otherwise.

Definition at line 542 of file passwordfile.cpp.

◆ save()

void Io::PasswordFile::save ( bool  useEncryption = true,
bool  useCompression = true 
)

Writes the current root entry to the file under path() replacing its previous contents.

Parameters
useEncryptionSpecifies whether encryption should be used.
useCompressionSpecifies whether compression should be used.
Exceptions
Throwsios_base::failure when an IO error occurs.
Throwsruntime_error when no root entry is present or a compression error occurs.
ThrowsIo::CryptoException when an encryption error occurs.

Definition at line 300 of file passwordfile.cpp.

◆ setPassword()

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.

◆ setPath()

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()

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.

◆ write()

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.

Parameters
useEncryptionSpecifies whether encryption should be used.
useCompressionSpecifies whether compression should be used.
Exceptions
Throwsios_base::failure when an IO error occurs.
Throwsruntime_error when no root entry is present or a compression error occurs.
ThrowsIo::CryptoException when an encryption error occurs.

Definition at line 327 of file passwordfile.cpp.


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