blob: 75d24ced917b6ccbe5264a7e72be0021fd503e58 [file] [log] [blame]
Alexander Afanasyev8495a4a2016-12-25 15:27:25 -08001/* -*- 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, originally written as part of NFD (Named Data Networking Forwarding Daemon),
12 * is a part of ChronoShare, a decentralized file sharing application over NDN.
13 *
14 * ChronoShare 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, either
16 * version 3 of the License, or (at your option) any later version.
17 *
18 * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY
19 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
20 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received copies of the GNU General Public License along with
23 * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * See AUTHORS.md for complete list of ChronoShare authors and contributors.
26 */
27
28#ifndef NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
29#define NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
30
31#include "tests/test-common.hpp"
32
33#include <ndn-cxx/security/key-chain.hpp>
34
35namespace ndn {
36namespace chronoshare {
37namespace tests {
38
39/** \brief a fixture that cleans up KeyChain identities and certificate files upon destruction
40 */
41class IdentityManagementFixture : public virtual BaseFixture
42{
43public:
44 IdentityManagementFixture();
45
46 /** \brief deletes created identities and saved certificate files
47 */
48 ~IdentityManagementFixture();
49
50 /** \brief add identity
51 * \return whether successful
52 */
53 bool
54 addIdentity(const Name& identity,
55 const ndn::KeyParams& params = ndn::KeyChain::DEFAULT_KEY_PARAMS);
56
57 /** \brief save identity certificate to a file
58 * \param identity identity name
59 * \param filename file name, should be writable
60 * \param wantAdd if true, add new identity when necessary
61 * \return whether successful
62 */
63 bool
64 saveIdentityCertificate(const Name& identity, const std::string& filename, bool wantAdd = false);
65
66protected:
67 ndn::KeyChain m_keyChain;
68
69private:
70 std::vector<ndn::Name> m_identities;
71 std::vector<std::string> m_certFiles;
72};
73
74/** \brief convenience base class for inheriting from both UnitTestTimeFixture
75 * and IdentityManagementFixture
76 */
77class IdentityManagementTimeFixture : public UnitTestTimeFixture
78 , public IdentityManagementFixture
79{
80};
81
82} // namespace tests
83} // namespace chronoshare
84} // namespace ndn
85
86#endif // NFD_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP