Eric Newberry | dbf14b1 | 2016-12-27 12:18:53 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Generates a predefined link object and outputs it to a file |
| 3 | * |
| 4 | * Author: Eric Newberry <enewberry@email.arizona.edu> |
| 5 | */ |
| 6 | |
| 7 | #include <ndn-cxx/link.hpp> |
| 8 | #include <ndn-cxx/security/key-chain.hpp> |
| 9 | #include <ndn-cxx/util/io.hpp> |
| 10 | |
| 11 | #include <iostream> |
| 12 | |
| 13 | int |
| 14 | main(int argc, char* argv[]) |
| 15 | { |
| 16 | if (argc < 5 || argc % 2 != 1) { |
| 17 | std::cout << "Usage: " << argv[0] << " [outfile] [name] [pref-1] [delegation-1] ... [pref-n] [delegation-n]" << std::endl; |
| 18 | return -1; |
| 19 | } |
| 20 | |
| 21 | // Create initial link object |
| 22 | ndn::Link link(argv[2]); |
| 23 | |
| 24 | // Load delegations into object |
| 25 | for (int i = 0; i < (argc - 3) / 2; i++) { |
| 26 | link.addDelegation(std::stoi(argv[2 * i + 3]), argv[2 * i + 4]); |
| 27 | } |
| 28 | |
| 29 | // Sign and save object |
| 30 | ndn::KeyChain keyChain; |
| 31 | keyChain.sign(link); |
| 32 | link.wireEncode(); |
| 33 | ndn::io::save(link, argv[1]); |
| 34 | return 0; |
| 35 | } |