diff --git a/src/core/Endian.cpp b/src/core/Endian.cpp index afe5ce5e..34ddd210 100644 --- a/src/core/Endian.cpp +++ b/src/core/Endian.cpp @@ -27,8 +27,7 @@ #endif #include -namespace Endian -{ +namespace Endian { qint16 bytesToInt16(const QByteArray& ba, QSysInfo::Endian byteOrder) { diff --git a/src/core/Endian.h b/src/core/Endian.h index 023df646..152cf9a1 100644 --- a/src/core/Endian.h +++ b/src/core/Endian.h @@ -23,8 +23,8 @@ class QIODevice; -namespace Endian -{ +namespace Endian { + qint16 bytesToInt16(const QByteArray& ba, QSysInfo::Endian byteOrder); quint16 bytesToUInt16(const QByteArray& ba, QSysInfo::Endian byteOrder); qint32 bytesToInt32(const QByteArray& ba, QSysInfo::Endian byteOrder); @@ -46,6 +46,7 @@ namespace Endian bool writeInt16(qint16 num, QIODevice* device, QSysInfo::Endian byteOrder); bool writeInt32(qint32 num, QIODevice* device, QSysInfo::Endian byteOrder); bool writeInt64(qint64 num, QIODevice* device, QSysInfo::Endian byteOrder); -}; + +} // namespace Endian #endif // KEEPASSX_ENDIAN_H diff --git a/src/core/EntryAttributes.cpp b/src/core/EntryAttributes.cpp index c81bdc40..eec7c364 100644 --- a/src/core/EntryAttributes.cpp +++ b/src/core/EntryAttributes.cpp @@ -17,7 +17,8 @@ #include "EntryAttributes.h" -const QStringList EntryAttributes::DEFAULT_ATTRIBUTES(QStringList() << "Title" << "URL" << "UserName" << "Password" << "Notes"); +const QStringList EntryAttributes::DEFAULT_ATTRIBUTES(QStringList() << "Title" << "URL" + << "UserName" << "Password" << "Notes"); EntryAttributes::EntryAttributes(QObject* parent) : QObject(parent) diff --git a/src/core/EntryAttributes.h b/src/core/EntryAttributes.h index 03a696db..490b5567 100644 --- a/src/core/EntryAttributes.h +++ b/src/core/EntryAttributes.h @@ -38,7 +38,7 @@ public: void clear(); bool areCustomKeysDifferent(const EntryAttributes* other); - const static QStringList DEFAULT_ATTRIBUTES; + static const QStringList DEFAULT_ATTRIBUTES; static bool isDefaultAttribute(const QString& key); Q_SIGNALS: @@ -51,7 +51,7 @@ Q_SIGNALS: void removed(QString key); void aboutToBeReset(); void reset(); - + private: QMap m_attributes; QSet m_protectedAttributes; diff --git a/src/core/TimeInfo.cpp b/src/core/TimeInfo.cpp index 142082f3..404e2bbf 100644 --- a/src/core/TimeInfo.cpp +++ b/src/core/TimeInfo.cpp @@ -59,6 +59,7 @@ int TimeInfo::usageCount() const { return m_usageCount; } + QDateTime TimeInfo::locationChanged() const { return m_locationChanged; diff --git a/src/core/TimeInfo.h b/src/core/TimeInfo.h index 079c5fbb..2c8d505c 100644 --- a/src/core/TimeInfo.h +++ b/src/core/TimeInfo.h @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -#ifndef KEEPASSX_DBTIMEINFO_H -#define KEEPASSX_DBTIMEINFO_H +#ifndef KEEPASSX_TIMEINFO_H +#define KEEPASSX_TIMEINFO_H #include @@ -51,4 +51,4 @@ private: QDateTime m_locationChanged; }; -#endif // KEEPASSX_DBTIMEINFO_H +#endif // KEEPASSX_TIMEINFO_H diff --git a/src/core/Tools.cpp b/src/core/Tools.cpp index 263e557f..9a553d54 100644 --- a/src/core/Tools.cpp +++ b/src/core/Tools.cpp @@ -20,7 +20,9 @@ #include #include -QString Tools::humanReadableFileSize(qint64 bytes) +namespace Tools { + +QString humanReadableFileSize(qint64 bytes) { double size = bytes; @@ -35,3 +37,5 @@ QString Tools::humanReadableFileSize(qint64 bytes) return QString("%1 %2").arg(QLocale().toString(size, 'f', 2), units.at(i)); } + +} // namespace Tools diff --git a/src/core/Tools.h b/src/core/Tools.h index eb5c3c17..45be9b59 100644 --- a/src/core/Tools.h +++ b/src/core/Tools.h @@ -24,6 +24,6 @@ namespace Tools { QString humanReadableFileSize(qint64 bytes); -} +} // namespace Tools #endif // KEEPASSX_TOOLS_H diff --git a/src/core/Uuid.cpp b/src/core/Uuid.cpp index 48005507..a97b9585 100644 --- a/src/core/Uuid.cpp +++ b/src/core/Uuid.cpp @@ -51,7 +51,7 @@ QByteArray Uuid::toByteArray() const bool Uuid::isNull() const { - for (int i=0; i(m_key.constData()), m_key.size()*8, 64); @@ -60,7 +60,7 @@ void SymmetricCipherSalsa20::setIv(const QByteArray& iv) QByteArray SymmetricCipherSalsa20::process(const QByteArray& data) { - Q_ASSERT( (data.size() < blockSize()) || ((data.size() % blockSize())==0) ); + Q_ASSERT((data.size() < blockSize()) || ((data.size() % blockSize()) == 0)); QByteArray result; result.resize(data.size()); @@ -73,7 +73,7 @@ QByteArray SymmetricCipherSalsa20::process(const QByteArray& data) void SymmetricCipherSalsa20::processInPlace(QByteArray& data) { - Q_ASSERT( (data.size() < blockSize()) || ((data.size() % blockSize())==0) ); + Q_ASSERT((data.size() < blockSize()) || ((data.size() % blockSize()) == 0)); ECRYPT_encrypt_bytes(&m_ctx, reinterpret_cast(data.constData()), reinterpret_cast(data.data()), data.size()); diff --git a/src/format/KeePass2RandomStream.cpp b/src/format/KeePass2RandomStream.cpp index 46df2d50..8b4a7c8e 100644 --- a/src/format/KeePass2RandomStream.cpp +++ b/src/format/KeePass2RandomStream.cpp @@ -53,7 +53,7 @@ QByteArray KeePass2RandomStream::process(const QByteArray& data) QByteArray result; result.resize(data.size()); - for (int i=0; itransformedMasterKey()); QByteArray finalKey = hash.result(); - SymmetricCipherStream cipherStream(device, SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Decrypt, finalKey, m_encryptionIV); + SymmetricCipherStream cipherStream(device, SymmetricCipher::Aes256, SymmetricCipher::Cbc, + SymmetricCipher::Decrypt, finalKey, m_encryptionIV); cipherStream.open(QIODevice::ReadOnly); QByteArray realStart = cipherStream.read(32); diff --git a/src/format/KeePass2Writer.cpp b/src/format/KeePass2Writer.cpp index 35a3eecc..1ee11a4d 100644 --- a/src/format/KeePass2Writer.cpp +++ b/src/format/KeePass2Writer.cpp @@ -62,17 +62,24 @@ void KeePass2Writer::writeDatabase(QIODevice* device, Database* db) CHECK_RETURN(writeData(Endian::int32ToBytes(KeePass2::FILE_VERSION, KeePass2::BYTEORDER))); CHECK_RETURN(writeHeaderField(KeePass2::CipherID, db->cipher().toByteArray())); - CHECK_RETURN(writeHeaderField(KeePass2::CompressionFlags, Endian::int32ToBytes(db->compressionAlgo(), KeePass2::BYTEORDER))); + CHECK_RETURN(writeHeaderField(KeePass2::CompressionFlags, + Endian::int32ToBytes(db->compressionAlgo(), + KeePass2::BYTEORDER))); CHECK_RETURN(writeHeaderField(KeePass2::MasterSeed, masterSeed)); CHECK_RETURN(writeHeaderField(KeePass2::TransformSeed, db->transformSeed())); - CHECK_RETURN(writeHeaderField(KeePass2::TransformRounds, Endian::int64ToBytes(db->transformRounds(), KeePass2::BYTEORDER))); + CHECK_RETURN(writeHeaderField(KeePass2::TransformRounds, + Endian::int64ToBytes(db->transformRounds(), + KeePass2::BYTEORDER))); CHECK_RETURN(writeHeaderField(KeePass2::EncryptionIV, encryptionIV)); CHECK_RETURN(writeHeaderField(KeePass2::ProtectedStreamKey, protectedStreamKey)); CHECK_RETURN(writeHeaderField(KeePass2::StreamStartBytes, startBytes)); - CHECK_RETURN(writeHeaderField(KeePass2::InnerRandomStreamID, Endian::int32ToBytes(KeePass2::Salsa20, KeePass2::BYTEORDER))); + CHECK_RETURN(writeHeaderField(KeePass2::InnerRandomStreamID, + Endian::int32ToBytes(KeePass2::Salsa20, + KeePass2::BYTEORDER))); CHECK_RETURN(writeHeaderField(KeePass2::EndOfHeader, endOfHeader)); - SymmetricCipherStream cipherStream(device, SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Encrypt, finalKey, encryptionIV); + SymmetricCipherStream cipherStream(device, SymmetricCipher::Aes256, SymmetricCipher::Cbc, + SymmetricCipher::Encrypt, finalKey, encryptionIV); cipherStream.open(QIODevice::WriteOnly); m_device = &cipherStream; CHECK_RETURN(writeData(startBytes)); diff --git a/src/format/KeePass2XmlReader.cpp b/src/format/KeePass2XmlReader.cpp index 2a9c00e2..d6177282 100644 --- a/src/format/KeePass2XmlReader.cpp +++ b/src/format/KeePass2XmlReader.cpp @@ -376,7 +376,6 @@ Group* KeePass2XmlReader::parseGroup() else { raiseError(3); } - } else if (m_xml.name() == "EnableSearching") { QString str = readString(); @@ -733,7 +732,7 @@ QColor KeePass2XmlReader::readColor() } QColor color; - for (int i=0; i<= 2; i++) { + for (int i = 0; i <= 2; i++) { QString rgbPartStr = colorStr.mid(1 + 2*i, 2); bool ok; int rgbPart = rgbPartStr.toInt(&ok, 16); diff --git a/src/gui/ChangeMasterKeyWidget.cpp b/src/gui/ChangeMasterKeyWidget.cpp index 8dec41fb..df3e3c75 100644 --- a/src/gui/ChangeMasterKeyWidget.cpp +++ b/src/gui/ChangeMasterKeyWidget.cpp @@ -65,7 +65,9 @@ void ChangeMasterKeyWidget::generateKey() if (m_ui->passwordGroup->isChecked()) { if (m_ui->enterPasswordEdit->text() == m_ui->repeatPasswordEdit->text()) { if (m_ui->enterPasswordEdit->text().isEmpty()) { - if (QMessageBox::question(this, tr("Question"), tr("Do you really want to use an empty string as password?"), QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { + if (QMessageBox::question(this, tr("Question"), + tr("Do you really want to use an empty string as password?"), + QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { return; } } diff --git a/src/gui/DatabaseOpenDialog.h b/src/gui/DatabaseOpenDialog.h index 0c2a3037..6419a771 100644 --- a/src/gui/DatabaseOpenDialog.h +++ b/src/gui/DatabaseOpenDialog.h @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -#ifndef KEEPASSX_KEYOPENDIALOG_H -#define KEEPASSX_KEYOPENDIALOG_H +#ifndef KEEPASSX_DATABASEOPENDIALOG_H +#define KEEPASSX_DATABASEOPENDIALOG_H #include #include @@ -56,4 +56,4 @@ private: Q_DISABLE_COPY(DatabaseOpenDialog) }; -#endif // KEEPASSX_KEYOPENDIALOG_H +#endif // KEEPASSX_DATABASEOPENDIALOG_H diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index e4f67ce0..7c499713 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -159,7 +159,6 @@ void DatabaseWidget::updateMasterKey(bool accepted) { if (accepted) { m_db->setKey(m_changeMasterKeyWidget->newMasterKey()); - } else if (!m_db->hasKey()) { Q_EMIT closeRequest(); diff --git a/src/gui/EditEntryWidget_p.h b/src/gui/EditEntryWidget_p.h index 3c3b3b2d..b4153a35 100644 --- a/src/gui/EditEntryWidget_p.h +++ b/src/gui/EditEntryWidget_p.h @@ -26,7 +26,7 @@ class CategoryListViewDelegate : public QStyledItemDelegate { public: - CategoryListViewDelegate(QObject *parent) : QStyledItemDelegate(parent) {} + explicit CategoryListViewDelegate(QObject *parent) : QStyledItemDelegate(parent) {} QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { @@ -39,7 +39,7 @@ public: class CategoryListWidget : public QListWidget { public: - CategoryListWidget(QWidget* parent = 0) : QListWidget(parent) + explicit CategoryListWidget(QWidget* parent = 0) : QListWidget(parent) { setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding); setItemDelegate(new CategoryListViewDelegate(this)); diff --git a/src/gui/EditGroupWidget.h b/src/gui/EditGroupWidget.h index 5d7d0c7b..b1acf351 100644 --- a/src/gui/EditGroupWidget.h +++ b/src/gui/EditGroupWidget.h @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -#ifndef KEEPASSX_GROUPDIALOG_H -#define KEEPASSX_GROUPDIALOG_H +#ifndef KEEPASSX_EDITGROUPWIDGET_H +#define KEEPASSX_EDITGROUPWIDGET_H #include #include @@ -51,4 +51,4 @@ private: Q_DISABLE_COPY(EditGroupWidget) }; -#endif // KEEPASSX_GROUPDIALOG_H +#endif // KEEPASSX_EDITGROUPWIDGET_H diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 45d5f0e9..d25585aa 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -65,7 +65,7 @@ void MainWindow::setMenuActionState(int index) index = dbWidget->currentIndex(); } - switch(index) { + switch (index) { case 0: // view m_ui->actionEntryNew->setEnabled(true); m_ui->actionGroupNew->setEnabled(true); diff --git a/src/keys/CompositeKey.cpp b/src/keys/CompositeKey.cpp index 094e669a..a0b10d54 100644 --- a/src/keys/CompositeKey.cpp +++ b/src/keys/CompositeKey.cpp @@ -17,11 +17,11 @@ #include "CompositeKey.h" +#include + #include "crypto/CryptoHash.h" #include "crypto/SymmetricCipher.h" -#include - CompositeKey::CompositeKey() { } @@ -90,7 +90,7 @@ QByteArray CompositeKey::transformKeyRaw(const QByteArray& key, const QByteArray QByteArray result = key; - for (int i=0; isize() == 0) { - return false; - } + if (device->size() == 0) { + return false; + } - if (!device->reset()) { - return false; - } - if (loadXml(device)) { - return true; - } + if (!device->reset()) { + return false; + } + if (loadXml(device)) { + return true; + } - if (!device->reset()) { - return false; - } - if (loadBinary(device)) { - return true; - } + if (!device->reset()) { + return false; + } + if (loadBinary(device)) { + return true; + } - if (!device->reset()) { - return false; - } - if (loadHex(device)) { - return true; - } + if (!device->reset()) { + return false; + } + if (loadHex(device)) { + return true; + } - if (!device->reset()) { - return false; - } - if (loadHashed(device)) { - return true; - } + if (!device->reset()) { + return false; + } + if (loadHashed(device)) { + return true; + } - return false; + return false; } bool FileKey::load(const QString& fileName, QString* errorMsg) diff --git a/src/main.cpp b/src/main.cpp index 4e336ca7..21bec90c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,17 +35,6 @@ int main(int argc, char **argv) Crypto::init(); - CompositeKey key; - PasswordKey password; - password.setPassword("a"); - key.addKey(password); - - //KeePass2Reader* xreader = new KeePass2Reader(); - //Database* db = xreader->readDatabase(QString(KEEPASSX_TEST_DIR).append("/NewDatabase.kdbx"), key); - - //KeePass2XmlReader* reader = new KeePass2XmlReader(); - //Database* db = reader->readDatabase(QString(KEEPASSX_TEST_DIR).append("/NewDatabase.xml")); - MainWindow mainWindow; mainWindow.show(); diff --git a/src/streams/SymmetricCipherStream.cpp b/src/streams/SymmetricCipherStream.cpp index 2d2a7888..634d004b 100644 --- a/src/streams/SymmetricCipherStream.cpp +++ b/src/streams/SymmetricCipherStream.cpp @@ -148,7 +148,7 @@ bool SymmetricCipherStream::writeBlock() else if (m_buffer.size() != m_cipher->blockSize()) { // PKCS7 padding int padLen = m_cipher->blockSize() - m_buffer.size(); - for (int i=m_buffer.size(); iblockSize(); i++) { + for (int i = m_buffer.size(); i < m_cipher->blockSize(); i++) { m_buffer.append(static_cast(padLen)); } } diff --git a/tests/TestKeePass2RandomStream.cpp b/tests/TestKeePass2RandomStream.cpp index cf520d1d..5e2e381c 100644 --- a/tests/TestKeePass2RandomStream.cpp +++ b/tests/TestKeePass2RandomStream.cpp @@ -52,7 +52,7 @@ void TestKeePass2RandomStream::test() QByteArray cipherData; cipherData.resize(SIZE); - for (int i=0; i