Apply clang-format

This commit is contained in:
Martchus 2017-05-01 03:25:30 +02:00
parent d4bb111800
commit 29220159fa
16 changed files with 209 additions and 219 deletions

3
.gitignore vendored
View File

@ -42,3 +42,6 @@ Makefile*
# tests
*.backup
# clang-format
/.clang-format

View File

@ -9,14 +9,14 @@ namespace Io {
/*!
* \brief Constructs a crypto exception.
*/
CryptoException::CryptoException(const std::string &openSslErrorQueue) USE_NOTHROW :
runtime_error(openSslErrorQueue)
{}
CryptoException::CryptoException(const std::string &openSslErrorQueue) USE_NOTHROW : runtime_error(openSslErrorQueue)
{
}
/*!
* \brief Destroys the exception.
*/
CryptoException::~CryptoException() USE_NOTHROW
{}
{
}
}

View File

@ -8,13 +8,11 @@
namespace Io {
class PASSWORD_FILE_EXPORT CryptoException : public std::runtime_error
{
class PASSWORD_FILE_EXPORT CryptoException : public std::runtime_error {
public:
CryptoException(const std::string &openSslErrorQueue) USE_NOTHROW;
virtual ~CryptoException() USE_NOTHROW;
};
}
#endif // CRYPTOFAILUREEXCEPTION_H

View File

@ -4,8 +4,8 @@
#include <c++utilities/io/binaryreader.h>
#include <c++utilities/io/binarywriter.h>
#include <sstream>
#include <algorithm>
#include <sstream>
using namespace std;
using namespace IoUtilities;
@ -29,9 +29,9 @@ namespace Io {
/*!
* \brief Constructs a new entry with the specified \a label and \a parent.
*/
Entry::Entry(const string &label, NodeEntry *parent) :
m_parent(nullptr),
m_index(-1)
Entry::Entry(const string &label, NodeEntry *parent)
: m_parent(nullptr)
, m_index(-1)
{
setParent(parent);
setLabel(label);
@ -42,11 +42,12 @@ Entry::Entry(const string &label, NodeEntry *parent) :
* \remarks The copy will be parentless and thus not be embedded in the hierarchy
* of \a other. Child entries will be copied as well.
*/
Entry::Entry(const Entry &other) :
m_label(other.m_label),
m_parent(nullptr),
m_index(-1)
{}
Entry::Entry(const Entry &other)
: m_label(other.m_label)
, m_parent(nullptr)
, m_index(-1)
{
}
/*!
* \brief Destroys the entry.
@ -102,8 +103,7 @@ void Entry::setParent(NodeEntry *parent, int index)
m_index = parent->m_children.size();
parent->m_children.push_back(this);
} else {
for(auto i = parent->m_children.insert(parent->m_children.begin() + index, this) + 1;
i != parent->m_children.end(); ++i) {
for (auto i = parent->m_children.insert(parent->m_children.begin() + index, this) + 1; i != parent->m_children.end(); ++i) {
(*i)->m_index += 1;
}
m_index = index;
@ -192,24 +192,26 @@ Entry *Entry::parse(istream &stream)
/*!
* \brief Constructs a new node entry.
*/
NodeEntry::NodeEntry() :
Entry(),
m_expandedByDefault(true)
{}
NodeEntry::NodeEntry()
: Entry()
, m_expandedByDefault(true)
{
}
/*!
* \brief Constructs a new node entry with the specified \a label and \a parent.
*/
NodeEntry::NodeEntry(const string &label, NodeEntry *parent) :
Entry(label, parent),
m_expandedByDefault(true)
{}
NodeEntry::NodeEntry(const string &label, NodeEntry *parent)
: Entry(label, parent)
, m_expandedByDefault(true)
{
}
/*!
* \brief Constructs a new node entry which is deserialized from the specified \a stream.
*/
NodeEntry::NodeEntry(istream &stream) :
m_expandedByDefault(true)
NodeEntry::NodeEntry(istream &stream)
: m_expandedByDefault(true)
{
BinaryReader reader(&stream);
byte version = reader.readByte();
@ -242,8 +244,8 @@ NodeEntry::NodeEntry(istream &stream) :
* \remarks The copy will be parentless and thus not be embedded in the hierarchy
* of \a other. Child entries will be copied as well.
*/
NodeEntry::NodeEntry(const NodeEntry &other) :
Entry(other)
NodeEntry::NodeEntry(const NodeEntry &other)
: Entry(other)
{
for (Entry *otherChild : other.m_children) {
Entry *clonedChild = otherChild->clone();
@ -373,14 +375,16 @@ NodeEntry *NodeEntry::clone() const
*/
AccountEntry::AccountEntry()
{}
{
}
/*!
* \brief Constructs a new account entry with the specified \a label and \a parent.
*/
AccountEntry::AccountEntry(const string &label, NodeEntry *parent) :
Entry(label, parent)
{}
AccountEntry::AccountEntry(const string &label, NodeEntry *parent)
: Entry(label, parent)
{
}
/*!
* \brief Constructs a new account entry which is deserialized from the specified \a stream.
@ -415,8 +419,8 @@ AccountEntry::AccountEntry(istream &stream)
* \remarks The copy will be parentless and thus not be embedded in the hierarchy
* of \a other. Child entries will be copied as well.
*/
AccountEntry::AccountEntry(const AccountEntry &other) :
Entry(other)
AccountEntry::AccountEntry(const AccountEntry &other)
: Entry(other)
{
m_fields = other.m_fields;
}
@ -425,7 +429,8 @@ AccountEntry::AccountEntry(const AccountEntry &other) :
* \brief Destroys the entry.
*/
AccountEntry::~AccountEntry()
{}
{
}
void AccountEntry::make(ostream &stream) const
{
@ -446,5 +451,4 @@ AccountEntry *AccountEntry::clone() const
{
return new AccountEntry(*this);
}
}

View File

@ -6,26 +6,25 @@
#include <c++utilities/conversion/types.h>
#include <iostream>
#include <list>
#include <string>
#include <vector>
#include <list>
namespace Io {
/*!
* \brief Specifies the entry type.
*/
enum class EntryType : int
{
enum class EntryType : int {
Node, /**< denotes a NodeEntry */
Account /**< denotes an AccountEntry */
};
class NodeEntry;
class PASSWORD_FILE_EXPORT Entry
{
class PASSWORD_FILE_EXPORT Entry {
friend class NodeEntry;
public:
virtual ~Entry();
Entry &operator=(const Entry &other) = delete;
@ -55,7 +54,6 @@ private:
protected:
std::string m_extendedData;
};
/*!
@ -94,9 +92,9 @@ inline int Entry::index() const
return m_index;
}
class PASSWORD_FILE_EXPORT NodeEntry : public Entry
{
class PASSWORD_FILE_EXPORT NodeEntry : public Entry {
friend class Entry;
public:
NodeEntry();
NodeEntry(const std::string &label, NodeEntry *parent = nullptr);
@ -144,8 +142,7 @@ inline bool Entry::denotesNodeEntry(byte version)
return (version & 0x80) == 0;
}
class PASSWORD_FILE_EXPORT AccountEntry : public Entry
{
class PASSWORD_FILE_EXPORT AccountEntry : public Entry {
public:
AccountEntry();
AccountEntry(const std::string &label, NodeEntry *parent = nullptr);
@ -158,6 +155,7 @@ public:
std::vector<Field> &fields();
virtual void make(std::ostream &stream) const;
virtual AccountEntry *clone() const;
private:
std::vector<Field> m_fields;
};
@ -176,7 +174,6 @@ inline std::vector<Field> &AccountEntry::fields()
{
return m_fields;
}
}
#endif // ENTRY_H

View File

@ -20,12 +20,13 @@ namespace Io {
* \brief Constructs a new account entry for the specified account with the specified \a name
* and \a value.
*/
Field::Field(AccountEntry *tiedAccount, const string &name, const string &value) :
m_name(name),
m_value(value),
m_type(FieldType::Normal),
m_tiedAccount(tiedAccount)
{}
Field::Field(AccountEntry *tiedAccount, const string &name, const string &value)
: m_name(name)
, m_value(value)
, m_type(FieldType::Normal)
, m_tiedAccount(tiedAccount)
{
}
/*!
* \brief Constructs a new account entry for the specified account which is deserialize from
@ -71,5 +72,4 @@ void Field::make(ostream &stream) const
writer.writeString(m_extendedData);
}
}
}

View File

@ -8,16 +8,11 @@
namespace Io {
enum class FieldType : int
{
Normal,
Password
};
enum class FieldType : int { Normal, Password };
class AccountEntry;
class PASSWORD_FILE_EXPORT Field
{
class PASSWORD_FILE_EXPORT Field {
public:
Field(AccountEntry *tiedAccount, const std::string &name = std::string(), const std::string &value = std::string());
Field(AccountEntry *tiedAccount, std::istream &stream);
@ -41,7 +36,6 @@ private:
protected:
std::string m_extendedData;
};
/*!
@ -115,7 +109,6 @@ inline bool Field::isValidType(int number)
{
return number >= 0 && number <= 1;
}
}
#endif // FIELD_H

View File

@ -10,14 +10,14 @@ namespace Io {
/*!
* \brief Constructs a parsing exception.
*/
ParsingException::ParsingException(const std::string &message) USE_NOTHROW :
runtime_error(message)
{}
ParsingException::ParsingException(const std::string &message) USE_NOTHROW : runtime_error(message)
{
}
/*!
* \brief Destroys the exception.
*/
ParsingException::~ParsingException() USE_NOTHROW
{}
{
}
}

View File

@ -8,13 +8,11 @@
namespace Io {
class PASSWORD_FILE_EXPORT ParsingException : public std::runtime_error
{
class PASSWORD_FILE_EXPORT ParsingException : public std::runtime_error {
public:
ParsingException(const std::string &message = std::string()) USE_NOTHROW;
virtual ~ParsingException() USE_NOTHROW;
};
}
#endif // PARSINGEXCEPTION_H

View File

@ -1,7 +1,7 @@
#include "./passwordfile.h"
#include "./cryptoexception.h"
#include "./parsingexception.h"
#include "./entry.h"
#include "./parsingexception.h"
#include <c++utilities/io/catchiofailure.h>
@ -12,11 +12,11 @@
#include <zlib.h>
#include <streambuf>
#include <sstream>
#include <cstring>
#include <memory>
#include <functional>
#include <memory>
#include <sstream>
#include <streambuf>
using namespace std;
using namespace IoUtilities;
@ -34,9 +34,9 @@ const unsigned int aes256cbcIvSize = 16U;
/*!
* \brief Constructs a new password file.
*/
PasswordFile::PasswordFile() :
m_freader(BinaryReader(&m_file)),
m_fwriter(BinaryWriter(&m_file))
PasswordFile::PasswordFile()
: m_freader(BinaryReader(&m_file))
, m_fwriter(BinaryWriter(&m_file))
{
m_file.exceptions(ios_base::failbit | ios_base::badbit);
clearPassword();
@ -45,9 +45,9 @@ PasswordFile::PasswordFile() :
/*!
* \brief Constructs a new password file with the specified \a path and \a password.
*/
PasswordFile::PasswordFile(const string &path, const string &password) :
m_freader(BinaryReader(&m_file)),
m_fwriter(BinaryWriter(&m_file))
PasswordFile::PasswordFile(const string &path, const string &password)
: m_freader(BinaryReader(&m_file))
, m_fwriter(BinaryWriter(&m_file))
{
m_file.exceptions(ios_base::failbit | ios_base::badbit);
setPath(path);
@ -57,10 +57,10 @@ PasswordFile::PasswordFile(const string &path, const string &password) :
/*!
* \brief Constructs a copy of another password file.
*/
PasswordFile::PasswordFile(const PasswordFile &other) :
m_path(other.m_path),
m_freader(BinaryReader(&m_file)),
m_fwriter(BinaryWriter(&m_file))
PasswordFile::PasswordFile(const PasswordFile &other)
: m_path(other.m_path)
, m_freader(BinaryReader(&m_file))
, m_fwriter(BinaryWriter(&m_file))
{
m_file.exceptions(ios_base::failbit | ios_base::badbit);
setPath(other.path());
@ -189,7 +189,9 @@ void PasswordFile::load()
int outlen1, outlen2;
if ((ctx = EVP_CIPHER_CTX_new()) == nullptr
|| EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, reinterpret_cast<unsigned const char *>(m_password), iv) != 1
|| EVP_DecryptUpdate(ctx, reinterpret_cast<unsigned char *>(decbuff.data()), &outlen1, reinterpret_cast<unsigned char *>(rawbuff.data()), size) != 1
|| EVP_DecryptUpdate(
ctx, reinterpret_cast<unsigned char *>(decbuff.data()), &outlen1, reinterpret_cast<unsigned char *>(rawbuff.data()), size)
!= 1
|| EVP_DecryptFinal_ex(ctx, reinterpret_cast<unsigned char *>(decbuff.data()) + outlen1, &outlen2) != 1) {
if (ctx) {
EVP_CIPHER_CTX_free(ctx);
@ -220,7 +222,8 @@ void PasswordFile::load()
}
uLongf decompressedSize = ConversionUtilities::LE::toUInt64(decbuff.data());
rawbuff.resize(decompressedSize);
switch(uncompress(reinterpret_cast<Bytef *>(rawbuff.data()), &decompressedSize, reinterpret_cast<Bytef *>(decbuff.data() + 8), size - static_cast<fstream::pos_type>(8))) {
switch (uncompress(reinterpret_cast<Bytef *>(rawbuff.data()), &decompressedSize, reinterpret_cast<Bytef *>(decbuff.data() + 8),
size - static_cast<fstream::pos_type>(8))) {
case Z_MEM_ERROR:
throw ParsingException("Decompressing failed. The source buffer was too small.");
case Z_BUF_ERROR:
@ -318,10 +321,11 @@ void PasswordFile::save(bool useEncryption, bool useCompression)
unsigned char iv[aes256cbcIvSize];
int outlen1, outlen2;
encbuff.resize(size + static_cast<fstream::pos_type>(32));
if (RAND_bytes(iv, aes256cbcIvSize) != 1
|| (ctx = EVP_CIPHER_CTX_new()) == nullptr
if (RAND_bytes(iv, aes256cbcIvSize) != 1 || (ctx = EVP_CIPHER_CTX_new()) == nullptr
|| EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, reinterpret_cast<unsigned const char *>(m_password), iv) != 1
|| EVP_EncryptUpdate(ctx, reinterpret_cast<unsigned char *>(encbuff.data()), &outlen1, reinterpret_cast<unsigned char *>(decbuff.data()), size) != 1
|| EVP_EncryptUpdate(
ctx, reinterpret_cast<unsigned char *>(encbuff.data()), &outlen1, reinterpret_cast<unsigned char *>(decbuff.data()), size)
!= 1
|| EVP_EncryptFinal_ex(ctx, reinterpret_cast<unsigned char *>(encbuff.data()) + outlen1, &outlen2) != 1) {
if (ctx) {
EVP_CIPHER_CTX_free(ctx);
@ -566,5 +570,4 @@ size_t PasswordFile::size()
m_file.seekg(0, ios::end);
return m_file.tellg();
}
}

View File

@ -6,17 +6,16 @@
#include <c++utilities/io/binaryreader.h>
#include <c++utilities/io/binarywriter.h>
#include <string>
#include <iostream>
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
namespace Io {
class NodeEntry;
class PASSWORD_FILE_EXPORT PasswordFile
{
class PASSWORD_FILE_EXPORT PasswordFile {
public:
explicit PasswordFile();
explicit PasswordFile(const std::string &path, const std::string &password);
@ -44,6 +43,7 @@ public:
bool isEncryptionUsed();
bool isOpen() const;
size_t size();
private:
std::string m_path;
char m_password[32];
@ -54,7 +54,6 @@ private:
IoUtilities::BinaryReader m_freader;
IoUtilities::BinaryWriter m_fwriter;
};
}
#endif // PASSWORDFILE_H

View File

@ -35,7 +35,5 @@ void clean()
// remove error strings
ERR_free_strings();
}
}
}

View File

@ -9,9 +9,7 @@ namespace OpenSsl {
void PASSWORD_FILE_EXPORT init();
void PASSWORD_FILE_EXPORT clean();
}
}
#endif // OPENSSL_H

View File

@ -4,8 +4,8 @@
#include <c++utilities/conversion/binaryconversion.h>
#include <openssl/rand.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <string>
@ -27,12 +27,14 @@ namespace Util {
* \brief Constructs a new random device.
*/
OpenSslRandomDevice::OpenSslRandomDevice()
{}
{
}
/*!
* \brief Generates a new random number.
*/
uint32 OpenSslRandomDevice::operator ()() const {
uint32 OpenSslRandomDevice::operator()() const
{
unsigned char buf[4];
if (RAND_bytes(buf, sizeof(buf))) {
return ConversionUtilities::LE::toUInt32(reinterpret_cast<char *>(buf));
@ -57,5 +59,4 @@ bool OpenSslRandomDevice::status() const
{
return RAND_status();
}
}

View File

@ -7,14 +7,12 @@
namespace Util {
class PASSWORD_FILE_EXPORT OpenSslRandomDevice
{
class PASSWORD_FILE_EXPORT OpenSslRandomDevice {
public:
OpenSslRandomDevice();
uint32 operator()() const;
bool status() const;
};
}
#endif // OPENSSLRANDOMDEVICE_H