GCrypt/GCryptCLI/src/ModuleHashing.cpp

65 lines
1.6 KiB
C++
Raw Normal View History

2022-06-01 02:09:49 +02:00
#include "ModuleHashing.h"
#include "DataIngestionLayer.h"
#include "DataOutputLayer.h"
2022-06-01 03:28:31 +02:00
#include "ProgressPrinter.h"
2022-06-01 02:09:49 +02:00
#include "KeyManager.h"
#include <GCrypt/GHash.h>
using namespace Module;
using namespace Leonetienne::GCrypt;
void Hashing::Run() {
// Initialize the data ingestion layer
IO::DataIngestionLayer::Init();
// Initialize the data output layer
IO::DataOutputLayer::Init();
// Initialize a ghasher
GHash hasher;
// Read in new blocks, if not reached eof
2022-06-01 03:28:31 +02:00
std::size_t nBlocksDigested = 0;
2022-06-01 02:09:49 +02:00
while (!IO::DataIngestionLayer::IsFinished()) {
if (!IO::DataIngestionLayer::ReachedEOF()) {
IO::DataIngestionLayer::ReadBlock();
}
// Process a block, if one is ready
if (IO::DataIngestionLayer::IsBlockReady()) {
2022-06-01 03:28:31 +02:00
// Print progress, if appropriate
ProgressPrinter::PrintIfAppropriate(
"Hashing",
nBlocksDigested,
IO::DataIngestionLayer::NBlocksRead()
);
2022-06-01 02:09:49 +02:00
const Block cleartext = IO::DataIngestionLayer::GetNextBlock();
hasher.Digest(cleartext);
2022-06-01 03:28:31 +02:00
nBlocksDigested++;
2022-06-01 02:09:49 +02:00
}
}
// Wait until we've finished digesting all blocks
// Enqueue that single block (the hash result) to the output layer
IO::DataOutputLayer::Enqueue(hasher.GetHashsum());
// Tell the data output layer that that was the last block
IO::DataOutputLayer::ReachedEOF();
// Dump it
while (!IO::DataOutputLayer::IsFinished()) {
IO::DataOutputLayer::WriteBlock();
}
// Destruct the data ingestion layer
IO::DataIngestionLayer::Destruct();
// Destruct the data output layer
IO::DataOutputLayer::Destruct();
return;
}