2022-05-31 21:40:13 +02:00
|
|
|
#include "ModuleDecryption.h"
|
|
|
|
#include "DataIngestionLayer.h"
|
|
|
|
#include "DataOutputLayer.h"
|
2022-06-01 03:28:31 +02:00
|
|
|
#include "ProgressPrinter.h"
|
2022-05-31 21:40:13 +02:00
|
|
|
#include "KeyManager.h"
|
|
|
|
#include <GCrypt/GCipher.h>
|
|
|
|
|
|
|
|
using namespace Module;
|
|
|
|
using namespace Leonetienne::GCrypt;
|
|
|
|
|
|
|
|
void Decryption::Run() {
|
|
|
|
|
|
|
|
// Initialize the data ingestion layer
|
|
|
|
IO::DataIngestionLayer::Init();
|
|
|
|
|
|
|
|
// Initialize the data output layer
|
|
|
|
IO::DataOutputLayer::Init();
|
|
|
|
|
|
|
|
// Initialize a cipher
|
|
|
|
GCipher cipher(
|
|
|
|
KeyManager::GetKey(),
|
|
|
|
GCipher::DIRECTION::DECIPHER
|
|
|
|
);
|
|
|
|
|
2022-06-01 03:28:31 +02:00
|
|
|
std::size_t nBlocksDigested = 0;
|
2022-05-31 21:40:13 +02:00
|
|
|
while (!IO::DataOutputLayer::IsFinished()) {
|
|
|
|
// Read in new blocks, if not reached eof
|
|
|
|
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(
|
|
|
|
"Decrypting",
|
|
|
|
nBlocksDigested,
|
|
|
|
IO::DataIngestionLayer::NBlocksRead()
|
|
|
|
);
|
|
|
|
|
2022-05-31 21:40:13 +02:00
|
|
|
const Block cleartext = IO::DataIngestionLayer::GetNextBlock();
|
|
|
|
const Block ciphertext = cipher.Digest(cleartext);
|
2022-06-01 03:28:31 +02:00
|
|
|
nBlocksDigested++;
|
2022-05-31 21:40:13 +02:00
|
|
|
|
|
|
|
// Enqueue the block for output
|
|
|
|
IO::DataOutputLayer::Enqueue(ciphertext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell the data output layer that it received the
|
|
|
|
// last block, if it did
|
|
|
|
if (IO::DataIngestionLayer::IsFinished()) {
|
|
|
|
IO::DataOutputLayer::ReachedEOF();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to write a block
|
|
|
|
IO::DataOutputLayer::WriteBlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destruct the data ingestion layer
|
|
|
|
IO::DataIngestionLayer::Destruct();
|
|
|
|
|
|
|
|
// Destruct the data output layer
|
|
|
|
IO::DataOutputLayer::Destruct();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|