blob: 8fe7c597f0cc7535bb64630326a84f0080539faf [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 Pesavento51cf75c2020-03-11 22:21:13 -04003 * Copyright (c) 2014-2020, 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
Junxiao Shid23de8b2016-07-23 20:05:42 +000028#include <ndn-cxx/security/signature-sha256-with-rsa.hpp>
29
30namespace nfd {
31namespace tests {
32
Junxiao Shid23de8b2016-07-23 20:05:42 +000033shared_ptr<Interest>
Junxiao Shi9d727852019-05-14 13:44:22 -060034makeInterest(const Name& name, bool canBePrefix, optional<time::milliseconds> lifetime,
Davide Pesavento51cf75c2020-03-11 22:21:13 -040035 optional<Interest::Nonce> nonce)
Junxiao Shid23de8b2016-07-23 20:05:42 +000036{
37 auto interest = make_shared<Interest>(name);
Junxiao Shi9d727852019-05-14 13:44:22 -060038 interest->setCanBePrefix(canBePrefix);
39 if (lifetime) {
40 interest->setInterestLifetime(*lifetime);
41 }
Davide Pesavento51cf75c2020-03-11 22:21:13 -040042 interest->setNonce(nonce);
Junxiao Shid23de8b2016-07-23 20:05:42 +000043 return interest;
44}
45
46shared_ptr<Data>
47makeData(const Name& name)
48{
49 auto data = make_shared<Data>(name);
50 return signData(data);
51}
52
53Data&
54signData(Data& data)
55{
56 ndn::SignatureSha256WithRsa fakeSignature;
57 fakeSignature.setValue(ndn::encoding::makeEmptyBlock(tlv::SignatureValue));
58 data.setSignature(fakeSignature);
59 data.wireEncode();
Junxiao Shid23de8b2016-07-23 20:05:42 +000060 return data;
61}
62
Junxiao Shid23de8b2016-07-23 20:05:42 +000063lp::Nack
Junxiao Shi99540072017-01-27 19:57:33 +000064makeNack(Interest interest, lp::NackReason reason)
65{
66 lp::Nack nack(std::move(interest));
67 nack.setReason(reason);
68 return nack;
69}
70
Junxiao Shid47cd632018-09-11 03:10:00 +000071ndn::PrefixAnnouncement
72makePrefixAnn(const Name& announcedName, time::milliseconds expiration,
73 optional<ndn::security::ValidityPeriod> validity)
74{
75 ndn::PrefixAnnouncement pa;
76 pa.setAnnouncedName(announcedName);
77 pa.setExpiration(expiration);
78 pa.setValidityPeriod(validity);
79 return pa;
80}
81
82ndn::PrefixAnnouncement
83makePrefixAnn(const Name& announcedName, time::milliseconds expiration,
84 std::pair<time::seconds, time::seconds> validityFromNow)
85{
86 auto now = time::system_clock::now();
87 return makePrefixAnn(announcedName, expiration,
88 ndn::security::ValidityPeriod(now + validityFromNow.first, now + validityFromNow.second));
89}
90
91ndn::PrefixAnnouncement
92signPrefixAnn(ndn::PrefixAnnouncement&& pa, ndn::KeyChain& keyChain,
93 const ndn::security::SigningInfo& si, optional<uint64_t> version)
94{
95 pa.toData(keyChain, si, version);
96 return std::move(pa);
97}
98
Junxiao Shid23de8b2016-07-23 20:05:42 +000099} // namespace tests
100} // namespace nfd