2021-07-11 09:22:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-09-28 08:45:15 +00:00
|
|
|
#include "config.h"
|
2021-11-22 11:19:26 +00:00
|
|
|
#include <Common/assert_cast.h>
|
2021-07-11 09:22:30 +00:00
|
|
|
|
|
|
|
#if USE_SSL
|
|
|
|
#include <IO/WriteBufferFromFileBase.h>
|
|
|
|
#include <IO/FileEncryptionCommon.h>
|
2021-11-10 22:58:56 +00:00
|
|
|
#include <IO/WriteBufferDecorator.h>
|
2021-07-11 09:22:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-07-11 19:26:39 +00:00
|
|
|
/// Encrypts data and writes the encrypted data to the underlying write buffer.
|
2021-11-10 22:58:56 +00:00
|
|
|
class WriteBufferFromEncryptedFile : public WriteBufferDecorator<WriteBufferFromFileBase>
|
2021-07-11 09:22:30 +00:00
|
|
|
{
|
|
|
|
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_,
|
2021-07-23 08:18:11 +00:00
|
|
|
const FileEncryption::Header & header_,
|
2021-07-11 19:26:39 +00:00
|
|
|
size_t old_file_size = 0);
|
2021-11-10 22:58:56 +00:00
|
|
|
|
2021-07-11 09:22:30 +00:00
|
|
|
~WriteBufferFromEncryptedFile() override;
|
|
|
|
|
|
|
|
void sync() override;
|
|
|
|
|
2024-01-03 16:47:15 +00:00
|
|
|
std::string getFileName() const override { return assert_cast<WriteBufferFromFileBase *>(out)->getFileName(); }
|
2021-07-11 09:22:30 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void nextImpl() override;
|
|
|
|
|
2021-11-22 11:19:26 +00:00
|
|
|
void finalizeBefore() override;
|
2021-07-11 09:22:30 +00:00
|
|
|
|
2021-07-23 08:18:11 +00:00
|
|
|
FileEncryption::Header header;
|
|
|
|
bool flush_header = false;
|
2021-07-11 19:26:39 +00:00
|
|
|
|
2021-07-11 09:22:30 +00:00
|
|
|
FileEncryption::Encryptor encryptor;
|
2024-01-09 14:44:33 +00:00
|
|
|
|
2024-01-23 17:04:50 +00:00
|
|
|
LoggerPtr log = getLogger("WriteBufferFromEncryptedFile");
|
2021-07-11 09:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|