Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 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. |
| 10 | * |
| 11 | * This file is part of NDNS (Named Data Networking Domain Name Service) and is |
| 12 | * based on the code written as part of NFD (Named Data Networking Daemon). |
| 13 | * See AUTHORS.md for complete list of NDNS authors and contributors. |
| 14 | * |
| 15 | * NDNS is free software: you can redistribute it and/or modify it under the terms |
| 16 | * of the GNU General Public License as published by the Free Software Foundation, |
| 17 | * either version 3 of the License, or (at your option) any later version. |
| 18 | * |
| 19 | * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 20 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 21 | * PURPOSE. See the GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License along with |
| 24 | * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 25 | */ |
| 26 | |
| 27 | #ifndef NDNS_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |
| 28 | #define NDNS_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |
| 29 | |
| 30 | #include "test-common.hpp" |
| 31 | |
| 32 | namespace ndn { |
| 33 | namespace ndns { |
| 34 | namespace tests { |
| 35 | |
| 36 | /** \brief a fixture that cleans up KeyChain identities and certificate files upon destruction |
| 37 | */ |
| 38 | class IdentityManagementFixture : public virtual BaseFixture |
| 39 | { |
| 40 | public: |
| 41 | IdentityManagementFixture(); |
| 42 | |
| 43 | /** \brief deletes created identities and saved certificate files |
| 44 | */ |
| 45 | ~IdentityManagementFixture(); |
| 46 | |
| 47 | /** \brief add identity |
| 48 | * \return whether successful |
| 49 | */ |
| 50 | bool |
| 51 | addIdentity(const Name& identity, |
| 52 | const ndn::KeyParams& params = ndn::KeyChain::DEFAULT_KEY_PARAMS); |
| 53 | |
| 54 | /** \brief save identity certificate to a file |
| 55 | * \param identity identity name |
| 56 | * \param filename file name, should be writable |
| 57 | * \param wantAdd if true, add new identity when necessary |
| 58 | * \return whether successful |
| 59 | */ |
| 60 | bool |
| 61 | saveIdentityCertificate(const Name& identity, const std::string& filename, bool wantAdd = false); |
| 62 | |
| 63 | protected: |
| 64 | ndn::KeyChain m_keyChain; |
| 65 | |
| 66 | private: |
| 67 | std::vector<ndn::Name> m_identities; |
| 68 | std::vector<std::string> m_certFiles; |
| 69 | }; |
| 70 | |
| 71 | /** \brief convenience base class for inheriting from both UnitTestTimeFixture |
| 72 | * and IdentityManagementFixture |
| 73 | */ |
| 74 | class IdentityManagementTimeFixture : public UnitTestTimeFixture |
| 75 | , public IdentityManagementFixture |
| 76 | { |
| 77 | }; |
| 78 | |
| 79 | } // namespace tests |
| 80 | } // namespace ndns |
| 81 | } // namespace ndn |
| 82 | |
| 83 | #endif // NDNS_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |