Dummy implementation for EncryptedBlockStore
This commit is contained in:
parent
4d72087e27
commit
86f8ca6dc4
27
implementations/encrypted/EncryptedBlock.cpp
Normal file
27
implementations/encrypted/EncryptedBlock.cpp
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
34
implementations/encrypted/EncryptedBlock.h
Normal file
34
implementations/encrypted/EncryptedBlock.h
Normal 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
|
36
implementations/encrypted/EncryptedBlockStore.cpp
Normal file
36
implementations/encrypted/EncryptedBlockStore.cpp
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
29
implementations/encrypted/EncryptedBlockStore.h
Normal file
29
implementations/encrypted/EncryptedBlockStore.h
Normal 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
|
23
test/implementations/encrypted/EncryptedBlockStoreTest.cpp
Normal file
23
test/implementations/encrypted/EncryptedBlockStoreTest.cpp
Normal 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
|
Loading…
Reference in New Issue
Block a user