1 /*
2 *  Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
3 *
4 *  This program is free software: you can redistribute it and/or modify
5 *  it under the terms of the GNU General Public License as published by
6 *  the Free Software Foundation, either version 2 or (at your option)
7 *  version 3 of the License.
8 *
9 *  This program is distributed in the hope that it will be useful,
10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *  GNU General Public License for more details.
13 *
14 *  You should have received a copy of the GNU General Public License
15 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef KEEPASSX_HASHEDBLOCKSTREAM_H
19 #define KEEPASSX_HASHEDBLOCKSTREAM_H
20 
21 #include <QSysInfo>
22 
23 #include "streams/LayeredStream.h"
24 
25 class HashedBlockStream : public LayeredStream
26 {
27     Q_OBJECT
28 
29 public:
30     explicit HashedBlockStream(QIODevice* baseDevice);
31     HashedBlockStream(QIODevice* baseDevice, qint32 blockSize);
32     ~HashedBlockStream();
33 
34     bool reset() override;
35     void close() override;
36 
37 protected:
38     qint64 readData(char* data, qint64 maxSize) override;
39     qint64 writeData(const char* data, qint64 maxSize) override;
40 
41 private:
42     void init();
43     bool readHashedBlock();
44     bool writeHashedBlock();
45 
46     static const QSysInfo::Endian ByteOrder;
47     qint32 m_blockSize;
48     QByteArray m_buffer;
49     int m_bufferPos;
50     quint32 m_blockIndex;
51     bool m_eof;
52     bool m_error;
53 };
54 
55 #endif // KEEPASSX_HASHEDBLOCKSTREAM_H
56