mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-04-04 13:07:38 +03:00
Write the remaining buffer in reset().
This commit is contained in:
parent
c2bdfab158
commit
36d974649e
2 changed files with 11 additions and 3 deletions
|
@ -29,11 +29,18 @@ SymmetricCipherStream::SymmetricCipherStream(QIODevice* baseDevice, SymmetricCip
|
||||||
|
|
||||||
bool SymmetricCipherStream::reset()
|
bool SymmetricCipherStream::reset()
|
||||||
{
|
{
|
||||||
|
if (isWritable()) {
|
||||||
|
if (!writeBlock()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_buffer.clear();
|
m_buffer.clear();
|
||||||
m_bufferPos = 0;
|
m_bufferPos = 0;
|
||||||
m_bufferFilling = false;
|
m_bufferFilling = false;
|
||||||
m_error = false;
|
m_error = false;
|
||||||
m_cipher->reset();
|
m_cipher->reset();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +140,7 @@ bool SymmetricCipherStream::writeBlock()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (m_buffer.size() != m_cipher->blockSize()) {
|
else if (m_buffer.size() != m_cipher->blockSize()) {
|
||||||
|
// PKCS7 padding
|
||||||
int padLen = m_cipher->blockSize() - m_buffer.size();
|
int padLen = m_cipher->blockSize() - m_buffer.size();
|
||||||
for (int i=m_buffer.size(); i<m_cipher->blockSize(); i++) {
|
for (int i=m_buffer.size(); i<m_cipher->blockSize(); i++) {
|
||||||
m_buffer.append(static_cast<char>(padLen));
|
m_buffer.append(static_cast<char>(padLen));
|
||||||
|
|
|
@ -59,21 +59,21 @@ void TestSymmetricCipher::testAes256CbcEncryption()
|
||||||
buffer.open(QIODevice::WriteOnly);
|
buffer.open(QIODevice::WriteOnly);
|
||||||
stream.open(QIODevice::WriteOnly);
|
stream.open(QIODevice::WriteOnly);
|
||||||
|
|
||||||
|
QVERIFY(stream.reset());
|
||||||
buffer.reset();
|
buffer.reset();
|
||||||
buffer.buffer().clear();
|
buffer.buffer().clear();
|
||||||
stream.reset();
|
|
||||||
stream.write(plainText.left(16));
|
stream.write(plainText.left(16));
|
||||||
QCOMPARE(QString(buffer.data().toHex()), QString(cipherText.left(16).toHex()));
|
QCOMPARE(QString(buffer.data().toHex()), QString(cipherText.left(16).toHex()));
|
||||||
|
|
||||||
|
QVERIFY(stream.reset());
|
||||||
buffer.reset();
|
buffer.reset();
|
||||||
buffer.buffer().clear();
|
buffer.buffer().clear();
|
||||||
stream.reset();
|
|
||||||
stream.write(plainText.left(10));
|
stream.write(plainText.left(10));
|
||||||
QCOMPARE(QString(buffer.data().toHex()), QString());
|
QCOMPARE(QString(buffer.data().toHex()), QString());
|
||||||
|
|
||||||
|
QVERIFY(stream.reset());
|
||||||
buffer.reset();
|
buffer.reset();
|
||||||
buffer.buffer().clear();
|
buffer.buffer().clear();
|
||||||
stream.reset();
|
|
||||||
stream.write(plainText.left(10));
|
stream.write(plainText.left(10));
|
||||||
stream.close();
|
stream.close();
|
||||||
QCOMPARE(buffer.data().size(), 16);
|
QCOMPARE(buffer.data().size(), 16);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue