MySQL 8.4.0
Source Code Documentation
keyring_generator_service_impl_template.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef KEYRING_GENERATOR_SERVICE_IMPL_TEMPLATE_INCLUDED
25#define KEYRING_GENERATOR_SERVICE_IMPL_TEMPLATE_INCLUDED
26
27#include <functional> /* std::function */
28#include <sstream>
29
30#include <my_dbug.h>
31#include <mysql/components/services/log_builtins.h> /* LogComponentErr */
32#include <mysqld_error.h>
33
37
38namespace keyring_common {
39namespace service_implementation {
40
43
44/**
45 Generate data and store in keyring
46
47 @param [in] data_id Data Identifier
48 @param [in] auth_id Authorization ID
49 @param [in] data_type Type of data. Assumed null terminated.
50 @param [in] data_size Size of the data to be generated
51 @param [in] keyring_operations Reference to the object
52 that handles cache and backend
53 @param [in] callbacks Handle to component specific callbacks
54
55 @returns status of the operation
56 @retval false Success - Key generated and stored in keyring.
57 @retval true Failure
58*/
59template <typename Backend, typename Data_extension = data::Data>
61 const char *data_id, const char *auth_id, const char *data_type,
62 size_t data_size,
64 Component_callbacks &callbacks) {
65 try {
66 if (callbacks.keyring_initialized() == false) {
67 LogComponentErr(INFORMATION_LEVEL,
68 ER_NOTE_KEYRING_COMPONENT_NOT_INITIALIZED);
69 return true;
70 }
71
72 if (data_id == nullptr || !*data_id) {
73 LogComponentErr(INFORMATION_LEVEL,
74 ER_NOTE_KEYRING_COMPONENT_EMPTY_DATA_ID);
75 assert(false);
76 return true;
77 }
78
79 if (data_size > keyring_operations.maximum_data_length()) {
80 LogComponentErr(INFORMATION_LEVEL,
81 ER_NOTE_KEYRING_COMPONENT_WRITE_MAXIMUM_DATA_LENGTH,
82 keyring_operations.maximum_data_length());
83 return true;
84 }
85
86 Metadata metadata(data_id, auth_id);
87 if (keyring_operations.generate(metadata, data_type, data_size) == true) {
88 LogComponentErr(INFORMATION_LEVEL,
89 ER_NOTE_KEYRING_COMPONENT_GENERATE_FAILED, data_id,
90 (auth_id == nullptr || !*auth_id) ? "NULL" : auth_id);
91 return true;
92 }
93 return false;
94 } catch (...) {
95 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "generate",
96 "keyring_generate");
97 return true;
98 }
99}
100
101} // namespace service_implementation
102} // namespace keyring_common
103
104#endif // !KEYRING_GENERATOR_SERVICE_IMPL_TEMPLATE_INCLUDED
Common metadata.
Definition: meta.h:39
Keyring operations A class to perform operations on keyring.
Definition: operations.h:483
bool generate(const meta::Metadata &metadata, const data::Type type, size_t length)
Generate API.
Definition: operations.h:633
size_t maximum_data_length() const
Maximum data length supported.
Definition: operations.h:779
bool keyring_initialized()
Keyring component status.
Definition: component_callbacks.cc:29
@ ERROR_LEVEL
Definition: my_loglevel.h:43
@ INFORMATION_LEVEL
Definition: my_loglevel.h:45
bool generate_template(const char *data_id, const char *auth_id, const char *data_type, size_t data_size, Keyring_operations< Backend, Data_extension > &keyring_operations, Component_callbacks &callbacks)
Generate data and store in keyring.
Definition: keyring_generator_service_impl_template.h:60
Definition: keyring_encryption_service_definition.h:32