2015-04-09 19:22:09 +02:00
|
|
|
#include "EncryptedBlockStore.h"
|
|
|
|
#include "EncryptedBlock.h"
|
|
|
|
#include <messmer/cpp-utils/pointer.h>
|
2015-04-09 21:17:28 +02:00
|
|
|
#include "../../utils/BlockStoreUtils.h"
|
2015-04-09 19:22:09 +02:00
|
|
|
|
|
|
|
using std::unique_ptr;
|
|
|
|
using std::make_unique;
|
|
|
|
|
|
|
|
namespace blockstore {
|
|
|
|
namespace encrypted {
|
|
|
|
|
2015-04-09 20:14:12 +02:00
|
|
|
EncryptedBlockStore::EncryptedBlockStore(unique_ptr<BlockStore> baseBlockStore, const EncryptionKey &encKey)
|
|
|
|
: _baseBlockStore(std::move(baseBlockStore)), _encKey(encKey) {
|
2015-04-09 19:22:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<Block> EncryptedBlockStore::create(size_t size) {
|
2015-04-09 21:17:28 +02:00
|
|
|
return EncryptedBlock::CreateNew(_baseBlockStore->create(EncryptedBlock::BASE_BLOCK_SIZE(size)), _encKey);
|
2015-04-09 19:22:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<Block> EncryptedBlockStore::load(const Key &key) {
|
|
|
|
auto block = _baseBlockStore->load(key);
|
|
|
|
if (block.get() == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-04-09 20:14:12 +02:00
|
|
|
return make_unique<EncryptedBlock>(std::move(block), _encKey);
|
2015-04-09 19:22:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EncryptedBlockStore::remove(unique_ptr<Block> block) {
|
|
|
|
return _baseBlockStore->remove(std::move(block));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t EncryptedBlockStore::numBlocks() const {
|
|
|
|
return _baseBlockStore->numBlocks();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|