blob: 7d6c16bc7a574c3e0d2c1ea33e077fbd6fd64454 [file] [log] [blame]
Davide Pesaventoba3f6892020-12-08 22:18:35 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventobde084f2022-04-17 00:21:35 -04003 * Copyright (c) 2014-2022, Regents of the University of California
Davide Pesaventoba3f6892020-12-08 22:18:35 -05004 *
5 * NAC library is free software: you can redistribute it and/or modify it under the
6 * terms of the GNU Lesser General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option) any later version.
8 *
9 * NAC library is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
12 *
13 * You should have received copies of the GNU General Public License and GNU Lesser
14 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 * See AUTHORS.md for complete list of NAC library authors and contributors.
18 */
19
20#ifndef NAC_TESTS_KEY_CHAIN_FIXTURE_HPP
21#define NAC_TESTS_KEY_CHAIN_FIXTURE_HPP
22
23#include <ndn-cxx/security/key-chain.hpp>
Davide Pesaventoba3f6892020-12-08 22:18:35 -050024
Davide Pesaventobde084f2022-04-17 00:21:35 -040025namespace ndn::nac::tests {
Davide Pesaventoba3f6892020-12-08 22:18:35 -050026
27/**
28 * @brief A fixture providing an in-memory KeyChain.
29 *
30 * Test cases can use this fixture to create identities. Identities, certificates, and
31 * saved certificates are automatically removed during test teardown.
32 */
33class KeyChainFixture
34{
35protected:
36 using Certificate = ndn::security::Certificate;
37 using Identity = ndn::security::Identity;
38 using Key = ndn::security::Key;
39
40public:
41 /**
Davide Pesaventoba3f6892020-12-08 22:18:35 -050042 * @brief Saves an NDN certificate to a file
43 * @return true if successful, false otherwise
44 */
45 bool
46 saveCert(const Data& cert, const std::string& filename);
47
48 /**
49 * @brief Saves the default certificate of @p identity to a file
50 * @return true if successful, false otherwise
51 */
52 bool
53 saveIdentityCert(const Identity& identity, const std::string& filename);
54
55 /**
56 * @brief Saves the default certificate of the identity named @p identityName to a file
57 * @param identityName Name of the identity
58 * @param filename File name, must be writable
59 * @param allowCreate If true, create the identity if it does not exist
60 * @return true if successful, false otherwise
61 */
62 bool
63 saveIdentityCert(const Name& identityName, const std::string& filename,
64 bool allowCreate = false);
65
66protected:
67 KeyChainFixture();
68
69 ~KeyChainFixture();
70
71protected:
72 ndn::KeyChain m_keyChain;
73
74private:
75 std::vector<std::string> m_certFiles;
76};
77
Davide Pesaventobde084f2022-04-17 00:21:35 -040078} // namespace ndn::nac::tests
Davide Pesaventoba3f6892020-12-08 22:18:35 -050079
80#endif // NAC_TESTS_KEY_CHAIN_FIXTURE_HPP