MySQL 8.3.0
Source Code Documentation
keyring_manager.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_MANAGER_INCLUDED
26#define MYSQL_HARNESS_KEYRING_MANAGER_INCLUDED
27
28#include <stdexcept>
29#include <string>
30
31#include "keyring.h"
32#include "keyring/master_key_file.h" // invalid_master_keyfile
33
34namespace mysql_harness {
35
36static const int kMaxKeyringKeyLength = 255;
37
38/**
39 * Initialize an instance of a keyring to be used in the application
40 * from the contents of a file, using the given master key file.
41 *
42 * @param keyring_file_path path to the file where keyring is stored
43 * @param master_key_path path to the file keyring master keys are stored
44 * @param create_if_needed creates the keyring if it doesn't exist yet
45 *
46 * @return false if the keyring had to be created
47 */
48HARNESS_EXPORT bool init_keyring(const std::string &keyring_file_path,
49 const std::string &master_key_path,
50 bool create_if_needed);
51
52/**
53 * Initialize an instance of a keyring to be used in the application
54 * from the contents of a file, using the given master key.
55 *
56 * @param keyring_file_path path to the file where keyring is stored
57 * @param master_key master key for the keyring
58 * @param create_if_needed creates the keyring if it doesn't exist yet
59 *
60 * @return false if the keyring had to be created
61 */
62HARNESS_EXPORT bool init_keyring_with_key(const std::string &keyring_file_path,
63 const std::string &master_key,
64 bool create_if_needed);
65
66/**
67 * Saves the keyring contents to disk.
68 */
69HARNESS_EXPORT void flush_keyring();
70
71/**
72 * Gets a previously initialized singleton instance of the keyring
73 */
74HARNESS_EXPORT Keyring *get_keyring() noexcept;
75
76/**
77 * Clears the keyring singleton.
78 */
79HARNESS_EXPORT void reset_keyring() noexcept;
80} // namespace mysql_harness
81
82#endif
Keyring interface.
Definition: keyring.h:40
Definition: common.h:41
HARNESS_EXPORT void reset_keyring() noexcept
Clears the keyring singleton.
Definition: keyring_manager.cc:214
HARNESS_EXPORT void flush_keyring()
Saves the keyring contents to disk.
Definition: keyring_manager.cc:207
static const int kMaxKeyringKeyLength
Definition: keyring_manager.h:36
HARNESS_EXPORT Keyring * get_keyring() noexcept
Gets a previously initialized singleton instance of the keyring.
Definition: keyring_manager.cc:212
HARNESS_EXPORT bool init_keyring(const std::string &keyring_file_path, const std::string &master_key_path, bool create_if_needed)
Initialize an instance of a keyring to be used in the application from the contents of a file,...
Definition: keyring_manager.cc:145
HARNESS_EXPORT bool init_keyring_with_key(const std::string &keyring_file_path, const std::string &master_key, bool create_if_needed)
Initialize an instance of a keyring to be used in the application from the contents of a file,...
Definition: keyring_manager.cc:186