diff --git a/src/core/Config.cpp b/src/core/Config.cpp index b0def78aa..c06b4f423 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -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() diff --git a/src/core/Config.h b/src/core/Config.h index f8c57a7e7..8b891ec0d 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -18,7 +18,7 @@ #ifndef KEEPASSX_CONFIG_H #define KEEPASSX_CONFIG_H - +#include #include class QSettings; @@ -32,7 +32,7 @@ public: private: Config(); - QSettings* m_settings; + QScopedPointer m_settings; friend Config* config(); }; diff --git a/src/core/Database.cpp b/src/core/Database.cpp index 91dd0ade6..7ac4a2af1 100644 --- a/src/core/Database.cpp +++ b/src/core/Database.cpp @@ -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())); } diff --git a/src/core/Database.h b/src/core/Database.h index d7c905b11..7190436e8 100644 --- a/src/core/Database.h +++ b/src/core/Database.h @@ -105,7 +105,7 @@ private: void createRecycleBin(); - Metadata* m_metadata; + Metadata* const m_metadata; Group* m_rootGroup; QList m_deletedObjects; @@ -116,7 +116,6 @@ private: QByteArray m_transformedMasterKey; CompositeKey m_key; - bool m_hasKey; }; diff --git a/src/core/Entry.h b/src/core/Entry.h index 57769389c..e7917dd3a 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -117,6 +117,7 @@ private Q_SLOTS: private: const Database* database() const; + template inline bool set(T& property, const T& value); Uuid m_uuid; int m_iconNumber; @@ -137,8 +138,6 @@ private: QPointer m_group; QPixmapCache::Key m_pixmapCacheKey; bool m_updateTimeinfo; - - template inline bool set(T& property, const T& value); }; #endif // KEEPASSX_ENTRY_H diff --git a/src/core/Metadata.h b/src/core/Metadata.h index af6b08a13..78fadc72d 100644 --- a/src/core/Metadata.h +++ b/src/core/Metadata.h @@ -109,7 +109,7 @@ private: template bool set(P& property, const V& value); template bool set(P& property, const V& value, QDateTime& dateTime); - Database* m_parent; + Database* const m_parent; QString m_generator; QString m_name; diff --git a/src/crypto/SymmetricCipher.cpp b/src/crypto/SymmetricCipher.cpp index 2bc0327f0..95f91dc63 100644 --- a/src/crypto/SymmetricCipher.cpp +++ b/src/crypto/SymmetricCipher.cpp @@ -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) diff --git a/src/crypto/SymmetricCipher.h b/src/crypto/SymmetricCipher.h index aaf50f69b..8a24f3172 100644 --- a/src/crypto/SymmetricCipher.h +++ b/src/crypto/SymmetricCipher.h @@ -19,6 +19,7 @@ #define KEEPASSX_SYMMETRICCIPHER_H #include +#include 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 m_backend; Q_DISABLE_COPY(SymmetricCipher) }; diff --git a/src/crypto/SymmetricCipherBackend.h b/src/crypto/SymmetricCipherBackend.h index a4e2b01a8..a46052987 100644 --- a/src/crypto/SymmetricCipherBackend.h +++ b/src/crypto/SymmetricCipherBackend.h @@ -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; diff --git a/src/crypto/SymmetricCipherGcrypt.cpp b/src/crypto/SymmetricCipherGcrypt.cpp index cee66e313..fb501a9e0 100644 --- a/src/crypto/SymmetricCipherGcrypt.cpp +++ b/src/crypto/SymmetricCipherGcrypt.cpp @@ -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; diff --git a/src/crypto/SymmetricCipherGcrypt.h b/src/crypto/SymmetricCipherGcrypt.h index d50a31db9..d8a871dd7 100644 --- a/src/crypto/SymmetricCipherGcrypt.h +++ b/src/crypto/SymmetricCipherGcrypt.h @@ -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; diff --git a/src/crypto/SymmetricCipherSalsa20.cpp b/src/crypto/SymmetricCipherSalsa20.cpp index 25612c980..53af8a8b9 100644 --- a/src/crypto/SymmetricCipherSalsa20.cpp +++ b/src/crypto/SymmetricCipherSalsa20.cpp @@ -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() diff --git a/src/crypto/SymmetricCipherSalsa20.h b/src/crypto/SymmetricCipherSalsa20.h index 872363b84..b2366e45b 100644 --- a/src/crypto/SymmetricCipherSalsa20.h +++ b/src/crypto/SymmetricCipherSalsa20.h @@ -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); diff --git a/src/format/KeePass2Writer.cpp b/src/format/KeePass2Writer.cpp index 1ee11a4d1..4f17cb5c3 100644 --- a/src/format/KeePass2Writer.cpp +++ b/src/format/KeePass2Writer.cpp @@ -33,7 +33,8 @@ #define CHECK_RETURN_FALSE(x) if (!(x)) return false; KeePass2Writer::KeePass2Writer() - : m_error(false) + : m_device(0) + , m_error(false) { } diff --git a/src/gui/ChangeMasterKeyWidget.h b/src/gui/ChangeMasterKeyWidget.h index 647715737..1b8fcc413 100644 --- a/src/gui/ChangeMasterKeyWidget.h +++ b/src/gui/ChangeMasterKeyWidget.h @@ -48,7 +48,7 @@ private Q_SLOTS: void togglePassword(bool checked); private: - QScopedPointer m_ui; + const QScopedPointer m_ui; CompositeKey m_key; Q_DISABLE_COPY(ChangeMasterKeyWidget) diff --git a/src/gui/DatabaseOpenDialog.h b/src/gui/DatabaseOpenDialog.h index 6419a7718..60c6cb6b6 100644 --- a/src/gui/DatabaseOpenDialog.h +++ b/src/gui/DatabaseOpenDialog.h @@ -48,10 +48,10 @@ private Q_SLOTS: void browseKeyFile(); private: - QScopedPointer m_ui; + const QScopedPointer m_ui; Database* m_db; - QFile* m_file; - QString m_filename; + QFile* const m_file; + const QString m_filename; Q_DISABLE_COPY(DatabaseOpenDialog) }; diff --git a/src/gui/DatabaseSettingsWidget.h b/src/gui/DatabaseSettingsWidget.h index c475d568e..28d2dde72 100644 --- a/src/gui/DatabaseSettingsWidget.h +++ b/src/gui/DatabaseSettingsWidget.h @@ -50,7 +50,7 @@ private Q_SLOTS: void reject(); private: - QScopedPointer m_ui; + const QScopedPointer m_ui; QString m_dbName; QString m_dbDescription; diff --git a/src/gui/DatabaseTabWidget.h b/src/gui/DatabaseTabWidget.h index ccf2fb72a..10a7eb873 100644 --- a/src/gui/DatabaseTabWidget.h +++ b/src/gui/DatabaseTabWidget.h @@ -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 m_dbList; DatabaseManagerStruct m_curDbStruct; diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 2ee7495d1..1eb8706c8 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -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; diff --git a/src/gui/EditEntryWidget.h b/src/gui/EditEntryWidget.h index a9dac9269..8b193ac22 100644 --- a/src/gui/EditEntryWidget.h +++ b/src/gui/EditEntryWidget.h @@ -60,22 +60,22 @@ private Q_SLOTS: void setPasswordCheckColors(); private: + bool passwordsEqual(); + Entry* m_entry; - QScopedPointer m_ui; - QScopedPointer m_mainUi; - QScopedPointer m_notesUi; - QScopedPointer m_advancedUi; - QWidget* m_mainWidget; - QWidget* m_notesWidget; - QWidget* m_advancedWidget; + const QScopedPointer m_ui; + const QScopedPointer m_mainUi; + const QScopedPointer m_notesUi; + const QScopedPointer 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) }; diff --git a/src/gui/EditGroupWidget.h b/src/gui/EditGroupWidget.h index b1acf351e..cbf79eba8 100644 --- a/src/gui/EditGroupWidget.h +++ b/src/gui/EditGroupWidget.h @@ -45,7 +45,7 @@ private Q_SLOTS: void cancel(); private: - QScopedPointer m_ui; + const QScopedPointer m_ui; Group* m_group; Q_DISABLE_COPY(EditGroupWidget) diff --git a/src/gui/EntryView.cpp b/src/gui/EntryView.cpp index 2e202dbd3..234ef41a0 100644 --- a/src/gui/EntryView.cpp +++ b/src/gui/EntryView.cpp @@ -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); diff --git a/src/gui/EntryView.h b/src/gui/EntryView.h index 7eef18bd9..99b7d2fcd 100644 --- a/src/gui/EntryView.h +++ b/src/gui/EntryView.h @@ -45,7 +45,7 @@ Q_SIGNALS: void entrySelectionChanged(); private: - EntryModel* m_model; + EntryModel* const m_model; }; #endif // KEEPASSX_ENTRYVIEW_H diff --git a/src/gui/GroupView.cpp b/src/gui/GroupView.cpp index d3d366379..1ffe6da7b 100644 --- a/src/gui/GroupView.cpp +++ b/src/gui/GroupView.cpp @@ -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); diff --git a/src/gui/GroupView.h b/src/gui/GroupView.h index 494e0fd6d..54cf6bf29 100644 --- a/src/gui/GroupView.h +++ b/src/gui/GroupView.h @@ -44,7 +44,7 @@ private Q_SLOTS: private: void recInitExpanded(Group* group); - GroupModel* m_model; + GroupModel* const m_model; }; #endif // KEEPASSX_GROUPVIEW_H diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 0b6381a85..d870d01c5 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -39,9 +39,8 @@ private Q_SLOTS: void setMenuActionState(int index = -1); void updateWindowTitle(); - private: - QScopedPointer m_ui; + const QScopedPointer m_ui; static const QString m_baseWindowTitle; Q_DISABLE_COPY(MainWindow) diff --git a/src/keys/CompositeKey.h b/src/keys/CompositeKey.h index d17e76fb9..6cd86ab8d 100644 --- a/src/keys/CompositeKey.h +++ b/src/keys/CompositeKey.h @@ -37,9 +37,9 @@ public: void addKey(const Key& key); private: - QList m_keys; - static QByteArray transformKeyRaw(const QByteArray& key, const QByteArray& seed, int rounds); + + QList m_keys; }; #endif // KEEPASSX_COMPOSITEKEY_H diff --git a/src/streams/LayeredStream.h b/src/streams/LayeredStream.h index 0c008ae93..f366c63d0 100644 --- a/src/streams/LayeredStream.h +++ b/src/streams/LayeredStream.h @@ -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();