Test if reset() and close() write only one final block.

This commit is contained in:
Felix Geyer 2015-07-20 21:50:39 +02:00
parent 2033174d95
commit 98d9dae087
4 changed files with 36 additions and 0 deletions

View file

@ -207,3 +207,22 @@ void TestSymmetricCipher::testPadding()
QByteArray decrypted = streamDec.readAll();
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);
}