2021-07-11 09:22:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#if !defined(ARCADIA_BUILD)
|
|
|
|
#include <Common/config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_SSL
|
|
|
|
#include <IO/WriteBufferFromFileBase.h>
|
|
|
|
#include <IO/FileEncryptionCommon.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-07-11 19:26:39 +00:00
|
|
|
/// Encrypts data and writes the encrypted data to the underlying write buffer.
|
2021-07-11 09:22:30 +00:00
|
|
|
class WriteBufferFromEncryptedFile : public WriteBufferFromFileBase
|
|
|
|
{
|
|
|
|
public:
|
2021-07-11 19:26:39 +00:00
|
|
|
/// `old_file_size` should be set to non-zero if we're going to append an existing file.
|
2021-07-11 09:22:30 +00:00
|
|
|
WriteBufferFromEncryptedFile(
|
2021-07-11 19:26:39 +00:00
|
|
|
size_t buffer_size_,
|
2021-07-11 09:22:30 +00:00
|
|
|
std::unique_ptr<WriteBufferFromFileBase> out_,
|
2021-07-11 19:26:39 +00:00
|
|
|
const String & key_,
|
|
|
|
const FileEncryption::InitVector & init_vector_,
|
|
|
|
size_t old_file_size = 0);
|
2021-07-11 09:22:30 +00:00
|
|
|
~WriteBufferFromEncryptedFile() override;
|
|
|
|
|
|
|
|
void sync() override;
|
|
|
|
void finalize() override { finish(); }
|
|
|
|
|
|
|
|
std::string getFileName() const override { return out->getFileName(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void nextImpl() override;
|
|
|
|
|
|
|
|
void finish();
|
|
|
|
void finishImpl();
|
|
|
|
|
|
|
|
bool finished = false;
|
|
|
|
std::unique_ptr<WriteBufferFromFileBase> out;
|
|
|
|
|
2021-07-11 19:26:39 +00:00
|
|
|
FileEncryption::InitVector iv;
|
|
|
|
bool flush_iv = false;
|
|
|
|
|
2021-07-11 09:22:30 +00:00
|
|
|
FileEncryption::Encryptor encryptor;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|