Constification and some style fixes.

This commit is contained in:
Felix Geyer 2012-04-23 19:44:43 +02:00
parent b3ddfca2bd
commit 3df2ad35cb
28 changed files with 84 additions and 105 deletions

View File

@ -64,7 +64,7 @@ Config::Config()
userPath += "keepassx2.ini";
m_settings = new QSettings(userPath, QSettings::IniFormat);
m_settings.reset(new QSettings(userPath, QSettings::IniFormat));
}
Config* config()

View File

@ -18,7 +18,7 @@
#ifndef KEEPASSX_CONFIG_H
#define KEEPASSX_CONFIG_H
#include <QtCore/QScopedPointer>
#include <QtCore/QVariant>
class QSettings;
@ -32,7 +32,7 @@ public:
private:
Config();
QSettings* m_settings;
QScopedPointer<QSettings> m_settings;
friend Config* config();
};

View File

@ -26,16 +26,15 @@
#include "format/KeePass2.h"
Database::Database()
: m_metadata(new Metadata(this))
, m_cipher(KeePass2::CIPHER_AES)
, m_compressionAlgo(CompressionGZip)
, m_transformRounds(50000)
, m_hasKey(false)
{
m_hasKey = false;
m_metadata = new Metadata(this);
setRootGroup(new Group());
rootGroup()->setUuid(Uuid::random());
m_cipher = KeePass2::CIPHER_AES;
m_compressionAlgo = CompressionGZip;
m_transformRounds = 50000;
connect(m_metadata, SIGNAL(modified()), this, SIGNAL(modified()));
}

View File

@ -105,7 +105,7 @@ private:
void createRecycleBin();
Metadata* m_metadata;
Metadata* const m_metadata;
Group* m_rootGroup;
QList<DeletedObject> m_deletedObjects;
@ -116,7 +116,6 @@ private:
QByteArray m_transformedMasterKey;
CompositeKey m_key;
bool m_hasKey;
};

View File

@ -117,6 +117,7 @@ private Q_SLOTS:
private:
const Database* database() const;
template <class T> inline bool set(T& property, const T& value);
Uuid m_uuid;
int m_iconNumber;
@ -137,8 +138,6 @@ private:
QPointer<Group> m_group;
QPixmapCache::Key m_pixmapCacheKey;
bool m_updateTimeinfo;
template <class T> inline bool set(T& property, const T& value);
};
#endif // KEEPASSX_ENTRY_H

View File

@ -109,7 +109,7 @@ private:
template <class P, class V> bool set(P& property, const V& value);
template <class P, class V> bool set(P& property, const V& value, QDateTime& dateTime);
Database* m_parent;
Database* const m_parent;
QString m_generator;
QString m_name;

View File

@ -22,24 +22,8 @@
SymmetricCipher::SymmetricCipher(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
SymmetricCipher::Direction direction, const QByteArray& key, const QByteArray& iv)
: m_backend(createBackend(algo, mode, direction))
{
switch (algo) {
case SymmetricCipher::Aes256:
m_backend = new SymmetricCipherGcrypt();
break;
case SymmetricCipher::Salsa20:
m_backend = new SymmetricCipherSalsa20();
break;
default:
Q_ASSERT(false);
break;
}
m_backend->setAlgorithm(algo);
m_backend->setMode(mode);
m_backend->setDirection(direction);
m_backend->init();
m_backend->setKey(key);
m_backend->setIv(iv);
@ -47,7 +31,22 @@ SymmetricCipher::SymmetricCipher(SymmetricCipher::Algorithm algo, SymmetricCiphe
SymmetricCipher::~SymmetricCipher()
{
delete m_backend;
}
SymmetricCipherBackend* SymmetricCipher::createBackend(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
SymmetricCipher::Direction direction)
{
switch (algo) {
case SymmetricCipher::Aes256:
return new SymmetricCipherGcrypt(algo, mode, direction);
case SymmetricCipher::Salsa20:
return new SymmetricCipherSalsa20(algo, mode, direction);
default:
Q_ASSERT(false);
return 0;
}
}
QByteArray SymmetricCipher::process(const QByteArray& data)

View File

@ -19,6 +19,7 @@
#define KEEPASSX_SYMMETRICCIPHER_H
#include <QtCore/QByteArray>
#include <QtCore/QScopedPointer>
class SymmetricCipherBackend;
@ -55,7 +56,10 @@ public:
int blockSize() const;
private:
SymmetricCipherBackend* m_backend;
static SymmetricCipherBackend* createBackend(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
SymmetricCipher::Direction direction);
const QScopedPointer<SymmetricCipherBackend> m_backend;
Q_DISABLE_COPY(SymmetricCipher)
};

View File

@ -24,9 +24,6 @@ class SymmetricCipherBackend
{
public:
virtual ~SymmetricCipherBackend() {}
virtual void setAlgorithm(SymmetricCipher::Algorithm algo) = 0;
virtual void setMode(SymmetricCipher::Mode mode) = 0;
virtual void setDirection(SymmetricCipher::Direction direction) = 0;
virtual void init() = 0;
virtual void setKey(const QByteArray& key) = 0;
virtual void setIv(const QByteArray& iv) = 0;

View File

@ -19,9 +19,14 @@
#include "crypto/Crypto.h"
SymmetricCipherGcrypt::SymmetricCipherGcrypt()
SymmetricCipherGcrypt::SymmetricCipherGcrypt(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
SymmetricCipher::Direction direction)
: m_algo(GCRY_CIPHER_AES256)
, m_mode(gcryptMode(mode))
, m_direction(direction)
{
Q_ASSERT(Crypto::initalized());
Q_ASSERT(algo == SymmetricCipher::Aes256);
}
SymmetricCipherGcrypt::~SymmetricCipherGcrypt()
@ -29,41 +34,21 @@ SymmetricCipherGcrypt::~SymmetricCipherGcrypt()
gcry_cipher_close(m_ctx);
}
void SymmetricCipherGcrypt::setAlgorithm(SymmetricCipher::Algorithm algo)
{
switch (algo) {
case SymmetricCipher::Aes256:
m_algo = GCRY_CIPHER_AES256;
break;
default:
Q_ASSERT(false);
break;
}
}
void SymmetricCipherGcrypt::setMode(SymmetricCipher::Mode mode)
int SymmetricCipherGcrypt::gcryptMode(SymmetricCipher::Mode mode)
{
switch (mode) {
case SymmetricCipher::Ecb:
m_mode = GCRY_CIPHER_MODE_ECB;
break;
return GCRY_CIPHER_MODE_ECB;
case SymmetricCipher::Cbc:
m_mode = GCRY_CIPHER_MODE_CBC;
break;
return GCRY_CIPHER_MODE_CBC;
default:
Q_ASSERT(false);
break;
return -1;
}
}
void SymmetricCipherGcrypt::setDirection(SymmetricCipher::Direction direction)
{
m_direction = direction;
}
void SymmetricCipherGcrypt::init()
{
gcry_error_t error;

View File

@ -25,11 +25,9 @@
class SymmetricCipherGcrypt : public SymmetricCipherBackend
{
public:
SymmetricCipherGcrypt();
SymmetricCipherGcrypt(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
SymmetricCipher::Direction direction);
~SymmetricCipherGcrypt();
void setAlgorithm(SymmetricCipher::Algorithm algo);
void setMode(SymmetricCipher::Mode mode);
void setDirection(SymmetricCipher::Direction direction);
void init();
void setKey(const QByteArray& key);
void setIv(const QByteArray& iv);
@ -41,10 +39,12 @@ public:
int blockSize() const;
private:
static int gcryptMode(SymmetricCipher::Mode mode);
gcry_cipher_hd_t m_ctx;
int m_algo;
int m_mode;
SymmetricCipher::Direction m_direction;
const int m_algo;
const int m_mode;
const SymmetricCipher::Direction m_direction;
QByteArray m_key;
QByteArray m_iv;
int m_blockSize;

View File

@ -17,25 +17,20 @@
#include "SymmetricCipherSalsa20.h"
SymmetricCipherSalsa20::~SymmetricCipherSalsa20()
{
}
void SymmetricCipherSalsa20::setAlgorithm(SymmetricCipher::Algorithm algo)
SymmetricCipherSalsa20::SymmetricCipherSalsa20(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
SymmetricCipher::Direction direction)
{
Q_ASSERT(algo == SymmetricCipher::Salsa20);
Q_UNUSED(algo);
}
void SymmetricCipherSalsa20::setMode(SymmetricCipher::Mode mode)
{
Q_ASSERT(mode == SymmetricCipher::Stream);
Q_UNUSED(mode);
Q_UNUSED(direction);
}
void SymmetricCipherSalsa20::setDirection(SymmetricCipher::Direction direction)
SymmetricCipherSalsa20::~SymmetricCipherSalsa20()
{
Q_UNUSED(direction);
}
void SymmetricCipherSalsa20::init()

View File

@ -24,6 +24,8 @@
class SymmetricCipherSalsa20 : public SymmetricCipherBackend
{
public:
SymmetricCipherSalsa20(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
SymmetricCipher::Direction direction);
~SymmetricCipherSalsa20();
void setAlgorithm(SymmetricCipher::Algorithm algo);
void setMode(SymmetricCipher::Mode mode);

View File

@ -33,7 +33,8 @@
#define CHECK_RETURN_FALSE(x) if (!(x)) return false;
KeePass2Writer::KeePass2Writer()
: m_error(false)
: m_device(0)
, m_error(false)
{
}

View File

@ -48,7 +48,7 @@ private Q_SLOTS:
void togglePassword(bool checked);
private:
QScopedPointer<Ui::ChangeMasterKeyWidget> m_ui;
const QScopedPointer<Ui::ChangeMasterKeyWidget> m_ui;
CompositeKey m_key;
Q_DISABLE_COPY(ChangeMasterKeyWidget)

View File

@ -48,10 +48,10 @@ private Q_SLOTS:
void browseKeyFile();
private:
QScopedPointer<Ui::DatabaseOpenDialog> m_ui;
const QScopedPointer<Ui::DatabaseOpenDialog> m_ui;
Database* m_db;
QFile* m_file;
QString m_filename;
QFile* const m_file;
const QString m_filename;
Q_DISABLE_COPY(DatabaseOpenDialog)
};

View File

@ -50,7 +50,7 @@ private Q_SLOTS:
void reject();
private:
QScopedPointer<Ui::DatabaseSettingsWidget> m_ui;
const QScopedPointer<Ui::DatabaseSettingsWidget> m_ui;
QString m_dbName;
QString m_dbDescription;

View File

@ -91,7 +91,7 @@ private:
Database* databaseFromDatabaseWidget(DatabaseWidget* dbWidget);
void insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct);
QWidget* m_window;
QWidget* const m_window;
KeePass2Writer m_writer;
QHash<Database*, DatabaseManagerStruct> m_dbList;
DatabaseManagerStruct m_curDbStruct;

View File

@ -63,7 +63,7 @@ private Q_SLOTS:
void updateSettings(bool accepted);
private:
Database* m_db;
Database* const m_db;
QWidget* m_mainWidget;
EditEntryWidget* m_editEntryWidget;
EditGroupWidget* m_editGroupWidget;

View File

@ -60,22 +60,22 @@ private Q_SLOTS:
void setPasswordCheckColors();
private:
bool passwordsEqual();
Entry* m_entry;
QScopedPointer<Ui::EditEntryWidget> m_ui;
QScopedPointer<Ui::EditEntryWidgetMain> m_mainUi;
QScopedPointer<Ui::EditEntryWidgetNotes> m_notesUi;
QScopedPointer<Ui::EditEntryWidgetAdvanced> m_advancedUi;
QWidget* m_mainWidget;
QWidget* m_notesWidget;
QWidget* m_advancedWidget;
const QScopedPointer<Ui::EditEntryWidget> m_ui;
const QScopedPointer<Ui::EditEntryWidgetMain> m_mainUi;
const QScopedPointer<Ui::EditEntryWidgetNotes> m_notesUi;
const QScopedPointer<Ui::EditEntryWidgetAdvanced> m_advancedUi;
QWidget* const m_mainWidget;
QWidget* const m_notesWidget;
QWidget* const m_advancedWidget;
EntryAttachmentsModel* m_attachmentsModel;
EntryAttributesModel* m_attributesModel;
EntryAttachments* m_entryAttachments;
EntryAttributes* m_entryAttributes;
bool passwordsEqual();
Q_DISABLE_COPY(EditEntryWidget)
};

View File

@ -45,7 +45,7 @@ private Q_SLOTS:
void cancel();
private:
QScopedPointer<Ui::EditGroupWidget> m_ui;
const QScopedPointer<Ui::EditGroupWidget> m_ui;
Group* m_group;
Q_DISABLE_COPY(EditGroupWidget)

View File

@ -21,8 +21,8 @@
EntryView::EntryView(QWidget* parent)
: QTreeView(parent)
, m_model(new EntryModel(this))
{
m_model = new EntryModel(this);
QTreeView::setModel(m_model);
setUniformRowHeights(true);

View File

@ -45,7 +45,7 @@ Q_SIGNALS:
void entrySelectionChanged();
private:
EntryModel* m_model;
EntryModel* const m_model;
};
#endif // KEEPASSX_ENTRYVIEW_H

View File

@ -25,8 +25,8 @@
GroupView::GroupView(Database* db, QWidget* parent)
: QTreeView(parent)
, m_model(new GroupModel(db, this))
{
m_model = new GroupModel(db, this);
QTreeView::setModel(m_model);
setHeaderHidden(true);
setUniformRowHeights(true);

View File

@ -44,7 +44,7 @@ private Q_SLOTS:
private:
void recInitExpanded(Group* group);
GroupModel* m_model;
GroupModel* const m_model;
};
#endif // KEEPASSX_GROUPVIEW_H

View File

@ -39,9 +39,8 @@ private Q_SLOTS:
void setMenuActionState(int index = -1);
void updateWindowTitle();
private:
QScopedPointer<Ui::MainWindow> m_ui;
const QScopedPointer<Ui::MainWindow> m_ui;
static const QString m_baseWindowTitle;
Q_DISABLE_COPY(MainWindow)

View File

@ -37,9 +37,9 @@ public:
void addKey(const Key& key);
private:
QList<Key*> m_keys;
static QByteArray transformKeyRaw(const QByteArray& key, const QByteArray& seed, int rounds);
QList<Key*> m_keys;
};
#endif // KEEPASSX_COMPOSITEKEY_H

View File

@ -36,7 +36,7 @@ protected:
qint64 readData(char* data, qint64 maxSize);
qint64 writeData(const char* data, qint64 maxSize);
QIODevice* m_baseDevice;
QIODevice* const m_baseDevice;
private Q_SLOTS:
void closeStream();