blob: 007022fee0fd6552136a600f8f0c88fff7bfc5d1 [file] [log] [blame]
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoc2649492020-12-22 21:43:35 -05002/*
Davide Pesaventobde084f2022-04-17 00:21:35 -04003 * Copyright (c) 2014-2022, Regents of the University of California
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -04004 *
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 Afanasyev2b57aeb2018-06-15 18:32:28 -040025#include <iostream>
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040026
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040027#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 Pesaventoc2649492020-12-22 21:43:35 -050032#include <ndn-cxx/util/exception.hpp>
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040033#include <ndn-cxx/util/io.hpp>
34
Davide Pesaventobde084f2022-04-17 00:21:35 -040035namespace ndn::nac {
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040036
37int
38nac_dump_kek(int argc, char** argv);
39
40int
41nac_add_member(int argc, char** argv);
42
Alexander Afanasyev5181d892020-06-06 18:05:47 -040043inline Certificate
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040044loadCertificate(const std::string& fileName)
45{
Davide Pesaventod6e569f2021-10-25 20:35:04 -040046 try {
47 if (fileName == "-") {
48 return io::loadTlv<Certificate>(std::cin, io::BASE64);
49 }
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040050
Davide Pesaventod6e569f2021-10-25 20:35:04 -040051 std::ifstream file(fileName);
52 if (!file) {
53 NDN_THROW(std::runtime_error("Cannot open '" + fileName + "'"));
54 }
55 return io::loadTlv<Certificate>(file, io::BASE64);
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040056 }
Davide Pesaventod6e569f2021-10-25 20:35:04 -040057 catch (const io::Error& e) {
58 NDN_THROW_NESTED(std::runtime_error("Cannot load certificate from '" + fileName +
59 "': malformed TLV or not in base64 format (" + e.what() + ")"));
60 }
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040061}
62
Davide Pesaventobde084f2022-04-17 00:21:35 -040063} // namespace ndn::nac
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040064
65#endif // NAC_TOOLS_NDN_NAC_NDN_NAC_HPP