Yingdi Yu | e6bfab2 | 2014-02-06 16:01:19 -0800 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Yingdi Yu |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 9 | */ |
| 10 | |
| 11 | #include <iostream> |
| 12 | #include <fstream> |
| 13 | |
| 14 | #include <boost/program_options/options_description.hpp> |
| 15 | #include <boost/program_options/variables_map.hpp> |
| 16 | #include <boost/program_options/parsers.hpp> |
| 17 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 18 | #include <cryptopp/base64.h> |
| 19 | |
| 20 | #include "security/key-chain.hpp" |
| 21 | |
| 22 | using namespace ndn; |
| 23 | namespace po = boost::program_options; |
| 24 | |
| 25 | int main(int argc, char** argv) |
| 26 | { |
| 27 | std::string certFileName; |
| 28 | bool setDefaultId = true; |
| 29 | bool setDefaultKey = false; |
| 30 | bool setDefaultCert = false; |
| 31 | std::string name; |
| 32 | |
| 33 | po::options_description desc("General Usage\n ndn-set-default [-h] [-K|C] name\nGeneral options"); |
| 34 | desc.add_options() |
| 35 | ("help,h", "produce help message") |
| 36 | ("default_key,K", "set default key of the identity") |
| 37 | ("default_cert,C", "set default certificate of the key") |
| 38 | ("name,n", po::value<std::string>(&name), "the name to set") |
| 39 | ; |
| 40 | |
| 41 | po::positional_options_description p; |
| 42 | p.add("name", 1); |
| 43 | po::variables_map vm; |
| 44 | po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm); |
| 45 | |
| 46 | po::notify(vm); |
| 47 | |
| 48 | if (vm.count("help")) |
| 49 | { |
| 50 | std::cerr << desc << std::endl; |
| 51 | return 1; |
| 52 | } |
| 53 | |
| 54 | KeyChain keyChain; |
| 55 | |
| 56 | if (vm.count("default_key")) |
| 57 | { |
| 58 | setDefaultKey = true; |
| 59 | setDefaultId = false; |
| 60 | } |
| 61 | else if(vm.count("default_cert")) |
| 62 | { |
| 63 | setDefaultCert = true; |
| 64 | setDefaultId = false; |
| 65 | } |
| 66 | |
| 67 | if (setDefaultId) |
| 68 | { |
| 69 | Name idName(name); |
| 70 | keyChain.setDefaultIdentity(idName); |
| 71 | return 0; |
| 72 | } |
| 73 | if (setDefaultKey) |
| 74 | { |
| 75 | Name keyName(name); |
| 76 | keyChain.setDefaultKeyNameForIdentity(keyName); |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | if (setDefaultCert) |
| 81 | { |
| 82 | keyChain.setDefaultCertificateNameForKey(name); |
| 83 | return 0; |
| 84 | } |
| 85 | } |