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