2021-07-11 09:22:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-09-28 08:45:15 +00:00
|
|
|
#include "config.h"
|
2021-07-11 09:22:30 +00:00
|
|
|
|
|
|
|
#if USE_SSL
|
|
|
|
#include <IO/ReadBufferFromFileBase.h>
|
|
|
|
#include <IO/FileEncryptionCommon.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-07-11 19:26:39 +00:00
|
|
|
/// Reads data from the underlying read buffer and decrypts it.
|
2021-07-11 09:22:30 +00:00
|
|
|
class ReadBufferFromEncryptedFile : public ReadBufferFromFileBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ReadBufferFromEncryptedFile(
|
2021-07-11 19:26:39 +00:00
|
|
|
size_t buffer_size_,
|
2021-07-11 09:22:30 +00:00
|
|
|
std::unique_ptr<ReadBufferFromFileBase> in_,
|
2021-07-11 19:26:39 +00:00
|
|
|
const String & key_,
|
2021-07-23 08:18:11 +00:00
|
|
|
const FileEncryption::Header & header_,
|
|
|
|
size_t offset_ = 0);
|
2021-07-11 09:22:30 +00:00
|
|
|
|
|
|
|
off_t seek(off_t off, int whence) override;
|
2021-07-11 19:26:39 +00:00
|
|
|
off_t getPosition() override;
|
2021-07-11 09:22:30 +00:00
|
|
|
|
|
|
|
std::string getFileName() const override { return in->getFileName(); }
|
|
|
|
|
2022-05-13 15:17:13 +00:00
|
|
|
void setReadUntilPosition(size_t position) override { in->setReadUntilPosition(position + FileEncryption::Header::kSize); }
|
2024-02-13 11:02:46 +00:00
|
|
|
|
2022-05-13 15:17:13 +00:00
|
|
|
void setReadUntilEnd() override { in->setReadUntilEnd(); }
|
2022-04-26 10:55:27 +00:00
|
|
|
|
2024-02-13 11:02:46 +00:00
|
|
|
size_t getFileSize() override { return in->getFileSize(); }
|
2022-05-25 14:49:40 +00:00
|
|
|
|
2021-07-11 09:22:30 +00:00
|
|
|
private:
|
|
|
|
bool nextImpl() override;
|
|
|
|
|
|
|
|
std::unique_ptr<ReadBufferFromFileBase> in;
|
|
|
|
|
2021-07-11 19:26:39 +00:00
|
|
|
off_t offset = 0;
|
2022-04-26 10:55:27 +00:00
|
|
|
|
2021-07-11 19:26:39 +00:00
|
|
|
bool need_seek = false;
|
2021-07-11 09:22:30 +00:00
|
|
|
|
2021-07-11 19:26:39 +00:00
|
|
|
Memory<> encrypted_buffer;
|
|
|
|
FileEncryption::Encryptor encryptor;
|
2021-07-11 09:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|