Junxiao Shi | 85d9083 | 2016-08-04 03:19:46 +0000 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #include "make-interest-data.hpp" |
| 23 | #include "security/signature-sha256-with-rsa.hpp" |
| 24 | |
| 25 | namespace ndn { |
| 26 | namespace tests { |
| 27 | |
| 28 | shared_ptr<Interest> |
| 29 | makeInterest(const Name& name, uint32_t nonce) |
| 30 | { |
| 31 | auto interest = make_shared<Interest>(name); |
| 32 | if (nonce != 0) { |
| 33 | interest->setNonce(nonce); |
| 34 | } |
| 35 | return interest; |
| 36 | } |
| 37 | |
| 38 | shared_ptr<Data> |
| 39 | makeData(const Name& name) |
| 40 | { |
| 41 | auto data = make_shared<Data>(name); |
| 42 | return signData(data); |
| 43 | } |
| 44 | |
| 45 | Data& |
| 46 | signData(Data& data) |
| 47 | { |
| 48 | ndn::SignatureSha256WithRsa fakeSignature; |
| 49 | fakeSignature.setValue(ndn::encoding::makeEmptyBlock(tlv::SignatureValue)); |
| 50 | data.setSignature(fakeSignature); |
| 51 | data.wireEncode(); |
| 52 | return data; |
| 53 | } |
| 54 | |
| 55 | shared_ptr<Link> |
| 56 | makeLink(const Name& name, std::initializer_list<std::pair<uint32_t, Name>> delegations) |
| 57 | { |
| 58 | auto link = make_shared<Link>(name, delegations); |
| 59 | signData(link); |
| 60 | return link; |
| 61 | } |
| 62 | |
| 63 | lp::Nack |
| 64 | makeNack(const Interest& interest, lp::NackReason reason) |
| 65 | { |
| 66 | lp::Nack nack(interest); |
| 67 | nack.setReason(reason); |
| 68 | return nack; |
| 69 | } |
| 70 | |
| 71 | lp::Nack |
| 72 | makeNack(const Name& name, uint32_t nonce, lp::NackReason reason) |
| 73 | { |
| 74 | Interest interest(name); |
| 75 | interest.setNonce(nonce); |
| 76 | return makeNack(interest, reason); |
| 77 | } |
| 78 | |
| 79 | } // namespace tests |
| 80 | } // namespace ndn |