Skip to content

Commit

Permalink
Improve code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
debfx committed Apr 18, 2012
1 parent 4e5e5c7 commit 2e011d5
Show file tree
Hide file tree
Showing 29 changed files with 100 additions and 94 deletions.
3 changes: 1 addition & 2 deletions src/core/Endian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
#endif
#include <QtCore/QIODevice>

namespace Endian
{
namespace Endian {

qint16 bytesToInt16(const QByteArray& ba, QSysInfo::Endian byteOrder)
{
Expand Down
7 changes: 4 additions & 3 deletions src/core/Endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
3 changes: 2 additions & 1 deletion src/core/EntryAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/core/EntryAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class EntryAttributes : public QObject
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:
Expand All @@ -51,7 +51,7 @@ class EntryAttributes : public QObject
void removed(QString key);
void aboutToBeReset();
void reset();

private:
QMap<QString, QString> m_attributes;
QSet<QString> m_protectedAttributes;
Expand Down
1 change: 1 addition & 0 deletions src/core/TimeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int TimeInfo::usageCount() const
{
return m_usageCount;
}

QDateTime TimeInfo::locationChanged() const
{
return m_locationChanged;
Expand Down
6 changes: 3 additions & 3 deletions src/core/TimeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -51,4 +51,4 @@ class TimeInfo
QDateTime m_locationChanged;
};

#endif // KEEPASSX_DBTIMEINFO_H
#endif // KEEPASSX_TIMEINFO_H
6 changes: 5 additions & 1 deletion src/core/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include <QtCore/QLocale>
#include <QtCore/QStringList>

QString Tools::humanReadableFileSize(qint64 bytes)
namespace Tools {

QString humanReadableFileSize(qint64 bytes)
{
double size = bytes;

Expand All @@ -35,3 +37,5 @@ QString Tools::humanReadableFileSize(qint64 bytes)

return QString("%1 %2").arg(QLocale().toString(size, 'f', 2), units.at(i));
}

} // namespace Tools
2 changes: 1 addition & 1 deletion src/core/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ namespace Tools {

QString humanReadableFileSize(qint64 bytes);

}
} // namespace Tools

#endif // KEEPASSX_TOOLS_H
2 changes: 1 addition & 1 deletion src/core/Uuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ QByteArray Uuid::toByteArray() const

bool Uuid::isNull() const
{
for (int i=0; i<m_data.size(); ++i) {
for (int i = 0; i < m_data.size(); ++i) {
if (m_data[i] != 0) {
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/crypto/SymmetricCipherSalsa20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void SymmetricCipherSalsa20::init()

void SymmetricCipherSalsa20::setKey(const QByteArray& key)
{
Q_ASSERT( (key.size() == 16) || (key.size() == 32) );
Q_ASSERT((key.size() == 16) || (key.size() == 32));

m_key = key;
ECRYPT_keysetup(&m_ctx, reinterpret_cast<const u8*>(m_key.constData()), m_key.size()*8, 64);
Expand All @@ -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());
Expand All @@ -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<const u8*>(data.constData()),
reinterpret_cast<u8*>(data.data()), data.size());
Expand Down
4 changes: 2 additions & 2 deletions src/format/KeePass2RandomStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ QByteArray KeePass2RandomStream::process(const QByteArray& data)
QByteArray result;
result.resize(data.size());

for (int i=0; i<data.size(); i++) {
for (int i = 0; i < data.size(); i++) {
result[i] = data[i] ^ randomData[i];
}

Expand All @@ -64,7 +64,7 @@ void KeePass2RandomStream::processInPlace(QByteArray& data)
{
QByteArray randomData = randomBytes(data.size());

for (int i=0; i<data.size(); i++) {
for (int i = 0; i < data.size(); i++) {
data[i] = data[i] ^ randomData[i];
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/format/KeePass2Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 11 additions & 4 deletions src/format/KeePass2Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions src/format/KeePass2XmlReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ Group* KeePass2XmlReader::parseGroup()
else {
raiseError(3);
}

}
else if (m_xml.name() == "EnableSearching") {
QString str = readString();
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/gui/ChangeMasterKeyWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/gui/DatabaseOpenDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -56,4 +56,4 @@ private Q_SLOTS:
Q_DISABLE_COPY(DatabaseOpenDialog)
};

#endif // KEEPASSX_KEYOPENDIALOG_H
#endif // KEEPASSX_DATABASEOPENDIALOG_H
1 change: 0 additions & 1 deletion src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/EditEntryWidget_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -39,7 +39,7 @@ class CategoryListViewDelegate : public QStyledItemDelegate
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));
Expand Down
6 changes: 3 additions & 3 deletions src/gui/EditGroupWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -51,4 +51,4 @@ private Q_SLOTS:
Q_DISABLE_COPY(EditGroupWidget)
};

#endif // KEEPASSX_GROUPDIALOG_H
#endif // KEEPASSX_EDITGROUPWIDGET_H
2 changes: 1 addition & 1 deletion src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/keys/CompositeKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

#include "CompositeKey.h"

#include <QtCore/QtConcurrentRun>

#include "crypto/CryptoHash.h"
#include "crypto/SymmetricCipher.h"

#include <QtCore/QtConcurrentRun>

CompositeKey::CompositeKey()
{
}
Expand Down Expand Up @@ -90,7 +90,7 @@ QByteArray CompositeKey::transformKeyRaw(const QByteArray& key, const QByteArray

QByteArray result = key;

for (int i=0; i<rounds; i++) {
for (int i = 0; i < rounds; i++) {
cipher.processInPlace(result);
}

Expand Down
66 changes: 33 additions & 33 deletions src/keys/FileKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,39 @@ bool FileKey::load(QIODevice* device)
return false;
}

if (device->size() == 0) {
return false;
}

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 (loadHex(device)) {
return true;
}

if (!device->reset()) {
return false;
}
if (loadHashed(device)) {
return true;
}

return false;
if (device->size() == 0) {
return false;
}

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 (loadHex(device)) {
return true;
}

if (!device->reset()) {
return false;
}
if (loadHashed(device)) {
return true;
}

return false;
}

bool FileKey::load(const QString& fileName, QString* errorMsg)
Expand Down
Loading

0 comments on commit 2e011d5

Please sign in to comment.