refactor: cryptography component

This commit is contained in:
Jan
2025-04-25 21:26:44 +01:00
committed by Jan Laupetin
parent 60f5c1a18f
commit 5635470b6e
63 changed files with 550 additions and 723 deletions

View File

@ -6,7 +6,12 @@
class ILoadingStream
{
public:
ILoadingStream() = default;
virtual ~ILoadingStream() = default;
ILoadingStream(const ILoadingStream& other) = default;
ILoadingStream(ILoadingStream&& other) noexcept = default;
ILoadingStream& operator=(const ILoadingStream& other) = default;
ILoadingStream& operator=(ILoadingStream&& other) noexcept = default;
virtual size_t Load(void* buffer, size_t length) = 0;
virtual int64_t Pos() = 0;

View File

@ -17,7 +17,7 @@ class ProcessorAuthedBlocks::Impl
const size_t m_chunk_size;
const unsigned m_max_master_block_count;
const std::unique_ptr<IHashFunction> m_hash_function;
const std::unique_ptr<cryptography::IHashFunction> m_hash_function;
IHashProvider* const m_master_block_hash_provider;
const std::unique_ptr<uint8_t[]> m_chunk_hashes_buffer;
const std::unique_ptr<uint8_t[]> m_current_chunk_hash_buffer;
@ -34,7 +34,7 @@ public:
const unsigned authedChunkCount,
const size_t chunkSize,
const unsigned maxMasterBlockCount,
std::unique_ptr<IHashFunction> hashFunction,
std::unique_ptr<cryptography::IHashFunction> hashFunction,
IHashProvider* masterBlockHashProvider)
: m_base(base),
m_authed_chunk_count(authedChunkCount),
@ -141,7 +141,7 @@ public:
ProcessorAuthedBlocks::ProcessorAuthedBlocks(const unsigned authedChunkCount,
const size_t chunkSize,
const unsigned maxMasterBlockCount,
std::unique_ptr<IHashFunction> hashFunction,
std::unique_ptr<cryptography::IHashFunction> hashFunction,
IHashProvider* masterBlockHashProvider)
: m_impl(new Impl(this, authedChunkCount, chunkSize, maxMasterBlockCount, std::move(hashFunction), masterBlockHashProvider))
{

View File

@ -1,5 +1,6 @@
#pragma once
#include "Crypto.h"
#include "Cryptography.h"
#include "Loading/IHashProvider.h"
#include "Loading/StreamProcessor.h"
@ -14,7 +15,7 @@ public:
ProcessorAuthedBlocks(unsigned authedChunkCount,
size_t chunkSize,
unsigned maxMasterBlockCount,
std::unique_ptr<IHashFunction> hashFunction,
std::unique_ptr<cryptography::IHashFunction> hashFunction,
IHashProvider* masterBlockHashProvider);
~ProcessorAuthedBlocks() override;
ProcessorAuthedBlocks(const ProcessorAuthedBlocks& other) = delete;

View File

@ -1,14 +1,8 @@
#include "ProcessorStreamCipher.h"
ProcessorStreamCipher::ProcessorStreamCipher(IStreamCipher* cipher)
ProcessorStreamCipher::ProcessorStreamCipher(std::unique_ptr<cryptography::IStreamCipher> cipher)
: m_cipher(std::move(cipher))
{
m_cipher = cipher;
}
ProcessorStreamCipher::~ProcessorStreamCipher()
{
delete m_cipher;
m_cipher = nullptr;
}
size_t ProcessorStreamCipher::Load(void* buffer, const size_t length)

View File

@ -1,14 +1,17 @@
#pragma once
#include "Crypto.h"
#include "Cryptography.h"
#include "Loading/StreamProcessor.h"
#include <memory>
class ProcessorStreamCipher final : public StreamProcessor
{
IStreamCipher* m_cipher;
public:
explicit ProcessorStreamCipher(IStreamCipher* cipher);
~ProcessorStreamCipher() override;
explicit ProcessorStreamCipher(std::unique_ptr<cryptography::IStreamCipher> cipher);
size_t Load(void* buffer, size_t length) override;
private:
std::unique_ptr<cryptography::IStreamCipher> m_cipher;
};

View File

@ -5,7 +5,7 @@
#include <cstring>
#include <memory>
StepVerifyHash::StepVerifyHash(std::unique_ptr<IHashFunction> hashFunction,
StepVerifyHash::StepVerifyHash(std::unique_ptr<cryptography::IHashFunction> hashFunction,
const unsigned hashIndex,
IHashProvider* hashProvider,
ICapturedDataProvider* dataProvider)

View File

@ -1,6 +1,6 @@
#pragma once
#include "Crypto.h"
#include "Cryptography.h"
#include "Loading/IHashProvider.h"
#include "Loading/ILoadingStep.h"
#include "Utils/ICapturedDataProvider.h"
@ -9,13 +9,16 @@
class StepVerifyHash final : public ILoadingStep
{
std::unique_ptr<IHashFunction> m_hash_function;
std::unique_ptr<cryptography::IHashFunction> m_hash_function;
unsigned m_hash_index;
IHashProvider* m_hash_provider;
ICapturedDataProvider* m_data_provider;
public:
StepVerifyHash(std::unique_ptr<IHashFunction> hashFunction, unsigned hashIndex, IHashProvider* hashProvider, ICapturedDataProvider* dataProvider);
StepVerifyHash(std::unique_ptr<cryptography::IHashFunction> hashFunction,
unsigned hashIndex,
IHashProvider* hashProvider,
ICapturedDataProvider* dataProvider);
~StepVerifyHash();
StepVerifyHash(const StepVerifyHash& other) = delete;
StepVerifyHash(StepVerifyHash&& other) noexcept = default;

View File

@ -4,7 +4,7 @@
#include <cassert>
StepVerifySignature::StepVerifySignature(std::unique_ptr<IPublicKeyAlgorithm> signatureAlgorithm,
StepVerifySignature::StepVerifySignature(std::unique_ptr<cryptography::IPublicKeyAlgorithm> signatureAlgorithm,
ISignatureProvider* signatureProvider,
ICapturedDataProvider* signatureDataProvider)
: m_algorithm(std::move(signatureAlgorithm)),

View File

@ -1,18 +1,18 @@
#pragma once
#include "Crypto.h"
#include "Cryptography.h"
#include "Loading/ILoadingStep.h"
#include "Loading/ISignatureProvider.h"
#include "Utils/ICapturedDataProvider.h"
class StepVerifySignature final : public ILoadingStep
{
std::unique_ptr<IPublicKeyAlgorithm> m_algorithm;
std::unique_ptr<cryptography::IPublicKeyAlgorithm> m_algorithm;
ISignatureProvider* m_signature_provider;
ICapturedDataProvider* m_signature_data_provider;
public:
StepVerifySignature(std::unique_ptr<IPublicKeyAlgorithm> signatureAlgorithm,
StepVerifySignature(std::unique_ptr<cryptography::IPublicKeyAlgorithm> signatureAlgorithm,
ISignatureProvider* signatureProvider,
ICapturedDataProvider* signatureDataProvider);
~StepVerifySignature() override = default;

View File

@ -4,11 +4,11 @@
class StreamProcessor : public ILoadingStream
{
protected:
ILoadingStream* m_base_stream;
public:
StreamProcessor();
void SetBaseStream(ILoadingStream* baseStream);
protected:
ILoadingStream* m_base_stream;
};