Passwordfile library  3.1.3
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 ()
 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 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...
 
size_t size ()
 Returns the size of the file if the file is open; returns always zero otherwise. 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 18 of file passwordfile.h.

Constructor & Destructor Documentation

§ PasswordFile() [1/3]

Io::PasswordFile::PasswordFile ( )
explicit

Constructs a new password file.

Definition at line 37 of file passwordfile.cpp.

§ PasswordFile() [2/3]

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 48 of file passwordfile.cpp.

§ PasswordFile() [3/3]

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

Constructs a copy of another password file.

Definition at line 60 of file passwordfile.cpp.

§ ~PasswordFile()

Io::PasswordFile::~PasswordFile ( )

Closes the file if still opened and destroys the instance.

Definition at line 73 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 365 of file passwordfile.cpp.

§ clearEntries()

void Io::PasswordFile::clearEntries ( )

Removes the root element if one is present.

Definition at line 357 of file passwordfile.cpp.

§ clearPassword()

void Io::PasswordFile::clearPassword ( )

Clears the current password.

Definition at line 521 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 495 of file passwordfile.cpp.

§ close()

void Io::PasswordFile::close ( )

Closes the file if currently opened.

Definition at line 467 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 111 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 421 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 381 of file passwordfile.cpp.

§ generateRootEntry()

void Io::PasswordFile::generateRootEntry ( )

Generates a new root entry for the file.

Definition at line 100 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 443 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 529 of file passwordfile.cpp.

§ isOpen()

bool Io::PasswordFile::isOpen ( ) const

Returns an indication whether the file is open.

Definition at line 553 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 128 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 82 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 504 of file passwordfile.cpp.

§ path()

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

Returns the current file path.

Definition at line 478 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 451 of file passwordfile.cpp.

§ rootEntry() [2/2]

NodeEntry * Io::PasswordFile::rootEntry ( )

Returns the root entry if present or nullptr otherwise.

Definition at line 459 of file passwordfile.cpp.

§ save()

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

Writes the current root entry to the file.

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.
ThrowsIo::CryptoException when a decryption error occurs.

Definition at line 255 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 512 of file passwordfile.cpp.

§ setPath()

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

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.


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