MySQL 9.0.0
Source Code Documentation
keyring_memory.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2016, 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 MYSQL_HARNESS_KEYRING_MEMORY_INCLUDED
27#define MYSQL_HARNESS_KEYRING_MEMORY_INCLUDED
28
29#include <map>
30#include <stdexcept>
31#include <vector>
32#include "keyring.h"
33
34namespace mysql_harness {
35
36class decryption_error : public std::runtime_error {
37 public:
38 decryption_error(const char *_what) : std::runtime_error(_what) {}
39};
40
41/**
42 * KeyringMemory class.
43 *
44 * Implements Keyring interface and provides additional methods for parsing
45 * and serialization using a simple binary format. Also, handles AES encryption.
46 * Used primarily for testing and as a base for KeyringFile.
47 */
48class HARNESS_EXPORT KeyringMemory : public Keyring {
49 public:
50 constexpr static unsigned int kFormatVersion = 0;
51
52 KeyringMemory() = default;
53
54 /**
55 * Serializes and encrypts keyring data to memory buffer.
56 *
57 * @param[in] key Key used for encryption.
58 *
59 * @return Serialized keyring data.
60 *
61 * @exception std::exception Serialization failed.
62 */
63 std::vector<char> serialize(const std::string &key) const;
64
65 /**
66 * Parses and decrypts keyring data.
67 *
68 * @param[in] key Key used for decryption.
69 * @param[in] buffer Serialized keyring data.
70 * @param[in] buffer_size Size of the data.
71 *
72 * @exception std::exception Parsing failed.
73 */
74 void parse(const std::string &key, const char *buffer,
75 std::size_t buffer_size);
76
77 // Keyring interface.
78 void store(const std::string &uid, const std::string &attribute,
79 const std::string &value) override;
80
81 std::string fetch(const std::string &uid,
82 const std::string &attribute) const override;
83
84 bool remove(const std::string &uid) override;
85
86 bool remove_attribute(const std::string &uid,
87 const std::string &attribute) override;
88
89 const std::map<std::string, std::map<std::string, std::string>> &entries()
90 const {
91 return entries_;
92 }
93
94 private:
95 std::map<std::string, std::map<std::string, std::string>> entries_;
96};
97
98} // namespace mysql_harness
99
100#endif // MYSQL_HARNESS_KEYRING_MEMORY_INCLUDED
KeyringMemory class.
Definition: keyring_memory.h:48
std::map< std::string, std::map< std::string, std::string > > entries_
Definition: keyring_memory.h:95
const std::map< std::string, std::map< std::string, std::string > > & entries() const
Definition: keyring_memory.h:89
Keyring interface.
Definition: keyring.h:41
Definition: keyring_memory.h:36
decryption_error(const char *_what)
Definition: keyring_memory.h:38
native_mutex_t serialize
Definition: debug_lock_order.cc:2884
bool store(THD *thd, const Table *tp)
Stores the SDI for a table.
Definition: sdi.cc:607
Definition: common.h:42
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
size_t buffer_size(const ConstBufferSequence &buffers) noexcept
Definition: buffer.h:313
static mysql_service_status_t remove(reference_caching_channel channel, const char *implementation_name) noexcept
Definition: component.cc:137
bool parse(MYSQL_THD thd, const string &query, bool is_prepared, Condition_handler *handler)
Definition: services.cc:81
Definition: gcs_xcom_synode.h:64
required string key
Definition: replication_asynchronous_connection_failover.proto:60