MySQL 8.0.40
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,
65 try {
66 if (callbacks.keyring_initialized() == false) {
67 return true;
68 }
69
70 if (data_id == nullptr || !*data_id) {
71 assert(false);
72 return true;
73 }
74
75 if (data_size > keyring_operations.maximum_data_length()) {
76 LogComponentErr(INFORMATION_LEVEL,
77 ER_NOTE_KEYRING_COMPONENT_WRITE_MAXIMUM_DATA_LENGTH,
78 keyring_operations.maximum_data_length());
79 return true;
80 }
81
82 Metadata metadata(data_id, auth_id);
83 if (keyring_operations.generate(metadata, data_type, data_size) == true) {
84 LogComponentErr(INFORMATION_LEVEL,
85 ER_NOTE_KEYRING_COMPONENT_GENERATE_FAILED, data_id,
86 (auth_id == nullptr || !*auth_id) ? "NULL" : auth_id);
87 return true;
88 }
89 return false;
90 } catch (...) {
91 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "generate",
92 "keyring_generate");
93 return true;
94 }
95}
96
97} // namespace service_implementation
98} // namespace keyring_common
99
100#endif // !KEYRING_GENERATOR_SERVICE_IMPL_TEMPLATE_INCLUDED
static const sasl_callback_t callbacks[]
Definition: auth_ldap_sasl_client.h:45
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
@ 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