Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | fc2e13d | 2017-07-25 02:08:48 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2019, Regents of the University of California, |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 4 | * 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 Pesavento | b7703ad | 2019-03-23 21:12:56 -0400 | [diff] [blame] | 26 | #include "tests/test-common.hpp" |
Davide Pesavento | 3dade00 | 2019-03-19 11:29:56 -0600 | [diff] [blame] | 27 | |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 28 | #include <ndn-cxx/security/signature-sha256-with-rsa.hpp> |
| 29 | |
| 30 | namespace nfd { |
| 31 | namespace tests { |
| 32 | |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 33 | shared_ptr<Interest> |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 34 | makeInterest(const Name& name, bool canBePrefix, optional<time::milliseconds> lifetime, |
| 35 | optional<uint32_t> nonce) |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 36 | { |
| 37 | auto interest = make_shared<Interest>(name); |
Junxiao Shi | 9d72785 | 2019-05-14 13:44:22 -0600 | [diff] [blame] | 38 | interest->setCanBePrefix(canBePrefix); |
| 39 | if (lifetime) { |
| 40 | interest->setInterestLifetime(*lifetime); |
| 41 | } |
| 42 | if (nonce) { |
| 43 | interest->setNonce(*nonce); |
Junxiao Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 44 | } |
| 45 | return interest; |
| 46 | } |
| 47 | |
| 48 | shared_ptr<Data> |
| 49 | makeData(const Name& name) |
| 50 | { |
| 51 | auto data = make_shared<Data>(name); |
| 52 | return signData(data); |
| 53 | } |
| 54 | |
| 55 | Data& |
| 56 | signData(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 Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 66 | lp::Nack |
Junxiao Shi | 9954007 | 2017-01-27 19:57:33 +0000 | [diff] [blame] | 67 | makeNack(Interest interest, lp::NackReason reason) |
| 68 | { |
| 69 | lp::Nack nack(std::move(interest)); |
| 70 | nack.setReason(reason); |
| 71 | return nack; |
| 72 | } |
| 73 | |
Junxiao Shi | d47cd63 | 2018-09-11 03:10:00 +0000 | [diff] [blame] | 74 | ndn::PrefixAnnouncement |
| 75 | makePrefixAnn(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 | |
| 85 | ndn::PrefixAnnouncement |
| 86 | makePrefixAnn(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 | |
| 94 | ndn::PrefixAnnouncement |
| 95 | signPrefixAnn(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 Shi | d23de8b | 2016-07-23 20:05:42 +0000 | [diff] [blame] | 102 | } // namespace tests |
| 103 | } // namespace nfd |