ClickHouse/src/IO/WriteBufferFromEncryptedFile.h

46 lines
1.1 KiB
C++
Raw Normal View History

#pragma once
#include <Common/config.h>
#if USE_SSL
#include <IO/WriteBufferFromFileBase.h>
#include <IO/FileEncryptionCommon.h>
2021-11-10 22:58:56 +00:00
#include <IO/WriteBufferDecorator.h>
namespace DB
{
/// 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>
{
public:
/// `old_file_size` should be set to non-zero if we're going to append an existing file.
WriteBufferFromEncryptedFile(
size_t buffer_size_,
std::unique_ptr<WriteBufferFromFileBase> out_,
const String & key_,
const FileEncryption::Header & header_,
size_t old_file_size = 0);
2021-11-10 22:58:56 +00:00
~WriteBufferFromEncryptedFile() override;
void sync() override;
2021-11-10 22:58:56 +00:00
std::string getFileName() const override { return dynamic_cast<WriteBufferFromFileBase *>(out.get())->getFileName(); }
private:
void nextImpl() override;
2021-11-10 22:58:56 +00:00
void finalizeBeforeNestedFinalize() override;
FileEncryption::Header header;
bool flush_header = false;
FileEncryption::Encryptor encryptor;
};
}
#endif