Dummy implementation for EncryptedBlockStore

This commit is contained in:
Sebastian Messmer 2015-04-09 19:22:09 +02:00
parent 4d72087e27
commit 86f8ca6dc4
5 changed files with 149 additions and 0 deletions

View File

@ -0,0 +1,27 @@
#include "EncryptedBlock.h"
namespace blockstore {
namespace encrypted {
EncryptedBlock::EncryptedBlock(std::unique_ptr<Block> baseBlock)
:Block(baseBlock->key()), _baseBlock(std::move(baseBlock)) {
}
const void *EncryptedBlock::data() const {
return _baseBlock->data();
}
void EncryptedBlock::write(const void *source, uint64_t offset, uint64_t size) {
return _baseBlock->write(source, offset, size);
}
void EncryptedBlock::flush() {
return _baseBlock->flush();
}
size_t EncryptedBlock::size() const {
return _baseBlock->size();
}
}
}

View File

@ -0,0 +1,34 @@
#pragma once
#ifndef BLOCKSTORE_IMPLEMENTATIONS_ENCRYPTED_ENCRYPTEDBLOCK_H_
#define BLOCKSTORE_IMPLEMENTATIONS_ENCRYPTED_ENCRYPTEDBLOCK_H_
#include "../../interface/Block.h"
#include "messmer/cpp-utils/macros.h"
#include <memory>
namespace blockstore {
namespace encrypted {
class EncryptedBlockStore;
class EncryptedBlock: public Block {
public:
//TODO Storing key twice (in parent class and in object pointed to). Once would be enough.
EncryptedBlock(std::unique_ptr<Block> baseBlock);
const void *data() const override;
void write(const void *source, uint64_t offset, uint64_t size) override;
void flush() override;
size_t size() const override;
private:
std::unique_ptr<Block> _baseBlock;
DISALLOW_COPY_AND_ASSIGN(EncryptedBlock);
};
}
}
#endif

View File

@ -0,0 +1,36 @@
#include "EncryptedBlockStore.h"
#include "EncryptedBlock.h"
#include <messmer/cpp-utils/pointer.h>
using std::unique_ptr;
using std::make_unique;
namespace blockstore {
namespace encrypted {
EncryptedBlockStore::EncryptedBlockStore(unique_ptr<BlockStore> baseBlockStore)
: _baseBlockStore(std::move(baseBlockStore)) {
}
unique_ptr<Block> EncryptedBlockStore::create(size_t size) {
return make_unique<EncryptedBlock>(_baseBlockStore->create(size));
}
unique_ptr<Block> EncryptedBlockStore::load(const Key &key) {
auto block = _baseBlockStore->load(key);
if (block.get() == nullptr) {
return nullptr;
}
return make_unique<EncryptedBlock>(std::move(block));
}
void EncryptedBlockStore::remove(unique_ptr<Block> block) {
return _baseBlockStore->remove(std::move(block));
}
uint64_t EncryptedBlockStore::numBlocks() const {
return _baseBlockStore->numBlocks();
}
}
}

View File

@ -0,0 +1,29 @@
#pragma once
#ifndef BLOCKSTORE_IMPLEMENTATIONS_ENCRYPTED_ENCRYPTEDBLOCKSTORE_H_
#define BLOCKSTORE_IMPLEMENTATIONS_ENCRYPTED_ENCRYPTEDBLOCKSTORE_H_
#include "../../interface/BlockStore.h"
#include <messmer/cpp-utils/macros.h>
namespace blockstore {
namespace encrypted {
class EncryptedBlockStore: public BlockStore {
public:
EncryptedBlockStore(std::unique_ptr<BlockStore> baseBlockStore);
std::unique_ptr<Block> create(size_t size) override;
std::unique_ptr<Block> load(const Key &key) override;
void remove(std::unique_ptr<Block> block) override;
uint64_t numBlocks() const override;
private:
std::unique_ptr<BlockStore> _baseBlockStore;
DISALLOW_COPY_AND_ASSIGN(EncryptedBlockStore);
};
}
}
#endif

View File

@ -0,0 +1,23 @@
#include "../../../implementations/encrypted/EncryptedBlockStore.h"
#include "../../../implementations/testfake/FakeBlockStore.h"
#include "../../testutils/BlockStoreTest.h"
#include "google/gtest/gtest.h"
using blockstore::BlockStore;
using blockstore::encrypted::EncryptedBlockStore;
using blockstore::testfake::FakeBlockStore;
using std::unique_ptr;
using std::make_unique;
class EncryptedBlockStoreTestFixture: public BlockStoreTestFixture {
public:
unique_ptr<BlockStore> createBlockStore() override {
return make_unique<EncryptedBlockStore>(make_unique<FakeBlockStore>());
}
};
INSTANTIATE_TYPED_TEST_CASE_P(Encrypted, BlockStoreTest, EncryptedBlockStoreTestFixture);
//TODO Add specific tests, for example loading it with a different key doesn't work