blob: 7cc2937e4b030fd742f58c5c7f97fb245edf1888 [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
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -070029namespace ndn {
30namespace delorean {
Yingdi Yu7d773322015-03-22 21:32:48 -070031namespace conf {
32
33class KeyLocatorCheckerFactory;
34
35/**
36 * @brief KeyLocatorChecker is one of the classes used by ValidatorConfig.
37 *
38 * The ValidatorConfig class consists of a set of rules.
39 * The KeyLocatorChecker class is part of a rule and is used to check if the KeyLocator field of a
40 * packet satisfy the requirements.
41 */
42
43
44class KeyLocatorChecker
45{
46public:
47 enum Relation {
48 RELATION_EQUAL,
49 RELATION_IS_PREFIX_OF,
50 RELATION_IS_STRICT_PREFIX_OF
51 };
52
53 virtual
54 ~KeyLocatorChecker();
55
56 bool
57 check(const Data& data, const KeyLocator& keyLocator, std::string& failInfo);
58
59protected:
60 virtual bool
61 check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo) = 0;
62
63 bool
64 checkRelation(const Relation& relation, const Name& name1, const Name& name2);
65};
66
67class RelationKeyLocatorNameChecker : public KeyLocatorChecker
68{
69public:
70 RelationKeyLocatorNameChecker(const Name& name, const KeyLocatorChecker::Relation& relation);
71
72protected:
73 virtual bool
74 check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo);
75
76private:
77 Name m_name;
78 KeyLocatorChecker::Relation m_relation;
79};
80
81class RegexKeyLocatorNameChecker : public KeyLocatorChecker
82{
83public:
84 explicit
85 RegexKeyLocatorNameChecker(const ndn::Regex& regex);
86
87protected:
88 virtual bool
89 check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo);
90
91private:
92 ndn::Regex m_regex;
93};
94
95class HyperKeyLocatorNameChecker : public KeyLocatorChecker
96{
97public:
98 HyperKeyLocatorNameChecker(const std::string& pExpr, const std::string pExpand,
99 const std::string& kExpr, const std::string kExpand,
100 const Relation& hyperRelation);
101
102protected:
103 virtual bool
104 check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo);
105
106private:
107 shared_ptr<ndn::Regex> m_hyperPRegex;
108 shared_ptr<ndn::Regex> m_hyperKRegex;
109 Relation m_hyperRelation;
110};
111
112
113class KeyLocatorCheckerFactory
114{
115public:
116 static shared_ptr<KeyLocatorChecker>
117 create(const ConfigSection& configSection);
118
119private:
120 static shared_ptr<KeyLocatorChecker>
121 createKeyLocatorNameChecker(const ConfigSection& configSection);
122};
123
124
125} // namespace conf
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -0700126} // namespace delorean
127} // namespace ndn
Yingdi Yu7d773322015-03-22 21:32:48 -0700128
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -0700129#endif // NDN_DELOREAN_CONF_KEY_LOCATOR_CHECKER_HPP