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