blob: 18ba4fca0bfd7daa7bf0145e012cc13c61ac893a [file] [log] [blame]
Yanbiao Lic17de832014-11-21 17:51:45 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi5ba7dfc2018-09-26 14:24:05 +00002/*
Davide Pesavento1d12d2f2019-03-22 12:44:14 -04003 * Copyright (c) 2014-2019, Regents of the University of California,
Junxiao Shi38f4ce92016-08-04 10:01:52 +00004 * 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
Davide Pesavento1d12d2f2019-03-22 12:44:14 -040026#ifndef NFD_TESTS_KEY_CHAIN_FIXTURE_HPP
27#define NFD_TESTS_KEY_CHAIN_FIXTURE_HPP
Yukai Tu0a49d342015-09-13 12:54:22 +080028
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040029#include "core/common.hpp"
Davide Pesavento1d12d2f2019-03-22 12:44:14 -040030
Yanbiao Lic17de832014-11-21 17:51:45 -080031#include <ndn-cxx/security/key-chain.hpp>
Yanbiao Lic17de832014-11-21 17:51:45 -080032
33namespace nfd {
34namespace tests {
35
Davide Pesavento1d12d2f2019-03-22 12:44:14 -040036/** \brief A fixture providing an in-memory KeyChain.
Yanbiao Lic17de832014-11-21 17:51:45 -080037 */
Davide Pesavento1d12d2f2019-03-22 12:44:14 -040038class KeyChainFixture
Yanbiao Lic17de832014-11-21 17:51:45 -080039{
40public:
Junxiao Shid7631272016-08-17 04:16:31 +000041 /** \brief add identity
42 * \return whether successful
43 */
Yanbiao Lic17de832014-11-21 17:51:45 -080044 bool
Junxiao Shid7631272016-08-17 04:16:31 +000045 addIdentity(const Name& identity,
Junxiao Shi16a3adf2017-05-26 17:38:51 +000046 const ndn::KeyParams& params = ndn::KeyChain::getDefaultKeyParams());
Yanbiao Lic17de832014-11-21 17:51:45 -080047
Junxiao Shid7631272016-08-17 04:16:31 +000048 /** \brief save identity certificate to a file
49 * \param identity identity name
Davide Pesavento1d12d2f2019-03-22 12:44:14 -040050 * \param filename file name, must be writable
51 * \param allowAdd if true, add new identity when necessary
Junxiao Shid7631272016-08-17 04:16:31 +000052 * \return whether successful
53 */
54 bool
Davide Pesavento1d12d2f2019-03-22 12:44:14 -040055 saveIdentityCertificate(const Name& identity, const std::string& filename, bool allowAdd = false);
Junxiao Shid7631272016-08-17 04:16:31 +000056
Junxiao Shi5ba7dfc2018-09-26 14:24:05 +000057 /** \brief retrieve identity certificate as base64 string
58 * \param identity identity name
Davide Pesavento1d12d2f2019-03-22 12:44:14 -040059 * \param allowAdd if true, add new identity when necessary
60 * \throw std::runtime_error identity does not exist and \p allowAdd is false
Junxiao Shi5ba7dfc2018-09-26 14:24:05 +000061 */
62 std::string
Davide Pesavento1d12d2f2019-03-22 12:44:14 -040063 getIdentityCertificateBase64(const Name& identity, bool allowAdd = false);
64
65protected:
66 KeyChainFixture();
67
68 /** \brief deletes saved certificate files
69 */
70 ~KeyChainFixture();
Junxiao Shi5ba7dfc2018-09-26 14:24:05 +000071
Yanbiao Lic17de832014-11-21 17:51:45 -080072protected:
73 ndn::KeyChain m_keyChain;
Junxiao Shid7631272016-08-17 04:16:31 +000074
75private:
Junxiao Shid7631272016-08-17 04:16:31 +000076 std::vector<std::string> m_certFiles;
Yanbiao Lic17de832014-11-21 17:51:45 -080077};
78
79} // namespace tests
80} // namespace nfd
Yukai Tu0a49d342015-09-13 12:54:22 +080081
Davide Pesavento1d12d2f2019-03-22 12:44:14 -040082#endif // NFD_TESTS_KEY_CHAIN_FIXTURE_HPP