userver: userver/dump/operations_encrypted.hpp Source File
Loading...
Searching...
No Matches
operations_encrypted.hpp
1#pragma once
2
3#include <userver/utils/boost_filesystem_file_status.hpp>
4
5#include <userver/dump/factory.hpp>
6#include <userver/dump/operations.hpp>
7#include <userver/utils/fast_pimpl.hpp>
8#include <userver/utils/strong_typedef.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace dump {
13
14using SecretKey = utils::NonLoggable<class SecretKeyTag, std::string>;
15
16class EncryptedWriter final : public Writer {
17public:
18 /// @brief Creates a new dump file and opens it
19 /// @throws `Error` on a filesystem error
21 std::string filename,
22 const SecretKey& secret_key,
23 boost::filesystem::perms,
24 tracing::ScopeTime& scope
25 );
26
27 ~EncryptedWriter() override;
28
29 void Finish() override;
30
31private:
32 void WriteRaw(std::string_view data) override;
33
34 struct Impl;
35 utils::FastPimpl<Impl, 632, 8> impl_;
36};
37
38class EncryptedReader final : public Reader {
39public:
40 /// @brief Opens an existing dump file
41 /// @throws `Error` on a filesystem error
42 EncryptedReader(std::string filename, const SecretKey& key);
43
44 ~EncryptedReader() override;
45
46 void Finish() override;
47
48private:
49 std::string_view ReadRaw(std::size_t max_size) override;
50
51 struct Impl;
52 utils::FastPimpl<Impl, 600, 8> impl_;
53};
54
55class EncryptedOperationsFactory final : public OperationsFactory {
56public:
57 EncryptedOperationsFactory(SecretKey&& secret_key, boost::filesystem::perms perms);
58
59 std::unique_ptr<Reader> CreateReader(std::string full_path) override;
60
61 std::unique_ptr<Writer> CreateWriter(std::string full_path, tracing::ScopeTime& scope) override;
62
63private:
64 const SecretKey secret_key_;
65 const boost::filesystem::perms perms_;
66};
67
68} // namespace dump
69
70USERVER_NAMESPACE_END