blob: 97f270b50196ef87d98af8c024d4e144c80e0317 [file] [log] [blame]
Yingdi Yu7d773322015-03-22 21:32:48 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07003 * Copyright (c) 2014-2017, Regents of the University of California
Yingdi Yu7d773322015-03-22 21:32:48 -07004 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07005 * This file is part of NDN DeLorean, An Authentication System for Data Archives in
6 * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors
7 * and contributors.
Yingdi Yu7d773322015-03-22 21:32:48 -07008 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07009 * NDN DeLorean is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
Yingdi Yu7d773322015-03-22 21:32:48 -070013 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070014 * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
Yingdi Yu7d773322015-03-22 21:32:48 -070017 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070018 * You should have received a copy of the GNU General Public License along with NDN
19 * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Yingdi Yu7d773322015-03-22 21:32:48 -070020 */
21
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070022#ifndef NDN_DELOREAN_CONF_KEY_LOCATOR_CHECKER_HPP
23#define NDN_DELOREAN_CONF_KEY_LOCATOR_CHECKER_HPP
Yingdi Yu7d773322015-03-22 21:32:48 -070024
25#include "common.hpp"
26#include "config.hpp"
27#include <ndn-cxx/util/regex.hpp>
28
29namespace nsl {
30namespace conf {
31
32class KeyLocatorCheckerFactory;
33
34/**
35 * @brief KeyLocatorChecker is one of the classes used by ValidatorConfig.
36 *
37 * The ValidatorConfig class consists of a set of rules.
38 * The KeyLocatorChecker class is part of a rule and is used to check if the KeyLocator field of a
39 * packet satisfy the requirements.
40 */
41
42
43class KeyLocatorChecker
44{
45public:
46 enum Relation {
47 RELATION_EQUAL,
48 RELATION_IS_PREFIX_OF,
49 RELATION_IS_STRICT_PREFIX_OF
50 };
51
52 virtual
53 ~KeyLocatorChecker();
54
55 bool
56 check(const Data& data, const KeyLocator& keyLocator, std::string& failInfo);
57
58protected:
59 virtual bool
60 check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo) = 0;
61
62 bool
63 checkRelation(const Relation& relation, const Name& name1, const Name& name2);
64};
65
66class RelationKeyLocatorNameChecker : public KeyLocatorChecker
67{
68public:
69 RelationKeyLocatorNameChecker(const Name& name, const KeyLocatorChecker::Relation& relation);
70
71protected:
72 virtual bool
73 check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo);
74
75private:
76 Name m_name;
77 KeyLocatorChecker::Relation m_relation;
78};
79
80class RegexKeyLocatorNameChecker : public KeyLocatorChecker
81{
82public:
83 explicit
84 RegexKeyLocatorNameChecker(const ndn::Regex& regex);
85
86protected:
87 virtual bool
88 check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo);
89
90private:
91 ndn::Regex m_regex;
92};
93
94class HyperKeyLocatorNameChecker : public KeyLocatorChecker
95{
96public:
97 HyperKeyLocatorNameChecker(const std::string& pExpr, const std::string pExpand,
98 const std::string& kExpr, const std::string kExpand,
99 const Relation& hyperRelation);
100
101protected:
102 virtual bool
103 check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo);
104
105private:
106 shared_ptr<ndn::Regex> m_hyperPRegex;
107 shared_ptr<ndn::Regex> m_hyperKRegex;
108 Relation m_hyperRelation;
109};
110
111
112class KeyLocatorCheckerFactory
113{
114public:
115 static shared_ptr<KeyLocatorChecker>
116 create(const ConfigSection& configSection);
117
118private:
119 static shared_ptr<KeyLocatorChecker>
120 createKeyLocatorNameChecker(const ConfigSection& configSection);
121};
122
123
124} // namespace conf
125} // namespace nsl
126
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -0700127#endif // NDN_DELOREAN_CONF_KEY_LOCATOR_CHECKER_HPP