blob: 236007eb99c352f8d02149ae74493dc1458d5ae0 [file] [log] [blame]
Junxiao Shid23de8b2016-07-23 20:05:42 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shifc2e13d2017-07-25 02:08:48 +00002/*
Davide Pesavento3dade002019-03-19 11:29:56 -06003 * Copyright (c) 2014-2019, Regents of the University of California,
Junxiao Shid23de8b2016-07-23 20:05:42 +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.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * 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.
17 *
18 * 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.
21 *
22 * 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/>.
24 */
25
Davide Pesaventob7703ad2019-03-23 21:12:56 -040026#include "tests/test-common.hpp"
Davide Pesavento3dade002019-03-19 11:29:56 -060027#include "daemon/global.hpp"
28
Junxiao Shid23de8b2016-07-23 20:05:42 +000029#include <ndn-cxx/security/signature-sha256-with-rsa.hpp>
30
31namespace nfd {
32namespace tests {
33
34BaseFixture::BaseFixture()
35 : g_io(getGlobalIoService())
36{
37}
38
39BaseFixture::~BaseFixture()
40{
41 resetGlobalIoService();
42}
43
Junxiao Shid23de8b2016-07-23 20:05:42 +000044shared_ptr<Interest>
45makeInterest(const Name& name, uint32_t nonce)
46{
47 auto interest = make_shared<Interest>(name);
48 if (nonce != 0) {
49 interest->setNonce(nonce);
50 }
51 return interest;
52}
53
54shared_ptr<Data>
55makeData(const Name& name)
56{
57 auto data = make_shared<Data>(name);
58 return signData(data);
59}
60
61Data&
62signData(Data& data)
63{
64 ndn::SignatureSha256WithRsa fakeSignature;
65 fakeSignature.setValue(ndn::encoding::makeEmptyBlock(tlv::SignatureValue));
66 data.setSignature(fakeSignature);
67 data.wireEncode();
68
69 return data;
70}
71
Junxiao Shid23de8b2016-07-23 20:05:42 +000072lp::Nack
Junxiao Shi99540072017-01-27 19:57:33 +000073makeNack(Interest interest, lp::NackReason reason)
74{
75 lp::Nack nack(std::move(interest));
76 nack.setReason(reason);
77 return nack;
78}
79
80lp::Nack
Junxiao Shid23de8b2016-07-23 20:05:42 +000081makeNack(const Name& name, uint32_t nonce, lp::NackReason reason)
82{
83 Interest interest(name);
84 interest.setNonce(nonce);
Junxiao Shi99540072017-01-27 19:57:33 +000085 return makeNack(std::move(interest), reason);
Junxiao Shid23de8b2016-07-23 20:05:42 +000086}
87
Junxiao Shid47cd632018-09-11 03:10:00 +000088ndn::PrefixAnnouncement
89makePrefixAnn(const Name& announcedName, time::milliseconds expiration,
90 optional<ndn::security::ValidityPeriod> validity)
91{
92 ndn::PrefixAnnouncement pa;
93 pa.setAnnouncedName(announcedName);
94 pa.setExpiration(expiration);
95 pa.setValidityPeriod(validity);
96 return pa;
97}
98
99ndn::PrefixAnnouncement
100makePrefixAnn(const Name& announcedName, time::milliseconds expiration,
101 std::pair<time::seconds, time::seconds> validityFromNow)
102{
103 auto now = time::system_clock::now();
104 return makePrefixAnn(announcedName, expiration,
105 ndn::security::ValidityPeriod(now + validityFromNow.first, now + validityFromNow.second));
106}
107
108ndn::PrefixAnnouncement
109signPrefixAnn(ndn::PrefixAnnouncement&& pa, ndn::KeyChain& keyChain,
110 const ndn::security::SigningInfo& si, optional<uint64_t> version)
111{
112 pa.toData(keyChain, si, version);
113 return std::move(pa);
114}
115
Junxiao Shid23de8b2016-07-23 20:05:42 +0000116} // namespace tests
117} // namespace nfd