| 1 |
/* Copyright (c) 2021, 2026, 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 |
#include <components/keyrings/keyring_file/keyring_file.h> |
| 25 |
|
| 26 |
#include <components/keyrings/common/component_helpers/include/keyring_reader_service_definition.h> |
| 27 |
#include <components/keyrings/common/component_helpers/include/keyring_reader_service_impl_template.h> |
| 28 |
|
| 29 |
using keyring_file::g_component_callbacks; |
| 30 |
using keyring_file::g_keyring_operations; |
| 31 |
using keyring_file::backend::Keyring_file_backend; |
| 32 |
|
| 33 |
namespace keyring_common { |
| 34 |
|
| 35 |
using service_implementation::deinit_reader_template; |
| 36 |
using service_implementation::fetch_length_template; |
| 37 |
using service_implementation::fetch_template; |
| 38 |
using service_implementation::init_reader_template; |
| 39 |
|
| 40 |
namespace service_definition { |
| 41 |
|
| 42 |
DEFINE_BOOL_METHOD(Keyring_reader_service_impl::init, |
| 43 |
(const char *data_id, const char *auth_id, |
| 44 |
my_h_keyring_reader_object *reader_object)) { |
| 45 |
std::unique_ptr<Iterator<Data>> it; |
| 46 |
int retval = init_reader_template<Keyring_file_backend>( |
| 47 |
data_id, auth_id, it, *g_keyring_operations, *g_component_callbacks); |
| 48 |
*reader_object = nullptr; |
| 49 |
if (retval == 1) |
| 50 |
*reader_object = reinterpret_cast<my_h_keyring_reader_object>(it.release()); |
| 51 |
return retval < 0; |
| 52 |
} |
| 53 |
|
| 54 |
DEFINE_BOOL_METHOD(Keyring_reader_service_impl::deinit, |
| 55 |
(my_h_keyring_reader_object reader_object)) { |
| 56 |
std::unique_ptr<Iterator<Data>> it; |
| 57 |
it.reset(reinterpret_cast<Iterator<Data> *>(reader_object)); |
| 58 |
return deinit_reader_template<Keyring_file_backend>(it, *g_keyring_operations, |
| 59 |
*g_component_callbacks); |
| 60 |
} |
| 61 |
|
| 62 |
DEFINE_BOOL_METHOD(Keyring_reader_service_impl::fetch_length, |
| 63 |
(my_h_keyring_reader_object reader_object, size_t *data_size, |
| 64 |
size_t *data_type_size)) { |
| 65 |
std::unique_ptr<Iterator<Data>> it; |
| 66 |
it.reset(reinterpret_cast<Iterator<Data> *>(reader_object)); |
| 67 |
bool retval = fetch_length_template<Keyring_file_backend>( |
| 68 |
it, data_size, data_type_size, *g_keyring_operations, |
| 69 |
*g_component_callbacks); |
| 70 |
/* Make sure we don't free the pointer */ |
| 71 |
(void)it.release(); |
| 72 |
return retval; |
| 73 |
} |
| 74 |
|
| 75 |
DEFINE_BOOL_METHOD(Keyring_reader_service_impl::fetch, |
| 76 |
(my_h_keyring_reader_object reader_object, |
| 77 |
unsigned char *data_buffer, size_t data_buffer_length, |
| 78 |
size_t *data_size, char *data_type_buffer, |
| 79 |
size_t data_type_buffer_length, size_t *data_type_size)) { |
| 80 |
std::unique_ptr<Iterator<Data>> it; |
| 81 |
it.reset(reinterpret_cast<Iterator<Data> *>(reader_object)); |
| 82 |
bool retval = fetch_template<Keyring_file_backend>( |
| 83 |
it, data_buffer, data_buffer_length, data_size, data_type_buffer, |
| 84 |
data_type_buffer_length, data_type_size, *g_keyring_operations, |
| 85 |
*g_component_callbacks); |
| 86 |
/* Make sure we don't free the pointer */ |
| 87 |
(void)it.release(); |
| 88 |
return retval; |
| 89 |
} |
| 90 |
|
| 91 |
} // namespace service_definition |
| 92 |
} // namespace keyring_common |