blob: 9bc824a75c4cebe623890b44f16126484021b8d5 [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
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,
35 optional<uint32_t> 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 }
42 if (nonce) {
43 interest->setNonce(*nonce);
Junxiao Shid23de8b2016-07-23 20:05:42 +000044 }
45 return interest;
46}
47
48shared_ptr<Data>
49makeData(const Name& name)
50{
51 auto data = make_shared<Data>(name);
52 return signData(data);
53}
54
55Data&
56signData(Data& data)
57{
58 ndn::SignatureSha256WithRsa fakeSignature;
59 fakeSignature.setValue(ndn::encoding::makeEmptyBlock(tlv::SignatureValue));
60 data.setSignature(fakeSignature);
61 data.wireEncode();
62
63 return data;
64}
65
Junxiao Shid23de8b2016-07-23 20:05:42 +000066lp::Nack
Junxiao Shi99540072017-01-27 19:57:33 +000067makeNack(Interest interest, lp::NackReason reason)
68{
69 lp::Nack nack(std::move(interest));
70 nack.setReason(reason);
71 return nack;
72}
73
Junxiao Shid47cd632018-09-11 03:10:00 +000074ndn::PrefixAnnouncement
75makePrefixAnn(const Name& announcedName, time::milliseconds expiration,
76 optional<ndn::security::ValidityPeriod> validity)
77{
78 ndn::PrefixAnnouncement pa;
79 pa.setAnnouncedName(announcedName);
80 pa.setExpiration(expiration);
81 pa.setValidityPeriod(validity);
82 return pa;
83}
84
85ndn::PrefixAnnouncement
86makePrefixAnn(const Name& announcedName, time::milliseconds expiration,
87 std::pair<time::seconds, time::seconds> validityFromNow)
88{
89 auto now = time::system_clock::now();
90 return makePrefixAnn(announcedName, expiration,
91 ndn::security::ValidityPeriod(now + validityFromNow.first, now + validityFromNow.second));
92}
93
94ndn::PrefixAnnouncement
95signPrefixAnn(ndn::PrefixAnnouncement&& pa, ndn::KeyChain& keyChain,
96 const ndn::security::SigningInfo& si, optional<uint64_t> version)
97{
98 pa.toData(keyChain, si, version);
99 return std::move(pa);
100}
101
Junxiao Shid23de8b2016-07-23 20:05:42 +0000102} // namespace tests
103} // namespace nfd