Skip to content

Commit

Permalink
Slim down ndncert-common.hpp
Browse files Browse the repository at this point in the history
Change-Id: Ifba0966d3787c5cbf770963b82cba054ee1fe791
  • Loading branch information
Pesa committed Feb 25, 2024
1 parent 842f1f7 commit 9510c91
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 55 deletions.
3 changes: 2 additions & 1 deletion src/ca-module.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2023, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand Down Expand Up @@ -32,6 +32,7 @@
#include <ndn-cxx/security/signing-helpers.hpp>
#include <ndn-cxx/security/verification-helpers.hpp>
#include <ndn-cxx/util/io.hpp>
#include <ndn-cxx/util/logger.hpp>
#include <ndn-cxx/util/random.hpp>
#include <ndn-cxx/util/string-helper.hpp>

Expand Down
5 changes: 4 additions & 1 deletion src/challenge/challenge-email.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2022, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -19,6 +19,9 @@
*/

#include "challenge-email.hpp"

#include <ndn-cxx/util/logger.hpp>

#include <regex>
#include <boost/process.hpp>

Expand Down
3 changes: 2 additions & 1 deletion src/challenge/challenge-module.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2022, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -24,6 +24,7 @@
#include "detail/ca-request-state.hpp"

#include <map>
#include <tuple>

namespace ndncert {

Expand Down
3 changes: 2 additions & 1 deletion src/challenge/challenge-pin.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2022, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -20,6 +20,7 @@

#include "challenge-pin.hpp"

#include <ndn-cxx/util/logger.hpp>
#include <ndn-cxx/util/random.hpp>

namespace ndncert {
Expand Down
3 changes: 2 additions & 1 deletion src/challenge/challenge-possession.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2023, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -23,6 +23,7 @@
#include <ndn-cxx/security/transform/public-key.hpp>
#include <ndn-cxx/security/verification-helpers.hpp>
#include <ndn-cxx/util/io.hpp>
#include <ndn-cxx/util/logger.hpp>
#include <ndn-cxx/util/random.hpp>

#include <boost/property_tree/json_parser.hpp>
Expand Down
1 change: 1 addition & 0 deletions src/detail/ca-profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "detail/ca-profile.hpp"
#include "challenge/challenge-module.hpp"

#include <boost/algorithm/string/case_conv.hpp>
#include <ndn-cxx/util/io.hpp>

namespace ndncert {
Expand Down
8 changes: 5 additions & 3 deletions src/detail/ca-profile.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2022, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -23,6 +23,8 @@

#include "detail/ndncert-common.hpp"

#include <optional>

namespace ndncert {

// used in parsing CA configuration file and Client CA profile storage file
Expand All @@ -44,8 +46,8 @@ class CaProfile
{
public:
/**
* Parse the configuration json.
* @param configJson the configuration json to parse
* Parse the configuration JSON.
* @param json the configuration json to parse
* @return the CaProfile according to this json
*/
static CaProfile
Expand Down
3 changes: 2 additions & 1 deletion src/detail/ca-request-state.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2023, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -24,6 +24,7 @@
#include "detail/ndncert-common.hpp"

#include <array>
#include <optional>

namespace ndncert {

Expand Down
6 changes: 4 additions & 2 deletions src/detail/error-encoder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2023, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -20,10 +20,12 @@

#include "detail/error-encoder.hpp"

NDN_LOG_INIT(ndncert.encode.error);
#include <ndn-cxx/util/logger.hpp>

namespace ndncert::errortlv {

NDN_LOG_INIT(ndncert.encode.error);

Block
encodeDataContent(ErrorCode errorCode, const std::string& description)
{
Expand Down
6 changes: 4 additions & 2 deletions src/detail/error-encoder.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2022, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -21,7 +21,9 @@
#ifndef NDNCERT_DETAIL_ERROR_ENCODER_HPP
#define NDNCERT_DETAIL_ERROR_ENCODER_HPP

#include "detail/ca-profile.hpp"
#include "detail/ndncert-common.hpp"

#include <tuple>

namespace ndncert::errortlv {

Expand Down
6 changes: 4 additions & 2 deletions src/detail/info-encoder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2022, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -20,10 +20,12 @@

#include "detail/info-encoder.hpp"

NDN_LOG_INIT(ndncert.encode.info);
#include <ndn-cxx/util/logger.hpp>

namespace ndncert::infotlv {

NDN_LOG_INIT(ndncert.encode.info);

Block
encodeDataContent(const CaProfile& caConfig, const Certificate& certificate)
{
Expand Down
38 changes: 19 additions & 19 deletions src/detail/ndncert-common.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2021, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -20,38 +20,38 @@

#include "detail/ndncert-common.hpp"

#include <ndn-cxx/util/backports.hpp>

namespace ndncert {

std::ostream&
operator<<(std::ostream& out, ErrorCode code)
{
switch (code) {
case ErrorCode::NO_ERROR: out << "NO_ERROR"; break;
case ErrorCode::BAD_INTEREST_FORMAT: out << "BAD_INTEREST_FORMAT"; break;
case ErrorCode::BAD_PARAMETER_FORMAT: out << "BAD_PARAMETER_FORMAT"; break;
case ErrorCode::BAD_SIGNATURE: out << "BAD_SIGNATURE"; break;
case ErrorCode::INVALID_PARAMETER: out << "INVALID_PARAMETER"; break;
case ErrorCode::NAME_NOT_ALLOWED: out << "NAME_NOT_ALLOWED"; break;
case ErrorCode::BAD_VALIDITY_PERIOD: out << "BAD_VALIDITY_PERIOD"; break;
case ErrorCode::OUT_OF_TRIES: out << "OUT_OF_TRIES"; break;
case ErrorCode::OUT_OF_TIME: out << "OUT_OF_TIME"; break;
case ErrorCode::NO_AVAILABLE_NAMES: out << "NO_AVAILABLE_NAMES"; break;
default: out << "UNKNOWN_ERROR"; break;
case ErrorCode::NO_ERROR: return out << "NO_ERROR";
case ErrorCode::BAD_INTEREST_FORMAT: return out << "BAD_INTEREST_FORMAT";
case ErrorCode::BAD_PARAMETER_FORMAT: return out << "BAD_PARAMETER_FORMAT";
case ErrorCode::BAD_SIGNATURE: return out << "BAD_SIGNATURE";
case ErrorCode::INVALID_PARAMETER: return out << "INVALID_PARAMETER";
case ErrorCode::NAME_NOT_ALLOWED: return out << "NAME_NOT_ALLOWED";
case ErrorCode::BAD_VALIDITY_PERIOD: return out << "BAD_VALIDITY_PERIOD";
case ErrorCode::OUT_OF_TRIES: return out << "OUT_OF_TRIES";
case ErrorCode::OUT_OF_TIME: return out << "OUT_OF_TIME";
case ErrorCode::NO_AVAILABLE_NAMES: return out << "NO_AVAILABLE_NAMES";
}
return out;
return out << "<Unknown Error " << ndn::to_underlying(code) << ">";
}

std::ostream&
operator<<(std::ostream& out, RequestType type)
{
switch (type) {
case RequestType::NEW: out << "New"; break;
case RequestType::RENEW: out << "Renew"; break;
case RequestType::REVOKE: out << "Revoke"; break;
case RequestType::NOTINITIALIZED: out << "Not Initialized"; break;
default: out << "UNKNOWN_REQUEST_TYPE"; break;
case RequestType::NOTINITIALIZED: return out << "Not Initialized";
case RequestType::NEW: return out << "New";
case RequestType::RENEW: return out << "Renew";
case RequestType::REVOKE: return out << "Revoke";
}
return out;
return out << "<Unknown Request Type " << ndn::to_underlying(type) << ">";
}

} // namespace ndncert
17 changes: 7 additions & 10 deletions src/detail/ndncert-common.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2022, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -23,7 +23,7 @@

#include "detail/ndncert-config.hpp"

#ifdef NDNCERT_HAVE_TESTS
#ifdef NDNCERT_WITH_TESTS
#define NDNCERT_VIRTUAL_WITH_TESTS virtual
#define NDNCERT_PUBLIC_WITH_TESTS_ELSE_PROTECTED public
#define NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE public
Expand All @@ -38,9 +38,8 @@
#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <tuple>
#include <vector>

#include <ndn-cxx/data.hpp>
Expand All @@ -50,12 +49,10 @@
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/security/certificate.hpp>
#include <ndn-cxx/util/exception.hpp>
#include <ndn-cxx/util/logger.hpp>
#include <ndn-cxx/util/time.hpp>

#include <boost/algorithm/string.hpp>
#include <boost/assert.hpp>
#include <boost/noncopyable.hpp>
#include <boost/core/noncopyable.hpp>
#include <boost/property_tree/ptree.hpp>

namespace ndncert {
Expand Down Expand Up @@ -99,7 +96,7 @@ enum : uint32_t {
ErrorInfo = 173,
AuthenticationTag = 175,
CertToRevoke = 177,
ProbeRedirect = 179
ProbeRedirect = 179,
};

} // namespace tlv
Expand All @@ -117,7 +114,7 @@ enum class ErrorCode : uint64_t {
BAD_VALIDITY_PERIOD = 6,
OUT_OF_TRIES = 7,
OUT_OF_TIME = 8,
NO_AVAILABLE_NAMES = 9
NO_AVAILABLE_NAMES = 9,
};

// Convert error code to string
Expand All @@ -129,7 +126,7 @@ enum class RequestType : uint64_t {
NOTINITIALIZED = 0,
NEW = 1,
RENEW = 2,
REVOKE = 3
REVOKE = 3,
};

// Convert request type to string
Expand Down
4 changes: 3 additions & 1 deletion src/detail/probe-encoder.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2022, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -23,6 +23,8 @@

#include "detail/ndncert-common.hpp"

#include <optional>

namespace ndncert::probetlv {

// For Client use
Expand Down
4 changes: 1 addition & 3 deletions src/redirection/redirection-email.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2022, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -20,8 +20,6 @@

#include "redirection-email.hpp"

#include <boost/algorithm/string.hpp>

namespace ndncert {

NDNCERT_REGISTER_REDIRECTION_POLICY(RedirectionEmail, "email");
Expand Down
7 changes: 4 additions & 3 deletions src/redirection/redirection-param.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2022, Regents of the University of California.
* Copyright (c) 2017-2024, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand All @@ -20,7 +20,8 @@

#include "redirection-param.hpp"

#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>

namespace ndncert {

Expand All @@ -33,7 +34,7 @@ RedirectionParam::RedirectionParam(const std::string& format)
}

std::vector<std::string> strs;
boost::split(strs,format,boost::is_any_of("&"));
boost::split(strs, format, boost::is_any_of("&"));
for (const auto& s : strs) {
auto i = s.find('=');
if (i == std::string::npos) {
Expand Down
Loading

0 comments on commit 9510c91

Please sign in to comment.