blob: 318cdd1c5b2008cea6333929ef330c2805c1473f [file] [log] [blame]
Yanbiao Lic17de832014-11-21 17:51:45 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi38f4ce92016-08-04 10:01:52 +00003 * 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 Lic17de832014-11-21 17:51:45 -080010 *
Junxiao Shi38f4ce92016-08-04 10:01:52 +000011 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
Yanbiao Lic17de832014-11-21 17:51:45 -080013 *
Junxiao Shi38f4ce92016-08-04 10:01:52 +000014 * 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 Lic17de832014-11-21 17:51:45 -080017 *
Junxiao Shi38f4ce92016-08-04 10:01:52 +000018 * 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 Lic17de832014-11-21 17:51:45 -080021 *
Junxiao Shi38f4ce92016-08-04 10:01:52 +000022 * 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 Lic17de832014-11-21 17:51:45 -080024 */
25
Yukai Tu0a49d342015-09-13 12:54:22 +080026#ifndef NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
27#define NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
28
Yanbiao Lic17de832014-11-21 17:51:45 -080029#include "tests/test-common.hpp"
30#include <ndn-cxx/security/key-chain.hpp>
Yanbiao Lic17de832014-11-21 17:51:45 -080031
32namespace nfd {
33namespace tests {
34
Junxiao Shid7631272016-08-17 04:16:31 +000035/** \brief a fixture that cleans up KeyChain identities and certificate files upon destruction
Yanbiao Lic17de832014-11-21 17:51:45 -080036 */
Yukai Tu0a49d342015-09-13 12:54:22 +080037class IdentityManagementFixture : public virtual BaseFixture
Yanbiao Lic17de832014-11-21 17:51:45 -080038{
39public:
40 IdentityManagementFixture();
41
Junxiao Shid7631272016-08-17 04:16:31 +000042 /** \brief deletes created identities and saved certificate files
43 */
Yanbiao Lic17de832014-11-21 17:51:45 -080044 ~IdentityManagementFixture();
45
Junxiao Shid7631272016-08-17 04:16:31 +000046 /** \brief add identity
47 * \return whether successful
48 */
Yanbiao Lic17de832014-11-21 17:51:45 -080049 bool
Junxiao Shid7631272016-08-17 04:16:31 +000050 addIdentity(const Name& identity,
Yanbiao Lic17de832014-11-21 17:51:45 -080051 const ndn::KeyParams& params = ndn::KeyChain::DEFAULT_KEY_PARAMS);
52
Junxiao Shid7631272016-08-17 04:16:31 +000053 /** \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 Lic17de832014-11-21 17:51:45 -080062protected:
63 ndn::KeyChain m_keyChain;
Junxiao Shid7631272016-08-17 04:16:31 +000064
65private:
Yanbiao Lic17de832014-11-21 17:51:45 -080066 std::vector<ndn::Name> m_identities;
Junxiao Shid7631272016-08-17 04:16:31 +000067 std::vector<std::string> m_certFiles;
Yanbiao Lic17de832014-11-21 17:51:45 -080068};
69
Junxiao Shid7631272016-08-17 04:16:31 +000070/** \brief convenience base class for inheriting from both UnitTestTimeFixture
71 * and IdentityManagementFixture
72 */
Junxiao Shi38f4ce92016-08-04 10:01:52 +000073class IdentityManagementTimeFixture : public UnitTestTimeFixture
74 , public IdentityManagementFixture
75{
76};
77
Yanbiao Lic17de832014-11-21 17:51:45 -080078} // namespace tests
79} // namespace nfd
Yukai Tu0a49d342015-09-13 12:54:22 +080080
81#endif // NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP