Don't encrypt and re-decrypt when creating a block, but keep plaintext data
This commit is contained in:
parent
417a701636
commit
c18893c151
@ -23,18 +23,22 @@ 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)
|
||||
:Block(baseBlock->key()),
|
||||
_baseBlock(std::move(baseBlock)),
|
||||
_plaintextData(USEABLE_BLOCK_SIZE(_baseBlock->size())),
|
||||
_encKey(encKey),
|
||||
_dataChanged(false) {
|
||||
: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(std::move(plaintextData)),
|
||||
_encKey(encKey),
|
||||
_dataChanged(false) {
|
||||
}
|
||||
|
||||
EncryptedBlock::~EncryptedBlock() {
|
||||
_encryptToBaseBlock();
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user