rule.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2023 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_CXX_SECURITY_VALIDATOR_CONFIG_RULE_HPP
23 #define NDN_CXX_SECURITY_VALIDATOR_CONFIG_RULE_HPP
24 
27 
28 namespace ndn::security {
29 
30 class ValidationState;
31 
32 namespace validator_config {
33 
34 class Rule : noncopyable
35 {
36 public:
37  Rule(const std::string& id, uint32_t pktType);
38 
39  const std::string&
40  getId() const
41  {
42  return m_id;
43  }
44 
45  uint32_t
46  getPktType() const
47  {
48  return m_pktType;
49  }
50 
51  void
52  addFilter(unique_ptr<Filter> filter);
53 
54  void
55  addChecker(unique_ptr<Checker> checker);
56 
70  bool
71  match(uint32_t pktType, const Name& pktName, const shared_ptr<ValidationState>& state) const;
72 
88  bool
89  check(uint32_t pktType, tlv::SignatureTypeValue sigType, const Name& pktName, const Name& klName,
90  const shared_ptr<ValidationState>& state) const;
91 
92 public:
100  static unique_ptr<Rule>
101  create(const ConfigSection& configSection, const std::string& configFilename);
102 
104  std::string m_id;
105  uint32_t m_pktType;
106  std::vector<unique_ptr<Filter>> m_filters;
107  std::vector<unique_ptr<Checker>> m_checkers;
108 };
109 
110 } // namespace validator_config
111 } // namespace ndn::security
112 
113 #endif // NDN_CXX_SECURITY_VALIDATOR_CONFIG_RULE_HPP
Represents an absolute name.
Definition: name.hpp:45
void addFilter(unique_ptr< Filter > filter)
Definition: rule.cpp:39
bool check(uint32_t pktType, tlv::SignatureTypeValue sigType, const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) const
Check if packet satisfies rule's condition.
Definition: rule.cpp:74
static unique_ptr< Rule > create(const ConfigSection &configSection, const std::string &configFilename)
Create a rule from configuration section.
Definition: rule.cpp:104
Rule(const std::string &id, uint32_t pktType)
Definition: rule.cpp:32
void addChecker(unique_ptr< Checker > checker)
Definition: rule.cpp:45
bool match(uint32_t pktType, const Name &pktName, const shared_ptr< ValidationState > &state) const
Check if the packet name matches rule's filter.
Definition: rule.cpp:51
const std::string & getId() const
Definition: rule.hpp:40
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:49
boost::property_tree::ptree ConfigSection
Definition: common.hpp:33
Contains the ndn-cxx security framework.
SignatureTypeValue
SignatureType values.
Definition: tlv.hpp:127