Yingdi Yu | 7d77332 | 2015-03-22 21:32:48 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California |
Yingdi Yu | 7d77332 | 2015-03-22 21:32:48 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 5 | * 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 Yu | 7d77332 | 2015-03-22 21:32:48 -0700 | [diff] [blame] | 8 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 9 | * 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 Yu | 7d77332 | 2015-03-22 21:32:48 -0700 | [diff] [blame] | 13 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 14 | * 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 Yu | 7d77332 | 2015-03-22 21:32:48 -0700 | [diff] [blame] | 17 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 18 | * 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 Yu | 7d77332 | 2015-03-22 21:32:48 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 22 | #ifndef NDN_DELOREAN_CONF_KEY_LOCATOR_CHECKER_HPP |
| 23 | #define NDN_DELOREAN_CONF_KEY_LOCATOR_CHECKER_HPP |
Yingdi Yu | 7d77332 | 2015-03-22 21:32:48 -0700 | [diff] [blame] | 24 | |
| 25 | #include "common.hpp" |
| 26 | #include "config.hpp" |
| 27 | #include <ndn-cxx/util/regex.hpp> |
| 28 | |
Alexander Afanasyev | 49e2e4c | 2017-05-06 13:42:57 -0700 | [diff] [blame^] | 29 | namespace ndn { |
| 30 | namespace delorean { |
Yingdi Yu | 7d77332 | 2015-03-22 21:32:48 -0700 | [diff] [blame] | 31 | namespace conf { |
| 32 | |
| 33 | class 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 | |
| 44 | class KeyLocatorChecker |
| 45 | { |
| 46 | public: |
| 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 | |
| 59 | protected: |
| 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 | |
| 67 | class RelationKeyLocatorNameChecker : public KeyLocatorChecker |
| 68 | { |
| 69 | public: |
| 70 | RelationKeyLocatorNameChecker(const Name& name, const KeyLocatorChecker::Relation& relation); |
| 71 | |
| 72 | protected: |
| 73 | virtual bool |
| 74 | check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo); |
| 75 | |
| 76 | private: |
| 77 | Name m_name; |
| 78 | KeyLocatorChecker::Relation m_relation; |
| 79 | }; |
| 80 | |
| 81 | class RegexKeyLocatorNameChecker : public KeyLocatorChecker |
| 82 | { |
| 83 | public: |
| 84 | explicit |
| 85 | RegexKeyLocatorNameChecker(const ndn::Regex& regex); |
| 86 | |
| 87 | protected: |
| 88 | virtual bool |
| 89 | check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo); |
| 90 | |
| 91 | private: |
| 92 | ndn::Regex m_regex; |
| 93 | }; |
| 94 | |
| 95 | class HyperKeyLocatorNameChecker : public KeyLocatorChecker |
| 96 | { |
| 97 | public: |
| 98 | HyperKeyLocatorNameChecker(const std::string& pExpr, const std::string pExpand, |
| 99 | const std::string& kExpr, const std::string kExpand, |
| 100 | const Relation& hyperRelation); |
| 101 | |
| 102 | protected: |
| 103 | virtual bool |
| 104 | check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo); |
| 105 | |
| 106 | private: |
| 107 | shared_ptr<ndn::Regex> m_hyperPRegex; |
| 108 | shared_ptr<ndn::Regex> m_hyperKRegex; |
| 109 | Relation m_hyperRelation; |
| 110 | }; |
| 111 | |
| 112 | |
| 113 | class KeyLocatorCheckerFactory |
| 114 | { |
| 115 | public: |
| 116 | static shared_ptr<KeyLocatorChecker> |
| 117 | create(const ConfigSection& configSection); |
| 118 | |
| 119 | private: |
| 120 | static shared_ptr<KeyLocatorChecker> |
| 121 | createKeyLocatorNameChecker(const ConfigSection& configSection); |
| 122 | }; |
| 123 | |
| 124 | |
| 125 | } // namespace conf |
Alexander Afanasyev | 49e2e4c | 2017-05-06 13:42:57 -0700 | [diff] [blame^] | 126 | } // namespace delorean |
| 127 | } // namespace ndn |
Yingdi Yu | 7d77332 | 2015-03-22 21:32:48 -0700 | [diff] [blame] | 128 | |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 129 | #endif // NDN_DELOREAN_CONF_KEY_LOCATOR_CHECKER_HPP |