2010-09-13 17:24:36 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KEEPASSX_SYMMETRICCIPHERSTREAM_H
|
|
|
|
#define KEEPASSX_SYMMETRICCIPHERSTREAM_H
|
|
|
|
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QByteArray>
|
|
|
|
#include <QScopedPointer>
|
2010-09-13 17:24:36 -04:00
|
|
|
|
|
|
|
#include "crypto/SymmetricCipher.h"
|
2011-07-08 08:51:14 -04:00
|
|
|
#include "streams/LayeredStream.h"
|
2010-09-13 17:24:36 -04:00
|
|
|
|
|
|
|
class SymmetricCipherStream : public LayeredStream
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2015-05-09 13:47:53 -04:00
|
|
|
SymmetricCipherStream(QIODevice* baseDevice, SymmetricCipher::Algorithm algo,
|
|
|
|
SymmetricCipher::Mode mode, SymmetricCipher::Direction direction);
|
2010-09-25 06:41:00 -04:00
|
|
|
~SymmetricCipherStream();
|
2015-05-09 13:47:53 -04:00
|
|
|
bool init(const QByteArray& key, const QByteArray& iv);
|
2015-07-24 12:28:12 -04:00
|
|
|
bool open(QIODevice::OpenMode mode) override;
|
|
|
|
bool reset() override;
|
|
|
|
void close() override;
|
2010-09-13 17:24:36 -04:00
|
|
|
|
|
|
|
protected:
|
2015-07-24 12:28:12 -04:00
|
|
|
qint64 readData(char* data, qint64 maxSize) override;
|
|
|
|
qint64 writeData(const char* data, qint64 maxSize) override;
|
2010-09-13 17:24:36 -04:00
|
|
|
|
|
|
|
private:
|
2015-07-20 15:02:57 -04:00
|
|
|
void resetInternalState();
|
2010-09-13 17:24:36 -04:00
|
|
|
bool readBlock();
|
2012-05-08 15:33:21 -04:00
|
|
|
bool writeBlock(bool lastBlock);
|
2010-09-13 17:24:36 -04:00
|
|
|
|
2012-04-22 16:26:05 -04:00
|
|
|
const QScopedPointer<SymmetricCipher> m_cipher;
|
2010-09-13 17:24:36 -04:00
|
|
|
QByteArray m_buffer;
|
|
|
|
int m_bufferPos;
|
2010-09-16 12:20:46 -04:00
|
|
|
bool m_bufferFilling;
|
|
|
|
bool m_error;
|
2015-05-09 13:47:53 -04:00
|
|
|
bool m_isInitalized;
|
2015-07-20 15:02:57 -04:00
|
|
|
bool m_dataWritten;
|
2010-09-13 17:24:36 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // KEEPASSX_SYMMETRICCIPHERSTREAM_H
|