Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | c264949 | 2020-12-22 21:43:35 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | d6e569f | 2021-10-25 20:35:04 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2021, Regents of the University of California |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 4 | * |
| 5 | * NAC library is free software: you can redistribute it and/or modify it under the |
| 6 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 7 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * NAC library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 11 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 12 | * |
| 13 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 14 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 15 | * <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * See AUTHORS.md for complete list of NAC library authors and contributors. |
| 18 | */ |
| 19 | |
| 20 | #ifndef NAC_TOOLS_NDN_NAC_NDN_NAC_HPP |
| 21 | #define NAC_TOOLS_NDN_NAC_NDN_NAC_HPP |
| 22 | |
| 23 | #include "common.hpp" |
| 24 | |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 25 | #include <iostream> |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 26 | |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 27 | #include <boost/program_options/options_description.hpp> |
| 28 | #include <boost/program_options/parsers.hpp> |
| 29 | #include <boost/program_options/variables_map.hpp> |
| 30 | |
| 31 | #include <ndn-cxx/util/dummy-client-face.hpp> |
Davide Pesavento | c264949 | 2020-12-22 21:43:35 -0500 | [diff] [blame] | 32 | #include <ndn-cxx/util/exception.hpp> |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 33 | #include <ndn-cxx/util/io.hpp> |
| 34 | |
| 35 | namespace ndn { |
| 36 | namespace nac { |
| 37 | |
| 38 | int |
| 39 | nac_dump_kek(int argc, char** argv); |
| 40 | |
| 41 | int |
| 42 | nac_add_member(int argc, char** argv); |
| 43 | |
Alexander Afanasyev | 5181d89 | 2020-06-06 18:05:47 -0400 | [diff] [blame] | 44 | inline Certificate |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 45 | loadCertificate(const std::string& fileName) |
| 46 | { |
Davide Pesavento | d6e569f | 2021-10-25 20:35:04 -0400 | [diff] [blame] | 47 | try { |
| 48 | if (fileName == "-") { |
| 49 | return io::loadTlv<Certificate>(std::cin, io::BASE64); |
| 50 | } |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 51 | |
Davide Pesavento | d6e569f | 2021-10-25 20:35:04 -0400 | [diff] [blame] | 52 | std::ifstream file(fileName); |
| 53 | if (!file) { |
| 54 | NDN_THROW(std::runtime_error("Cannot open '" + fileName + "'")); |
| 55 | } |
| 56 | return io::loadTlv<Certificate>(file, io::BASE64); |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 57 | } |
Davide Pesavento | d6e569f | 2021-10-25 20:35:04 -0400 | [diff] [blame] | 58 | catch (const io::Error& e) { |
| 59 | NDN_THROW_NESTED(std::runtime_error("Cannot load certificate from '" + fileName + |
| 60 | "': malformed TLV or not in base64 format (" + e.what() + ")")); |
| 61 | } |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | } // namespace nac |
| 65 | } // namespace ndn |
| 66 | |
| 67 | #endif // NAC_TOOLS_NDN_NAC_NDN_NAC_HPP |