2022-05-27 18:26:48 +02:00
|
|
|
#ifndef GCRYPTCLI_DATAINGESTIONLAYER_H
|
|
|
|
#define GCRYPTCLI_DATAINGESTIONLAYER_H
|
|
|
|
|
2022-05-31 14:25:23 +02:00
|
|
|
#include <iosfwd>
|
|
|
|
#include <queue>
|
|
|
|
#include <GCrypt/Block.h>
|
2022-05-31 15:32:17 +02:00
|
|
|
#include "Configuration.h"
|
2022-05-31 14:25:23 +02:00
|
|
|
|
|
|
|
using namespace Leonetienne::GCrypt;
|
2022-05-27 18:26:48 +02:00
|
|
|
|
|
|
|
namespace IO {
|
|
|
|
|
|
|
|
// This class is used to read in data.
|
|
|
|
class DataIngestionLayer {
|
|
|
|
public:
|
|
|
|
//! Will initialize the ingestion
|
|
|
|
static void Init();
|
|
|
|
|
2022-05-31 15:32:17 +02:00
|
|
|
//! Will destruct the ingestion layer (like, closing file handles)
|
|
|
|
static void Destruct();
|
|
|
|
|
2022-05-31 14:25:23 +02:00
|
|
|
//! Will attempt to read a data block.
|
|
|
|
//! Requires Init() to have been called
|
|
|
|
static void ReadBlock();
|
|
|
|
|
|
|
|
//! Have we read in all available blocks?
|
|
|
|
static bool ReachedEOF();
|
|
|
|
|
2022-05-31 15:32:17 +02:00
|
|
|
//! Returns true if there are blocks to be fetched (GetNextBlock())
|
2022-05-31 14:25:23 +02:00
|
|
|
static bool IsBlockReady();
|
|
|
|
|
|
|
|
//! Will return the next block in the queue
|
|
|
|
static Block GetNextBlock();
|
|
|
|
|
2022-05-31 15:32:17 +02:00
|
|
|
//! Returns true, if EOF is reached, and there are no more blocks to fetch (GetNextBlock())
|
|
|
|
static bool IsFinished();
|
|
|
|
|
2022-05-27 18:26:48 +02:00
|
|
|
private:
|
|
|
|
static std::istream* in;
|
|
|
|
|
2022-05-31 21:40:13 +02:00
|
|
|
// Will read n bytes from the input.
|
|
|
|
// If EOF is reached, it will return a string of length <= 5
|
|
|
|
// and will set the approriate flags.
|
|
|
|
static std::string ReadBytes(const std::size_t n, std::size_t& out_bytes_read);
|
|
|
|
|
2022-05-27 18:26:48 +02:00
|
|
|
// We have to hold on to a reference to a filestream,
|
|
|
|
// even if we're always just reading from in.
|
|
|
|
// We still have to CLOSE the file handle afterwards!
|
|
|
|
static std::ifstream ifs;
|
|
|
|
static std::istringstream iss;
|
2022-05-31 14:25:23 +02:00
|
|
|
|
|
|
|
// Indicates whether EOF has been reached
|
|
|
|
static bool reachedEof;
|
2022-05-31 17:35:05 +02:00
|
|
|
// Indicates whether this class has been initialized
|
2022-05-31 14:25:23 +02:00
|
|
|
static bool initialized;
|
|
|
|
|
2022-05-31 21:40:13 +02:00
|
|
|
// Are we reading ciphertext or regular text?
|
|
|
|
static bool isReadingCiphertext;
|
|
|
|
|
2022-05-31 14:25:23 +02:00
|
|
|
// All read blocks, that haven't been given out yet
|
|
|
|
static std::queue<Block> blocks;
|
2022-05-31 14:28:17 +02:00
|
|
|
|
|
|
|
// No instanciation! >:(
|
|
|
|
DataIngestionLayer();
|
2022-05-27 18:26:48 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|