Davide Pesavento | ba3f689 | 2020-12-08 22:18:35 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | bde084f | 2022-04-17 00:21:35 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, Regents of the University of California |
Davide Pesavento | ba3f689 | 2020-12-08 22:18:35 -0500 | [diff] [blame] | 4 | * |
| 5 | * NAC library is free software: you can redistribute it and/or modify it under the |
| 6 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 7 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * NAC library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 11 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 12 | * |
| 13 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 14 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 15 | * <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * See AUTHORS.md for complete list of NAC library authors and contributors. |
| 18 | */ |
| 19 | |
| 20 | #ifndef NAC_TESTS_KEY_CHAIN_FIXTURE_HPP |
| 21 | #define NAC_TESTS_KEY_CHAIN_FIXTURE_HPP |
| 22 | |
| 23 | #include <ndn-cxx/security/key-chain.hpp> |
Davide Pesavento | ba3f689 | 2020-12-08 22:18:35 -0500 | [diff] [blame] | 24 | |
Davide Pesavento | bde084f | 2022-04-17 00:21:35 -0400 | [diff] [blame^] | 25 | namespace ndn::nac::tests { |
Davide Pesavento | ba3f689 | 2020-12-08 22:18:35 -0500 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * @brief A fixture providing an in-memory KeyChain. |
| 29 | * |
| 30 | * Test cases can use this fixture to create identities. Identities, certificates, and |
| 31 | * saved certificates are automatically removed during test teardown. |
| 32 | */ |
| 33 | class KeyChainFixture |
| 34 | { |
| 35 | protected: |
| 36 | using Certificate = ndn::security::Certificate; |
| 37 | using Identity = ndn::security::Identity; |
| 38 | using Key = ndn::security::Key; |
| 39 | |
| 40 | public: |
| 41 | /** |
Davide Pesavento | ba3f689 | 2020-12-08 22:18:35 -0500 | [diff] [blame] | 42 | * @brief Saves an NDN certificate to a file |
| 43 | * @return true if successful, false otherwise |
| 44 | */ |
| 45 | bool |
| 46 | saveCert(const Data& cert, const std::string& filename); |
| 47 | |
| 48 | /** |
| 49 | * @brief Saves the default certificate of @p identity to a file |
| 50 | * @return true if successful, false otherwise |
| 51 | */ |
| 52 | bool |
| 53 | saveIdentityCert(const Identity& identity, const std::string& filename); |
| 54 | |
| 55 | /** |
| 56 | * @brief Saves the default certificate of the identity named @p identityName to a file |
| 57 | * @param identityName Name of the identity |
| 58 | * @param filename File name, must be writable |
| 59 | * @param allowCreate If true, create the identity if it does not exist |
| 60 | * @return true if successful, false otherwise |
| 61 | */ |
| 62 | bool |
| 63 | saveIdentityCert(const Name& identityName, const std::string& filename, |
| 64 | bool allowCreate = false); |
| 65 | |
| 66 | protected: |
| 67 | KeyChainFixture(); |
| 68 | |
| 69 | ~KeyChainFixture(); |
| 70 | |
| 71 | protected: |
| 72 | ndn::KeyChain m_keyChain; |
| 73 | |
| 74 | private: |
| 75 | std::vector<std::string> m_certFiles; |
| 76 | }; |
| 77 | |
Davide Pesavento | bde084f | 2022-04-17 00:21:35 -0400 | [diff] [blame^] | 78 | } // namespace ndn::nac::tests |
Davide Pesavento | ba3f689 | 2020-12-08 22:18:35 -0500 | [diff] [blame] | 79 | |
| 80 | #endif // NAC_TESTS_KEY_CHAIN_FIXTURE_HPP |