blob: 66d6d6a146fbbb83d400e41ebbbd99365d07731d [file] [log] [blame]
Alexander Afanasyeve5a19b82017-01-30 22:30:46 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013-2017 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_SECURITY_V2_VALIDATOR_CONFIG_RULE_HPP
23#define NDN_SECURITY_V2_VALIDATOR_CONFIG_RULE_HPP
24
25#include "filter.hpp"
26#include "checker.hpp"
27
28namespace ndn {
29namespace security {
30namespace v2 {
31
32class ValidationState;
33
34namespace validator_config {
35
36class Rule : noncopyable
37{
38public:
39 Rule(const std::string& id, uint32_t pktType);
40
41 const std::string&
42 getId() const
43 {
44 return m_id;
45 }
46
47 uint32_t
48 getPktType() const
49 {
50 return m_pktType;
51 }
52
53 void
54 addFilter(unique_ptr<Filter> filter);
55
56 void
57 addChecker(unique_ptr<Checker> checker);
58
59 /**
60 * @brief check if the packet name matches rule's filter
61 *
62 * If no filters were added, the rule matches everything.
63 *
64 * @param pktType tlv::Interest or tlv::Data
65 * @param pktName packet name, for signed Interests the last two components are not removed
66 * @retval true If at least one filter matches @p pktName
67 * @retval false If none of the filters match @p pktName
68 *
69 * @throw Error the supplied pktType doesn't match one for which the rule is designed
70 */
71 bool
72 match(uint32_t pktType, const Name& pktName) const;
73
74 /**
75 * @brief check if packet satisfies rule's condition
76 *
77 * @param pktType tlv::Interest or tlv::Data
78 * @param pktName packet name, for signed Interests the last two components are not removed
79 * @param klName KeyLocator name
80 * @param state Validation state
81 *
82 * @retval false packet violates at least one checker. Will call state::fail() with proper code and message.
83 * @retval true packet satisfies all checkers, further validation is needed
84 *
85 * @throw Error the supplied pktType doesn't match one for which the rule is designed
86 */
87 bool
88 check(uint32_t pktType, const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state) const;
89
90public:
91 /**
92 * @brief create a rule from configuration section
93 *
94 * @param configSection The section containing the definition of checker.
95 * @param configFilename The configuration file name.
96 * @return a rule created from configuration
97 */
98 static unique_ptr<Rule>
99 create(const ConfigSection& configSection, const std::string& configFilename);
100
101NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
102 std::string m_id;
103 uint32_t m_pktType;
104 std::vector<unique_ptr<Filter>> m_filters;
105 std::vector<unique_ptr<Checker>> m_checkers;
106};
107
108} // namespace validator_config
109} // namespace v2
110} // namespace security
111} // namespace ndn
112
113#endif // NDN_SECURITY_V2_VALIDATOR_CONFIG_RULE_HPP