Don't encrypt and re-decrypt when creating a block, but keep plaintext data

This commit is contained in:
Sebastian Meßmer 2015-04-18 15:10:42 +02:00
parent 417a701636
commit c18893c151
4 changed files with 11 additions and 12 deletions

View File

@ -23,16 +23,20 @@ std::unique_ptr<EncryptedBlock> EncryptedBlock::TryCreateNew(BlockStore *baseBlo
return nullptr;
}
return make_unique<EncryptedBlock>(std::move(baseBlock), encKey);
return make_unique<EncryptedBlock>(std::move(baseBlock), encKey, std::move(data));
}
EncryptedBlock::EncryptedBlock(std::unique_ptr<Block> baseBlock, const EncryptionKey &encKey)
:EncryptedBlock(std::move(baseBlock), encKey, Data(USEABLE_BLOCK_SIZE(baseBlock->size()))) {
_decryptFromBaseBlock();
}
EncryptedBlock::EncryptedBlock(std::unique_ptr<Block> baseBlock, const EncryptionKey &encKey, Data plaintextData)
:Block(baseBlock->key()),
_baseBlock(std::move(baseBlock)),
_plaintextData(USEABLE_BLOCK_SIZE(_baseBlock->size())),
_plaintextData(std::move(plaintextData)),
_encKey(encKey),
_dataChanged(false) {
_decryptFromBaseBlock();
}
EncryptedBlock::~EncryptedBlock() {

View File

@ -18,6 +18,7 @@ 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 EncryptionKey &encKey);
EncryptedBlock(std::unique_ptr<Block> baseBlock, const EncryptionKey &encKey, Data plaintextData);
virtual ~EncryptedBlock();
static std::unique_ptr<EncryptedBlock> TryCreateNew(BlockStore *baseBlockStore, const Key &key, Data data, const EncryptionKey &encKey);

View File

@ -37,10 +37,6 @@ uint64_t EncryptedBlockStore::numBlocks() const {
return _baseBlockStore->numBlocks();
}
unique_ptr<Block> EncryptedBlockStore::tryCreateInBaseStore(const Key &key, Data encryptedData) {
return _baseBlockStore->tryCreate(key, std::move(encryptedData));
}
}
}

View File

@ -19,8 +19,6 @@ public:
void remove(std::unique_ptr<Block> block) override;
uint64_t numBlocks() const override;
std::unique_ptr<Block> tryCreateInBaseStore(const Key &key, Data encryptedData);
private:
std::unique_ptr<BlockStore> _baseBlockStore;
EncryptionKey _encKey;