mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-06-29 00:47:32 -04:00
Improve code style.
This commit is contained in:
parent
4e5e5c71ca
commit
2e011d5362
29 changed files with 95 additions and 89 deletions
|
@ -27,8 +27,7 @@
|
|||
#endif
|
||||
#include <QtCore/QIODevice>
|
||||
|
||||
namespace Endian
|
||||
{
|
||||
namespace Endian {
|
||||
|
||||
qint16 bytesToInt16(const QByteArray& ba, QSysInfo::Endian byteOrder)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -59,6 +59,7 @@ int TimeInfo::usageCount() const
|
|||
{
|
||||
return m_usageCount;
|
||||
}
|
||||
|
||||
QDateTime TimeInfo::locationChanged() const
|
||||
{
|
||||
return m_locationChanged;
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KEEPASSX_DBTIMEINFO_H
|
||||
#define KEEPASSX_DBTIMEINFO_H
|
||||
#ifndef KEEPASSX_TIMEINFO_H
|
||||
#define KEEPASSX_TIMEINFO_H
|
||||
|
||||
#include <QtCore/QDateTime>
|
||||
|
||||
|
@ -51,4 +51,4 @@ private:
|
|||
QDateTime m_locationChanged;
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_DBTIMEINFO_H
|
||||
#endif // KEEPASSX_TIMEINFO_H
|
||||
|
|
|
@ -20,7 +20,9 @@
|
|||
#include <QtCore/QLocale>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
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
|
||||
|
|
|
@ -24,6 +24,6 @@ namespace Tools {
|
|||
|
||||
QString humanReadableFileSize(qint64 bytes);
|
||||
|
||||
}
|
||||
} // namespace Tools
|
||||
|
||||
#endif // KEEPASSX_TOOLS_H
|
||||
|
|
|
@ -79,7 +79,8 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke
|
|||
hash.addData(m_db->transformedMasterKey());
|
||||
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);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -376,7 +376,6 @@ Group* KeePass2XmlReader::parseGroup()
|
|||
else {
|
||||
raiseError(3);
|
||||
}
|
||||
|
||||
}
|
||||
else if (m_xml.name() == "EnableSearching") {
|
||||
QString str = readString();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KEEPASSX_KEYOPENDIALOG_H
|
||||
#define KEEPASSX_KEYOPENDIALOG_H
|
||||
#ifndef KEEPASSX_DATABASEOPENDIALOG_H
|
||||
#define KEEPASSX_DATABASEOPENDIALOG_H
|
||||
|
||||
#include <QtCore/QScopedPointer>
|
||||
#include <QtGui/QDialog>
|
||||
|
@ -56,4 +56,4 @@ private:
|
|||
Q_DISABLE_COPY(DatabaseOpenDialog)
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_KEYOPENDIALOG_H
|
||||
#endif // KEEPASSX_DATABASEOPENDIALOG_H
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef KEEPASSX_GROUPDIALOG_H
|
||||
#define KEEPASSX_GROUPDIALOG_H
|
||||
#ifndef KEEPASSX_EDITGROUPWIDGET_H
|
||||
#define KEEPASSX_EDITGROUPWIDGET_H
|
||||
|
||||
#include <QtCore/QScopedPointer>
|
||||
#include <QtGui/QWidget>
|
||||
|
@ -51,4 +51,4 @@ private:
|
|||
Q_DISABLE_COPY(EditGroupWidget)
|
||||
};
|
||||
|
||||
#endif // KEEPASSX_GROUPDIALOG_H
|
||||
#endif // KEEPASSX_EDITGROUPWIDGET_H
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
|
||||
#include "CompositeKey.h"
|
||||
|
||||
#include <QtCore/QtConcurrentRun>
|
||||
|
||||
#include "crypto/CryptoHash.h"
|
||||
#include "crypto/SymmetricCipher.h"
|
||||
|
||||
#include <QtCore/QtConcurrentRun>
|
||||
|
||||
CompositeKey::CompositeKey()
|
||||
{
|
||||
}
|
||||
|
|
11
src/main.cpp
11
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();
|
||||
|
||||
|
|
|
@ -31,4 +31,4 @@ private Q_SLOTS:
|
|||
void testEntrySets();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // KEEPASSX_TESTMODIFIED_H
|
||||
|
|
|
@ -41,14 +41,16 @@ void TestSymmetricCipher::testAes256CbcEncryption()
|
|||
QByteArray cipherText = QByteArray::fromHex("f58c4c04d6e5f1ba779eabfb5f7bfbd6");
|
||||
cipherText.append(QByteArray::fromHex("9cfc4e967edb808d679f777bc6702c7d"));
|
||||
|
||||
SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Encrypt, key, iv);
|
||||
SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Encrypt,
|
||||
key, iv);
|
||||
QCOMPARE(cipher.blockSize(), 16);
|
||||
|
||||
QCOMPARE(cipher.process(plainText),
|
||||
cipherText);
|
||||
|
||||
QBuffer buffer;
|
||||
SymmetricCipherStream stream(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Encrypt, key, iv);
|
||||
SymmetricCipherStream stream(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
|
||||
SymmetricCipher::Encrypt, key, iv);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
stream.open(QIODevice::WriteOnly);
|
||||
|
||||
|
@ -88,7 +90,8 @@ void TestSymmetricCipher::testAes256CbcDecryption()
|
|||
plainText);
|
||||
|
||||
QBuffer buffer(&cipherText);
|
||||
SymmetricCipherStream stream(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc, SymmetricCipher::Decrypt, key, iv);
|
||||
SymmetricCipherStream stream(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
|
||||
SymmetricCipher::Decrypt, key, iv);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
stream.open(QIODevice::ReadOnly);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue