mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-29 21:20:49 +00:00
refactoring
This commit is contained in:
parent
3f00f064af
commit
b7a0f2db57
@ -152,7 +152,7 @@ void registerDiskEncrypted(DiskFactory & factory)
|
||||
const Poco::Util::AbstractConfiguration & config,
|
||||
const String & config_prefix,
|
||||
ContextConstPtr /*context*/,
|
||||
const DisksMap & map) -> DiskPtr {
|
||||
const DisksMap & map) -> DiskPtr {
|
||||
|
||||
String wrapped_disk_name = config.getString(config_prefix + ".disk", "");
|
||||
if (wrapped_disk_name.empty())
|
||||
@ -162,9 +162,9 @@ void registerDiskEncrypted(DiskFactory & factory)
|
||||
String key = config.getString(config_prefix + ".key", "");
|
||||
if (key.empty())
|
||||
throw Exception("Encrypted disk key can not be empty. Disk " + name, ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG);
|
||||
if (key.size() != CipherKeyLength(DefaultCipher()))
|
||||
if (key.size() != CipherKeyLength(DefaultCipher()))
|
||||
throw Exception("Expected key with size " + std::to_string(CipherKeyLength(DefaultCipher())) + ", got key with size " + std::to_string(key.size()),
|
||||
ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG);
|
||||
ErrorCodes::UNKNOWN_ELEMENT_IN_CONFIG);
|
||||
|
||||
auto wrapped_disk = map.find(wrapped_disk_name);
|
||||
if (wrapped_disk == map.end())
|
||||
|
@ -110,7 +110,7 @@ public:
|
||||
|
||||
void copy(const String & from_path, const std::shared_ptr<IDisk> & to_disk, const String & to_path) override
|
||||
{
|
||||
IDisk::copy(from_path, to_disk, to_path);
|
||||
IDisk::copy(from_path, to_disk, to_path);
|
||||
}
|
||||
|
||||
std::unique_ptr<ReadBufferFromFileBase> readFile(
|
||||
@ -204,7 +204,7 @@ public:
|
||||
void onFreeze(const String & path) override
|
||||
{
|
||||
auto wrapped_path = wrappedPath(path);
|
||||
delegate->onFreeze(wrapped_path);
|
||||
delegate->onFreeze(wrapped_path);
|
||||
}
|
||||
|
||||
void applyNewSettings(const Poco::Util::AbstractConfiguration & config, ContextConstPtr context, const String & config_prefix, const DisksMap & map) override;
|
||||
|
@ -128,7 +128,7 @@ public:
|
||||
, block_size(CipherIVLength(evp_cipher))
|
||||
{
|
||||
assert(iv_.size() == CipherIVLength(evp_cipher));
|
||||
assert(key_.Size() == CipherKeyLength(evp_cipher));
|
||||
assert(key_.Size() == CipherKeyLength(evp_cipher));
|
||||
|
||||
offset = BlockOffset(offset_);
|
||||
}
|
||||
@ -164,7 +164,7 @@ protected:
|
||||
class Encryptor : public Encryption
|
||||
{
|
||||
public:
|
||||
Encryptor(const String & iv_, const EncryptionKey & key_, size_t off)
|
||||
Encryptor(const String & iv_, const EncryptionKey & key_, size_t off)
|
||||
: Encryption(iv_, key_, off) { }
|
||||
|
||||
void Encrypt(const char * plaintext, DB::WriteBuffer & buf, size_t size)
|
||||
@ -173,8 +173,8 @@ public:
|
||||
return;
|
||||
|
||||
auto iv = InitVector(init_vector);
|
||||
auto off = BlockOffset(offset);
|
||||
iv.Set(Blocks(offset));
|
||||
auto off = BlockOffset(offset);
|
||||
iv.Set(Blocks(offset));
|
||||
|
||||
size_t part_size = PartBlockSize(size, off);
|
||||
if (off)
|
||||
@ -182,14 +182,14 @@ public:
|
||||
buf.write(EncryptPartialBlock(plaintext, part_size, iv, off).data(), part_size);
|
||||
offset += part_size;
|
||||
size -= part_size;
|
||||
plaintext += part_size;
|
||||
plaintext += part_size;
|
||||
iv.Inc();
|
||||
}
|
||||
|
||||
if (size)
|
||||
{
|
||||
buf.write(EncryptNBytes(plaintext + part_size, size, iv).data(), size);
|
||||
offset += size;
|
||||
offset += size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,15 +257,15 @@ public:
|
||||
return;
|
||||
|
||||
auto iv = InitVector(init_vector);
|
||||
iv.Set(Blocks(off));
|
||||
off = BlockOffset(off);
|
||||
iv.Set(Blocks(off));
|
||||
off = BlockOffset(off);
|
||||
|
||||
size_t part_size = PartBlockSize(size, off);
|
||||
if (off)
|
||||
{
|
||||
DecryptPartialBlock(buf, ciphertext, part_size, iv, off);
|
||||
size -= part_size;
|
||||
if (part_size + off == block_size)
|
||||
if (part_size + off == block_size)
|
||||
iv.Inc();
|
||||
}
|
||||
|
||||
|
@ -18,12 +18,12 @@ public:
|
||||
std::unique_ptr<ReadBufferFromFileBase> in_,
|
||||
const String & init_vector_,
|
||||
const EncryptionKey & key_,
|
||||
const size_t iv_offset_)
|
||||
const size_t iv_offset_)
|
||||
: ReadBufferFromFileBase(buf_size_, nullptr, 0)
|
||||
, in(std::move(in_))
|
||||
, buf_size(buf_size_)
|
||||
, decryptor(Decryptor(init_vector_, key_))
|
||||
, iv_offset(iv_offset_)
|
||||
, iv_offset(iv_offset_)
|
||||
{ }
|
||||
|
||||
off_t seek(off_t off, int whence) override
|
||||
@ -83,7 +83,7 @@ private:
|
||||
size_t in_pos = start_pos + iv_offset;
|
||||
|
||||
String data;
|
||||
data.resize(buf_size);
|
||||
data.resize(buf_size);
|
||||
size_t data_size = 0;
|
||||
|
||||
in->seek(in_pos, SEEK_SET);
|
||||
@ -96,11 +96,11 @@ private:
|
||||
}
|
||||
|
||||
data.resize(data_size);
|
||||
working_buffer.resize(data_size);
|
||||
working_buffer.resize(data_size);
|
||||
|
||||
decryptor.Decrypt(data.data(), working_buffer.begin(), data_size, start_pos);
|
||||
|
||||
pos = working_buffer.begin();
|
||||
pos = working_buffer.begin();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
|
@ -30,22 +30,22 @@ public:
|
||||
try
|
||||
{
|
||||
finalize();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
tryLogCurrentException(__PRETTY_FUNCTION__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void finalize() override
|
||||
{
|
||||
if (finalized)
|
||||
return;
|
||||
return;
|
||||
|
||||
next();
|
||||
out->finalize();
|
||||
|
||||
finalized = true;
|
||||
finalized = true;
|
||||
}
|
||||
|
||||
void sync() override
|
||||
|
Loading…
Reference in New Issue
Block a user