Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2016, Regents of the University of California, |
| 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 NDNS (Named Data Networking Domain Name Service) and is |
| 12 | * based on the code written as part of NFD (Named Data Networking Daemon). |
| 13 | * See AUTHORS.md for complete list of NDNS authors and contributors. |
| 14 | * |
| 15 | * NDNS is free software: you can redistribute it and/or modify it under the terms |
| 16 | * of the GNU General Public License as published by the Free Software Foundation, |
| 17 | * either version 3 of the License, or (at your option) any later version. |
| 18 | * |
| 19 | * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 20 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 21 | * PURPOSE. See the GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License along with |
| 24 | * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 25 | */ |
| 26 | |
| 27 | #include "test-common.hpp" |
| 28 | |
| 29 | #include <ndn-cxx/security/signature-sha256-with-rsa.hpp> |
| 30 | |
| 31 | namespace ndn { |
| 32 | namespace ndns { |
| 33 | namespace tests { |
| 34 | |
| 35 | shared_ptr<Interest> |
| 36 | makeInterest(const Name& name, uint32_t nonce) |
| 37 | { |
| 38 | auto interest = make_shared<Interest>(name); |
| 39 | if (nonce != 0) { |
| 40 | interest->setNonce(nonce); |
| 41 | } |
| 42 | return interest; |
| 43 | } |
| 44 | |
| 45 | shared_ptr<Data> |
| 46 | makeData(const Name& name) |
| 47 | { |
| 48 | auto data = make_shared<Data>(name); |
| 49 | return signData(data); |
| 50 | } |
| 51 | |
| 52 | Data& |
| 53 | signData(Data& data) |
| 54 | { |
| 55 | ndn::SignatureSha256WithRsa fakeSignature; |
| 56 | fakeSignature.setValue(ndn::encoding::makeEmptyBlock(tlv::SignatureValue)); |
| 57 | data.setSignature(fakeSignature); |
| 58 | data.wireEncode(); |
| 59 | |
| 60 | return data; |
| 61 | } |
| 62 | |
| 63 | shared_ptr<Link> |
| 64 | makeLink(const Name& name, std::initializer_list<std::pair<uint32_t, Name>> delegations) |
| 65 | { |
| 66 | auto link = make_shared<Link>(name, delegations); |
| 67 | signData(link); |
| 68 | return link; |
| 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 | lp::Nack nack(std::move(interest)); |
| 77 | nack.setReason(reason); |
| 78 | return nack; |
| 79 | } |
| 80 | |
| 81 | } // namespace tests |
| 82 | } // namespace ndns |
| 83 | } // namespace ndn |