MySQL 8.0.39
Source Code Documentation
master_key_file.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_KEYRING_MASTER_KEY_FILE_INCLUDED
27#define ROUTER_KEYRING_MASTER_KEY_FILE_INCLUDED
28
29#include <stdexcept>
30#include <string>
31#include <utility> // std::pair
32#include <vector>
33
34#include "harness_export.h"
35#include "my_compiler.h"
36
37namespace mysql_harness {
38
41class HARNESS_EXPORT invalid_master_keyfile : public std::runtime_error {
42 public:
43 invalid_master_keyfile(const std::string &w) : std::runtime_error(w) {}
44};
46
47class HARNESS_EXPORT MasterKeyFile {
48 public:
49 MasterKeyFile(const std::string &file) : path_(file) {}
50
51 /**
52 * load master-key-file from disk.
53 *
54 * @throws std::runtime_error on failure
55 */
56 void load();
57
58 /**
59 * save master-key-file to disk.
60 *
61 * @throws std::runtime_error on failure
62 */
63 void save();
64
65 /**
66 * add value-key pair to 'id'.
67 *
68 * encrypts the value-key pair.
69 *
70 * @throws std::runtime_error on failure
71 */
72 void add(const std::string &id, const std::string &value,
73 const std::string &key);
74
75 /**
76 * add encrypted buffer to 'id'.
77 *
78 * @throws std::runtime_error on failure
79 */
80 void add_encrypted(const std::string &id, const std::string &buf);
81
82 /**
83 * get value for 'key' for 'id'.
84 *
85 * @returns value for 'key' of 'id'.
86 * @retval empty if key or id aren't found
87 */
88 std::string get(const std::string &id, const std::string &key) const;
89
90 /**
91 * get value encrypted 'key-value' pair for 'id'.
92 *
93 * @returns encrypted buffer of 'id'.
94 * @retval empty if key or id aren't found
95 */
96 std::string get_encrypted(const std::string &id) const;
97
98 /**
99 * remove id from master-key-dict.
100 *
101 * @returns success
102 * @retval true id removed
103 * @retval false id not removed (not found, ...)
104 */
105 bool remove(const std::string &id);
106
107 /**
108 * get entries.
109 */
110 const auto &entries() const { return entries_; }
111
112 private:
113 std::string path_;
114 std::vector<std::pair<std::string, std::string>> entries_;
115};
116} // namespace mysql_harness
117
118#endif
Definition: master_key_file.h:47
std::string path_
Definition: master_key_file.h:113
std::vector< std::pair< std::string, std::string > > entries_
Definition: master_key_file.h:114
MasterKeyFile(const std::string &file)
Definition: master_key_file.h:49
const auto & entries() const
get entries.
Definition: master_key_file.h:110
Definition: master_key_file.h:41
invalid_master_keyfile(const std::string &w)
Definition: master_key_file.h:43
Header for compiler-dependent features.
#define MY_COMPILER_MSVC_DIAGNOSTIC_IGNORE(X)
Definition: my_compiler.h:266
#define MY_COMPILER_DIAGNOSTIC_PUSH()
save the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:296
#define MY_COMPILER_DIAGNOSTIC_POP()
restore the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:297
Definition: buf0block_hint.cc:30
bool load(THD *, const dd::String_type &fname, dd::String_type *buf)
Read an sdi file from disk and store in a buffer.
Definition: sdi_file.cc:308
Definition: os0file.h:86
Definition: common.h:42
void get(PSI_field *, PSI_longlong *) noexcept
Definition: pfs_plugin_column_bigint_v1_all_empty.cc:32
static mysql_service_status_t remove(reference_caching_channel channel, const char *implementation_name) noexcept
Definition: component.cc:145
Definition: gcs_xcom_synode.h:64
required string key
Definition: replication_asynchronous_connection_failover.proto:60