MySQL 8.3.0
Source Code Documentation
master_key_file.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 2023, 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 also distributed 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 included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24
25#ifndef ROUTER_KEYRING_MASTER_KEY_FILE_INCLUDED
26#define ROUTER_KEYRING_MASTER_KEY_FILE_INCLUDED
27
28#include <stdexcept>
29#include <string>
30#include <utility> // std::pair
31#include <vector>
32
33#include "harness_export.h"
34#include "my_compiler.h"
35
36namespace mysql_harness {
37
40class HARNESS_EXPORT invalid_master_keyfile : public std::runtime_error {
41 public:
42 invalid_master_keyfile(const std::string &w) : std::runtime_error(w) {}
43};
45
46class HARNESS_EXPORT MasterKeyFile {
47 public:
48 MasterKeyFile(const std::string &file) : path_(file) {}
49
50 /**
51 * load master-key-file from disk.
52 *
53 * @throws std::runtime_error on failure
54 */
55 void load();
56
57 /**
58 * save master-key-file to disk.
59 *
60 * @throws std::runtime_error on failure
61 */
62 void save();
63
64 /**
65 * add value-key pair to 'id'.
66 *
67 * encrypts the value-key pair.
68 *
69 * @throws std::runtime_error on failure
70 */
71 void add(const std::string &id, const std::string &value,
72 const std::string &key);
73
74 /**
75 * add encrypted buffer to 'id'.
76 *
77 * @throws std::runtime_error on failure
78 */
79 void add_encrypted(const std::string &id, const std::string &buf);
80
81 /**
82 * get value for 'key' for 'id'.
83 *
84 * @returns value for 'key' of 'id'.
85 * @retval empty if key or id aren't found
86 */
87 std::string get(const std::string &id, const std::string &key) const;
88
89 /**
90 * get value encrypted 'key-value' pair for 'id'.
91 *
92 * @returns encrypted buffer of 'id'.
93 * @retval empty if key or id aren't found
94 */
95 std::string get_encrypted(const std::string &id) const;
96
97 /**
98 * remove id from master-key-dict.
99 *
100 * @returns success
101 * @retval true id removed
102 * @retval false id not removed (not found, ...)
103 */
104 bool remove(const std::string &id);
105
106 /**
107 * get entries.
108 */
109 const auto &entries() const { return entries_; }
110
111 private:
112 std::string path_;
113 std::vector<std::pair<std::string, std::string>> entries_;
114};
115} // namespace mysql_harness
116
117#endif
Definition: master_key_file.h:46
std::string path_
Definition: master_key_file.h:112
std::vector< std::pair< std::string, std::string > > entries_
Definition: master_key_file.h:113
MasterKeyFile(const std::string &file)
Definition: master_key_file.h:48
const auto & entries() const
get entries.
Definition: master_key_file.h:109
Definition: master_key_file.h:40
invalid_master_keyfile(const std::string &w)
Definition: master_key_file.h:42
Header for compiler-dependent features.
#define MY_COMPILER_MSVC_DIAGNOSTIC_IGNORE(X)
Definition: my_compiler.h:254
#define MY_COMPILER_DIAGNOSTIC_PUSH()
save the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:284
#define MY_COMPILER_DIAGNOSTIC_POP()
restore the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:285
Definition: buf0block_hint.cc:29
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:307
Definition: os0file.h:88
Definition: common.h:41
void get(PSI_field *, PSI_longlong *) noexcept
Definition: pfs_plugin_column_bigint_v1_all_empty.cc:31
static mysql_service_status_t remove(reference_caching_channel channel, const char *implementation_name) noexcept
Definition: component.cc:136
Definition: varlen_sort.h:174
required string key
Definition: replication_asynchronous_connection_failover.proto:59