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