1 /* 2 Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. 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_FILE_INCLUDED 26 #define MYSQL_HARNESS_KEYRING_FILE_INCLUDED 27 28 #include <iostream> 29 #include "keyring_memory.h" 30 31 namespace mysql_harness { 32 33 /** 34 * KeyringFile class. 35 * 36 * Implements Keyring interface and provides additional methods for loading and 37 * saving keyring to file. 38 */ 39 class HARNESS_EXPORT KeyringFile : public KeyringMemory { 40 public: 41 KeyringFile() = default; 42 43 /** 44 * Sets additional data to be stored with the file but will not be 45 * encrypted. 46 * 47 * @param[in] data to store in header 48 */ 49 void set_header(const std::string &data); 50 51 /** 52 * Saves keyring to file. 53 * 54 * @param[in] file_name Keyring file name. 55 * @param[in] key Key used for encryption. 56 * 57 * @exception std::exception Saving to file failed. 58 */ 59 void save(const std::string &file_name, const std::string &key) const; 60 61 /** 62 * Load keyring from file. 63 * 64 * @param[in] file_name Keyring file name. 65 * @param[in] key Key used for decryption. 66 * 67 * @exception std::exception Loading from file failed. 68 */ 69 void load(const std::string &file_name, const std::string &key); 70 71 /** 72 * Read header data from file. 73 * 74 * @param[in] file_name Keyring file name. 75 * 76 * @exception std::exception Loading from file failed. 77 */ 78 std::string read_header(const std::string &file_name); 79 80 private: 81 std::string header_; 82 }; 83 84 } // namespace mysql_harness 85 86 #endif // MYSQL_HARNESS_KEYRING_FILE_INCLUDED 87