blob: d792a3f6a651e601fdd787037c232b676d4da84e [file] [log] [blame]
Yingdi Yud9715e32014-06-27 08:48:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhang1e164cc2017-01-03 11:04:35 -08003 * Copyright (c) 2013-2017 Regents of the University of California.
Yingdi Yud9715e32014-06-27 08:48:47 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
Yingdi Yu41546342014-11-30 23:37:53 -080022#ifndef NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
23#define NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
24
Yingdi Yud9715e32014-06-27 08:48:47 -070025#include "security/key-chain.hpp"
Zhiyi Zhang1e164cc2017-01-03 11:04:35 -080026#include "security/signing-helpers.hpp"
Yingdi Yud9715e32014-06-27 08:48:47 -070027#include <vector>
28
29#include "boost-test.hpp"
30
31namespace ndn {
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070032namespace tests {
Yingdi Yud9715e32014-06-27 08:48:47 -070033
34/**
35 * @brief IdentityManagementFixture is a test suite level fixture.
36 * Test cases in the suite can use this fixture to create identities.
37 * Identities added via addIdentity method are automatically deleted
38 * during test teardown.
39 */
40class IdentityManagementFixture
41{
42public:
43 IdentityManagementFixture();
44
45 ~IdentityManagementFixture();
46
47 /// @brief add identity, return true if succeed.
48 bool
49 addIdentity(const Name& identity, const KeyParams& params = KeyChain::DEFAULT_KEY_PARAMS);
50
Zhiyi Zhang0a939b42016-11-16 14:27:20 -080051 /**
52 * @brief save identity certificate to a file
53 * @param identity identity name
54 * @param filename file name, should be writable
55 * @param wantAdd if true, add new identity when necessary
56 * @return whether successful
57 */
58 bool
59 saveIdentityCertificate(const Name& identity, const std::string& filename, bool wantAdd = false);
60
Zhiyi Zhang1e164cc2017-01-03 11:04:35 -080061 /** \brief issue a certificate for \p identity signed by \p issuer
62 *
63 * If identity does not exist, it is created.
64 * A new key is generated as the default key for identity.
65 * A default certificate for the key is signed by the issuer using its default certificate.
66 *
67 * \return whether success
68 */
69 bool
70 addSubCertificate(const Name& identity, const Name& issuer,
71 const KeyParams& params = KeyChain::DEFAULT_KEY_PARAMS);
72
Yingdi Yud9715e32014-06-27 08:48:47 -070073protected:
74 KeyChain m_keyChain;
Zhiyi Zhang0a939b42016-11-16 14:27:20 -080075
76private:
Yingdi Yud9715e32014-06-27 08:48:47 -070077 std::vector<Name> m_identities;
Zhiyi Zhang0a939b42016-11-16 14:27:20 -080078 std::vector<std::string> m_certFiles;
Yingdi Yud9715e32014-06-27 08:48:47 -070079};
80
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070081} // namespace tests
Yingdi Yud9715e32014-06-27 08:48:47 -070082} // namespace ndn
Yingdi Yu41546342014-11-30 23:37:53 -080083
84#endif // NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP