Warn if result of processInPlace() is unchecked.

Fix callers accordingly.
This commit is contained in:
Felix Geyer 2015-05-09 19:57:16 +02:00
parent a762cef0a9
commit f6243675c9
7 changed files with 13 additions and 11 deletions

View File

@ -59,11 +59,11 @@ public:
return m_backend->process(data, ok); return m_backend->process(data, ok);
} }
inline bool processInPlace(QByteArray& data) { inline bool processInPlace(QByteArray& data) Q_REQUIRED_RESULT {
return m_backend->processInPlace(data); return m_backend->processInPlace(data);
} }
inline bool processInPlace(QByteArray& data, quint64 rounds) { inline bool processInPlace(QByteArray& data, quint64 rounds) Q_REQUIRED_RESULT {
Q_ASSERT(rounds > 0); Q_ASSERT(rounds > 0);
return m_backend->processInPlace(data, rounds); return m_backend->processInPlace(data, rounds);
} }

View File

@ -29,8 +29,8 @@ public:
virtual bool setIv(const QByteArray& iv) = 0; virtual bool setIv(const QByteArray& iv) = 0;
virtual QByteArray process(const QByteArray& data, bool* ok) = 0; virtual QByteArray process(const QByteArray& data, bool* ok) = 0;
virtual bool processInPlace(QByteArray& data) = 0; virtual bool processInPlace(QByteArray& data) Q_REQUIRED_RESULT = 0;
virtual bool processInPlace(QByteArray& data, quint64 rounds) = 0; virtual bool processInPlace(QByteArray& data, quint64 rounds) Q_REQUIRED_RESULT = 0;
virtual bool reset() = 0; virtual bool reset() = 0;
virtual int blockSize() const = 0; virtual int blockSize() const = 0;

View File

@ -35,8 +35,8 @@ public:
bool setIv(const QByteArray& iv); bool setIv(const QByteArray& iv);
QByteArray process(const QByteArray& data, bool* ok); QByteArray process(const QByteArray& data, bool* ok);
bool processInPlace(QByteArray& data); bool processInPlace(QByteArray& data) Q_REQUIRED_RESULT;
bool processInPlace(QByteArray& data, quint64 rounds); bool processInPlace(QByteArray& data, quint64 rounds) Q_REQUIRED_RESULT;
bool reset(); bool reset();
int blockSize() const; int blockSize() const;

View File

@ -29,7 +29,7 @@ public:
bool init(const QByteArray& key); bool init(const QByteArray& key);
QByteArray randomBytes(int size, bool* ok); QByteArray randomBytes(int size, bool* ok);
QByteArray process(const QByteArray& data, bool* ok); QByteArray process(const QByteArray& data, bool* ok);
bool processInPlace(QByteArray& data); bool processInPlace(QByteArray& data) Q_REQUIRED_RESULT;
QString errorString() const; QString errorString() const;
private: private:

View File

@ -877,7 +877,9 @@ QPair<QString, QString> KeePass2XmlReader::parseEntryBinary(Entry* entry)
&& (attr.value("Protected") == "True"); && (attr.value("Protected") == "True");
if (isProtected && !value.isEmpty()) { if (isProtected && !value.isEmpty()) {
m_randomStream->processInPlace(value); if (!m_randomStream->processInPlace(value)) {
raiseError(m_randomStream->errorString());
}
} }
} }

View File

@ -186,7 +186,7 @@ void TransformKeyBenchmarkThread::run()
t.start(); t.start();
do { do {
cipher.processInPlace(key, 100); Q_UNUSED(cipher.processInPlace(key, 100));
m_rounds += 100; m_rounds += 100;
} while (t.elapsed() < m_msec); } while (t.elapsed() < m_msec);
} }

View File

@ -49,7 +49,7 @@ void TestKeePass2RandomStream::test()
QByteArray cipherPad; QByteArray cipherPad;
cipherPad.fill('\0', Size); cipherPad.fill('\0', Size);
cipher.processInPlace(cipherPad); QVERIFY(cipher.processInPlace(cipherPad));
QByteArray cipherData; QByteArray cipherData;
cipherData.resize(Size); cipherData.resize(Size);
@ -68,7 +68,7 @@ void TestKeePass2RandomStream::test()
randomStreamData.append(randomStream.process(data.mid(7, 1), &ok)); randomStreamData.append(randomStream.process(data.mid(7, 1), &ok));
QVERIFY(ok); QVERIFY(ok);
QByteArray tmpData = data.mid(8, 12); QByteArray tmpData = data.mid(8, 12);
randomStream.processInPlace(tmpData); QVERIFY(randomStream.processInPlace(tmpData));
randomStreamData.append(tmpData); randomStreamData.append(tmpData);
randomStreamData.append(randomStream.process(data.mid(20, 44), &ok)); randomStreamData.append(randomStream.process(data.mid(20, 44), &ok));
QVERIFY(ok); QVERIFY(ok);