MySQL 9.0.0
Source Code Documentation
backend.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
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, version 2.0, 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#ifndef KEYRING_FILE_BACKEND_INCLUDED
25#define KEYRING_FILE_BACKEND_INCLUDED
26
27#include <string>
28
32
33namespace keyring_file::backend {
34
36 public:
37 explicit Keyring_file_backend(const std::string &keyring_file_name,
38 bool read_only);
39
41
42 /**
43 Fetch data
44
45 @param [in] metadata Key
46 @param [out] data Value
47
48 @returns Status of find operation
49 @retval false Entry found. Check data.
50 @retval true Entry missing.
51 */
52 bool get(const keyring_common::meta::Metadata &metadata,
53 keyring_common::data::Data &data) const;
54
55 /**
56 Store data
57
58 @param [in] metadata Key
59 @param [in, out] data Value
60
61 @returns Status of store operation
62 @retval false Entry stored successfully
63 @retval true Failure
64 */
65
66 bool store(const keyring_common::meta::Metadata &metadata,
68
69 /**
70 Erase data located at given key
71
72 @param [in] metadata Key
73 @param [in] data Value - not used.
74
75 @returns Status of erase operation
76 @retval false Data deleted
77 @retval true Could not find or delete data
78 */
79 bool erase(const keyring_common::meta::Metadata &metadata,
81
82 /**
83 Generate random data and store it
84
85 @param [in] metadata Key
86 @param [out] data Generated value
87 @param [in] length Length of data to be generated
88
89 @returns Status of generate + store operation
90 @retval false Data generated and stored successfully
91 @retval true Error
92
93 */
94 bool generate(const keyring_common::meta::Metadata &metadata,
96
97 /**
98 Populate cache
99
100 @param [in] operations Handle to operations class
101
102 @returns status of cache insertion
103 @retval false Success
104 @retval true Failure
105 */
106 bool load_cache(
108 &operations);
109
110 /** Maximum data length supported */
111 size_t maximum_data_length() const { return 16384; }
112
113 /** Get number of elements stored in backend */
114 size_t size() const { return json_writer_.num_elements(); }
115
116 /** Validity */
117 bool valid() const { return valid_; }
118
119 private:
120 /**
121 Write existing data to file.
122 This function overwrites existing data stored in the file.
123
124 @returns Status of write operation.
125 @retval false Successfully written data to file
126 @retval true Error writing data to file
127 */
128 bool write_to_file();
129
130 /** Create data file if missing */
131 void create_file_if_missing(const std::string &file_name);
132
133 private:
134 /** Keyring file */
136
137 /** Read only flag */
139
140 /** In memory cache for keyring data */
142
143 /** Validity */
144 bool valid_;
145};
146
147} // namespace keyring_file::backend
148
149#endif // !KEYRING_FILE_BACKEND_INCLUDED
Sensitive data storage.
Definition: data.h:39
Definition: json_writer.h:44
size_t num_elements() const
Number of elements stored.
Definition: json_writer.cc:148
Common metadata.
Definition: meta.h:38
Keyring operations A class to perform operations on keyring.
Definition: operations.h:481
std::string keyring_file_name_
Keyring file.
Definition: backend.h:135
bool load_cache(keyring_common::operations::Keyring_operations< Keyring_file_backend > &operations)
Populate cache.
Definition: backend.cc:90
size_t size() const
Get number of elements stored in backend.
Definition: backend.h:114
bool store(const keyring_common::meta::Metadata &metadata, keyring_common::data::Data &data)
Store data.
Definition: backend.cc:124
keyring_common::json_data::Json_writer json_writer_
In memory cache for keyring data.
Definition: backend.h:141
void create_file_if_missing(const std::string &file_name)
Create data file if missing.
Definition: backend.cc:167
Keyring_file_backend(const std::string &keyring_file_name, bool read_only)
Definition: backend.cc:52
bool generate(const keyring_common::meta::Metadata &metadata, keyring_common::data::Data &data, size_t length)
Generate random data and store it.
Definition: backend.cc:146
bool write_to_file()
Write existing data to file.
Definition: backend.cc:161
bool get(const keyring_common::meta::Metadata &metadata, keyring_common::data::Data &data) const
Fetch data.
Definition: backend.cc:119
bool read_only_
Read only flag.
Definition: backend.h:138
size_t maximum_data_length() const
Maximum data length supported.
Definition: backend.h:111
bool erase(const keyring_common::meta::Metadata &metadata, keyring_common::data::Data &data)
Erase data located at given key.
Definition: backend.cc:135
bool valid() const
Validity.
Definition: backend.h:117
bool valid_
Validity.
Definition: backend.h:144
operations
Definition: mysqlcheck.h:39
constexpr value_type read_only
Definition: classic_protocol_constants.h:213
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Definition: backend.cc:38
std::string file_name(Log_file_id file_id)
Provides name of the log file with the given file id, e.g.
Definition: log0pre_8_0_30.cc:94