Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 10 | * |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 13 | * |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 17 | * |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 21 | * |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 24 | */ |
| 25 | |
Yukai Tu | 0a49d34 | 2015-09-13 12:54:22 +0800 | [diff] [blame] | 26 | #ifndef NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |
| 27 | #define NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |
| 28 | |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 29 | #include "tests/test-common.hpp" |
| 30 | #include <ndn-cxx/security/key-chain.hpp> |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | namespace tests { |
| 34 | |
Junxiao Shi | d763127 | 2016-08-17 04:16:31 +0000 | [diff] [blame^] | 35 | /** \brief a fixture that cleans up KeyChain identities and certificate files upon destruction |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 36 | */ |
Yukai Tu | 0a49d34 | 2015-09-13 12:54:22 +0800 | [diff] [blame] | 37 | class IdentityManagementFixture : public virtual BaseFixture |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 38 | { |
| 39 | public: |
| 40 | IdentityManagementFixture(); |
| 41 | |
Junxiao Shi | d763127 | 2016-08-17 04:16:31 +0000 | [diff] [blame^] | 42 | /** \brief deletes created identities and saved certificate files |
| 43 | */ |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 44 | ~IdentityManagementFixture(); |
| 45 | |
Junxiao Shi | d763127 | 2016-08-17 04:16:31 +0000 | [diff] [blame^] | 46 | /** \brief add identity |
| 47 | * \return whether successful |
| 48 | */ |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 49 | bool |
Junxiao Shi | d763127 | 2016-08-17 04:16:31 +0000 | [diff] [blame^] | 50 | addIdentity(const Name& identity, |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 51 | const ndn::KeyParams& params = ndn::KeyChain::DEFAULT_KEY_PARAMS); |
| 52 | |
Junxiao Shi | d763127 | 2016-08-17 04:16:31 +0000 | [diff] [blame^] | 53 | /** \brief save identity certificate to a file |
| 54 | * \param identity identity name |
| 55 | * \param filename file name, should be writable |
| 56 | * \param wantAdd if true, add new identity when necessary |
| 57 | * \return whether successful |
| 58 | */ |
| 59 | bool |
| 60 | saveIdentityCertificate(const Name& identity, const std::string& filename, bool wantAdd = false); |
| 61 | |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 62 | protected: |
| 63 | ndn::KeyChain m_keyChain; |
Junxiao Shi | d763127 | 2016-08-17 04:16:31 +0000 | [diff] [blame^] | 64 | |
| 65 | private: |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 66 | std::vector<ndn::Name> m_identities; |
Junxiao Shi | d763127 | 2016-08-17 04:16:31 +0000 | [diff] [blame^] | 67 | std::vector<std::string> m_certFiles; |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 68 | }; |
| 69 | |
Junxiao Shi | d763127 | 2016-08-17 04:16:31 +0000 | [diff] [blame^] | 70 | /** \brief convenience base class for inheriting from both UnitTestTimeFixture |
| 71 | * and IdentityManagementFixture |
| 72 | */ |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 73 | class IdentityManagementTimeFixture : public UnitTestTimeFixture |
| 74 | , public IdentityManagementFixture |
| 75 | { |
| 76 | }; |
| 77 | |
Yanbiao Li | c17de83 | 2014-11-21 17:51:45 -0800 | [diff] [blame] | 78 | } // namespace tests |
| 79 | } // namespace nfd |
Yukai Tu | 0a49d34 | 2015-09-13 12:54:22 +0800 | [diff] [blame] | 80 | |
| 81 | #endif // NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |