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