Formatting and consistency fixes

This commit is contained in:
Jonathan White 2017-12-20 09:57:17 -05:00
parent 4592de8fb6
commit 61c4fe8992
No known key found for this signature in database
GPG Key ID: 440FC65F2E0C6E01
6 changed files with 29 additions and 43 deletions

View File

@ -57,7 +57,7 @@ CryptoHash::CryptoHash(Algorithm algo, bool hmac)
}
gcry_error_t error = gcry_md_open(&d->ctx, algoGcrypt, flagsGcrypt);
if (error) {
if (error != GPG_ERR_NO_ERROR) {
qWarning("Gcrypt error (ctor): %s", gcry_strerror(error));
qWarning("Gcrypt error (ctor): %s", gcry_strsource(error));
}

View File

@ -114,13 +114,12 @@ int AesKdf::benchmarkImpl(int msec) const
QByteArray seed = QByteArray(32, '\x4B');
QByteArray iv(16, 0);
SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Ecb,
SymmetricCipher::Encrypt);
SymmetricCipher cipher(SymmetricCipher::Aes256, SymmetricCipher::Ecb, SymmetricCipher::Encrypt);
cipher.init(seed, iv);
int rounds = 0;
QElapsedTimer t;
t.start();
QElapsedTimer timer;
timer.start();
do {
if (!cipher.processInPlace(key, 10000)) {
rounds = -1;
@ -128,7 +127,7 @@ int AesKdf::benchmarkImpl(int msec) const
}
rounds += 10000;
}
while (!t.hasExpired(msec));
while (!timer.hasExpired(msec));
return rounds;
}

View File

@ -45,7 +45,8 @@ int Kdf::benchmark(int msec) const
}
Kdf::BenchmarkThread::BenchmarkThread(int msec, const Kdf* kdf)
: m_msec(msec), m_kdf(kdf)
: m_msec(msec)
, m_kdf(kdf)
{
}

View File

@ -322,12 +322,9 @@ void Kdbx3Reader::setTransformSeed(const QByteArray& data)
}
auto kdf = m_db->kdf();
if (!kdf) {
kdf = QSharedPointer<AesKdf>::create();
m_db->setKdf(kdf);
if (!kdf.isNull()) {
kdf->setSeed(data);
}
kdf->setSeed(data);
}
void Kdbx3Reader::setTransformRounds(const QByteArray& data)
@ -339,12 +336,9 @@ void Kdbx3Reader::setTransformRounds(const QByteArray& data)
auto rounds = Endian::bytesToSizedInt<quint64>(data, KeePass2::BYTEORDER);
auto kdf = m_db->kdf();
if (!kdf) {
kdf = QSharedPointer<AesKdf>::create();
m_db->setKdf(kdf);
if (!kdf.isNull()) {
kdf->setRounds(rounds);
}
kdf->setRounds(rounds);
}
void Kdbx3Reader::setEncryptionIV(const QByteArray& data)

View File

@ -26,18 +26,16 @@
#include "format/KeePass2.h"
#include "format/Kdbx3Reader.h"
BaseKeePass2Reader::BaseKeePass2Reader() :
m_error(false),
m_saveXml(false),
m_irsAlgo(KeePass2::InvalidProtectedStreamAlgo)
BaseKeePass2Reader::BaseKeePass2Reader()
: m_error(false)
, m_saveXml(false)
, m_irsAlgo(KeePass2::InvalidProtectedStreamAlgo)
{
m_errorStr.clear();
m_xmlData.clear();
m_protectedStreamKey.clear();
}
BaseKeePass2Reader::~BaseKeePass2Reader() {}
Database* BaseKeePass2Reader::readDatabase(const QString& filename, const CompositeKey& key)
{
QFile file(filename);
@ -134,35 +132,30 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke
bool KeePass2Reader::hasError()
{
return m_error || (m_reader && m_reader->hasError());
return m_error || (!m_reader.isNull() && m_reader->hasError());
}
QString KeePass2Reader::errorString()
{
return m_reader ? m_reader->errorString() : m_errorStr;
return !m_reader.isNull() ? m_reader->errorString() : m_errorStr;
}
QByteArray KeePass2Reader::xmlData()
{
return m_reader ? m_reader->xmlData() : m_xmlData;
return !m_reader.isNull() ? m_reader->xmlData() : m_xmlData;
}
QByteArray KeePass2Reader::streamKey()
{
return m_reader ? m_reader->streamKey() : m_protectedStreamKey;
return !m_reader.isNull() ? m_reader->streamKey() : m_protectedStreamKey;
}
KeePass2::ProtectedStreamAlgo KeePass2Reader::protectedStreamAlgo() const
{
return m_reader ? m_reader->protectedStreamAlgo() : m_irsAlgo;
return !m_reader.isNull() ? m_reader->protectedStreamAlgo() : m_irsAlgo;
}
quint32 KeePass2Reader::version() const
{
return m_version;
}
BaseKeePass2Reader* KeePass2Reader::reader() const
{
return m_reader.data();
}

View File

@ -31,6 +31,8 @@
class BaseKeePass2Reader
{
Q_DECLARE_TR_FUNCTIONS(BaseKeePass2Reader)
public:
BaseKeePass2Reader();
@ -44,7 +46,7 @@ public:
virtual QByteArray streamKey();
virtual KeePass2::ProtectedStreamAlgo protectedStreamAlgo() const;
virtual ~BaseKeePass2Reader();
virtual ~BaseKeePass2Reader() = default;
protected:
void raiseError(const QString& errorMessage);
@ -60,20 +62,17 @@ protected:
class KeePass2Reader : public BaseKeePass2Reader
{
Q_DECLARE_TR_FUNCTIONS(KeePass2Reader)
public:
virtual Database* readDatabase(QIODevice* device, const CompositeKey& key, bool keepDatabase = false) override;
Database* readDatabase(QIODevice* device, const CompositeKey& key, bool keepDatabase = false) override;
using BaseKeePass2Reader::readDatabase;
virtual bool hasError() override;
virtual QString errorString() override;
virtual QByteArray xmlData() override;
virtual QByteArray streamKey() override;
virtual KeePass2::ProtectedStreamAlgo protectedStreamAlgo() const override;
bool hasError() override;
QString errorString() override;
QByteArray xmlData() override;
QByteArray streamKey() override;
KeePass2::ProtectedStreamAlgo protectedStreamAlgo() const override;
quint32 version() const;
BaseKeePass2Reader* reader() const;
private:
QScopedPointer<BaseKeePass2Reader> m_reader;
quint32 m_version;