mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-05 21:14:20 -04:00
Test if reset() and close() write only one final block.
This commit is contained in:
parent
2033174d95
commit
98d9dae087
4 changed files with 36 additions and 0 deletions
|
@ -73,6 +73,21 @@ void TestHashedBlockStream::testWriteRead()
|
||||||
buffer.buffer().clear();
|
buffer.buffer().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestHashedBlockStream::testReset()
|
||||||
|
{
|
||||||
|
QBuffer buffer;
|
||||||
|
QVERIFY(buffer.open(QIODevice::WriteOnly));
|
||||||
|
|
||||||
|
HashedBlockStream writer(&buffer, 16);
|
||||||
|
QVERIFY(writer.open(QIODevice::WriteOnly));
|
||||||
|
QCOMPARE(writer.write(QByteArray(8, 'Z')), qint64(8));
|
||||||
|
// test if reset() and close() write only one final block
|
||||||
|
QVERIFY(writer.reset());
|
||||||
|
QVERIFY(writer.reset());
|
||||||
|
writer.close();
|
||||||
|
QCOMPARE(buffer.buffer().size(), 8 + (32 + 4 + 4) * 2);
|
||||||
|
}
|
||||||
|
|
||||||
void TestHashedBlockStream::testWriteFailure()
|
void TestHashedBlockStream::testWriteFailure()
|
||||||
{
|
{
|
||||||
FailDevice failDevice(1500);
|
FailDevice failDevice(1500);
|
||||||
|
|
|
@ -27,6 +27,7 @@ class TestHashedBlockStream : public QObject
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void testWriteRead();
|
void testWriteRead();
|
||||||
|
void testReset();
|
||||||
void testWriteFailure();
|
void testWriteFailure();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -207,3 +207,22 @@ void TestSymmetricCipher::testPadding()
|
||||||
QByteArray decrypted = streamDec.readAll();
|
QByteArray decrypted = streamDec.readAll();
|
||||||
QCOMPARE(decrypted, plainText);
|
QCOMPARE(decrypted, plainText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestSymmetricCipher::testStreamReset()
|
||||||
|
{
|
||||||
|
QByteArray key = QByteArray::fromHex("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
|
||||||
|
QByteArray iv = QByteArray::fromHex("000102030405060708090a0b0c0d0e0f");
|
||||||
|
|
||||||
|
QBuffer buffer;
|
||||||
|
QVERIFY(buffer.open(QIODevice::WriteOnly));
|
||||||
|
SymmetricCipherStream writer(&buffer, SymmetricCipher::Aes256, SymmetricCipher::Cbc,
|
||||||
|
SymmetricCipher::Encrypt);
|
||||||
|
QVERIFY(writer.init(key, iv));
|
||||||
|
QVERIFY(writer.open(QIODevice::WriteOnly));
|
||||||
|
QCOMPARE(writer.write(QByteArray(4, 'Z')), qint64(4));
|
||||||
|
// test if reset() and close() write only one block
|
||||||
|
QVERIFY(writer.reset());
|
||||||
|
QVERIFY(writer.reset());
|
||||||
|
writer.close();
|
||||||
|
QCOMPARE(buffer.buffer().size(), 16);
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ private Q_SLOTS:
|
||||||
void testAes256CbcDecryption();
|
void testAes256CbcDecryption();
|
||||||
void testSalsa20();
|
void testSalsa20();
|
||||||
void testPadding();
|
void testPadding();
|
||||||
|
void testStreamReset();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEEPASSX_TESTSYMMETRICCIPHER_H
|
#endif // KEEPASSX_TESTSYMMETRICCIPHER_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue