27 #include <boost/algorithm/string/predicate.hpp> 32 namespace validator_config {
36 const shared_ptr<ValidationState>& state)
66 , m_relation(relation)
72 const shared_ptr<ValidationState>& state)
78 std::ostringstream os;
79 os <<
"KeyLocator check failed: name relation " << m_name <<
" " << m_relation
80 <<
" for packet " << pktName <<
" is invalid" 81 <<
" (KeyLocator=" << klName <<
", identity=" << identity <<
")";
95 bool result = m_regex.
match(klName);
97 std::ostringstream os;
98 os <<
"KeyLocator check failed: regex " << m_regex <<
" for packet " << pktName <<
" is invalid" 99 <<
" (KeyLocator=" << klName <<
")";
106 const std::string& klNameExpr,
const std::string klNameExpand,
108 : m_hyperPRegex(pktNameExpr, pktNameExpand)
109 , m_hyperKRegex(klNameExpr, klNameExpand)
110 , m_hyperRelation(hyperRelation)
116 const shared_ptr<ValidationState>& state)
118 if (!m_hyperPRegex.
match(pktName) || !m_hyperKRegex.
match(klName)) {
119 std::ostringstream os;
120 os <<
"Packet " << pktName <<
" (" <<
"KeyLocator=" << klName <<
") does not match " 121 <<
"the hyper relation rule pkt=" << m_hyperPRegex <<
", key=" << m_hyperKRegex;
128 std::ostringstream os;
129 os <<
"KeyLocator check failed: hyper relation " << m_hyperRelation
130 <<
" pkt=" << m_hyperPRegex <<
", key=" << m_hyperKRegex
131 <<
" of packet " << pktName <<
" (KeyLocator=" << klName <<
") is invalid";
140 auto propertyIt = configSection.begin();
143 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"type")) {
147 std::string type = propertyIt->second.data();
148 if (boost::iequals(type,
"customized")) {
149 return createCustomizedChecker(configSection, configFilename);
151 else if (boost::iequals(type,
"hierarchical")) {
152 return createHierarchicalChecker(configSection, configFilename);
160 Checker::createCustomizedChecker(
const ConfigSection& configSection,
161 const std::string& configFilename)
163 auto propertyIt = configSection.begin();
168 if (propertyIt != configSection.end() && boost::iequals(propertyIt->first,
"sig-type")) {
174 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"key-locator")) {
178 auto checker = createKeyLocatorChecker(propertyIt->second, configFilename);
181 if (propertyIt != configSection.end()) {
188 Checker::createHierarchicalChecker(
const ConfigSection& configSection,
189 const std::string& configFilename)
191 auto propertyIt = configSection.begin();
196 if (propertyIt != configSection.end() && boost::iequals(propertyIt->first,
"sig-type")) {
201 if (propertyIt != configSection.end()) {
204 return make_unique<HyperRelationChecker>(
"^(<>*)$",
"\\1",
205 "^(<>*)<KEY><>$",
"\\1",
210 Checker::createKeyLocatorChecker(
const ConfigSection& configSection,
211 const std::string& configFilename)
213 auto propertyIt = configSection.begin();
216 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"type"))
219 std::string type = propertyIt->second.data();
220 if (boost::iequals(type,
"name"))
221 return createKeyLocatorNameChecker(configSection, configFilename);
223 NDN_THROW(
Error(
"Unrecognized <checker.key-locator.type>: " + type));
227 Checker::createKeyLocatorNameChecker(
const ConfigSection& configSection,
228 const std::string& configFilename)
230 auto propertyIt = configSection.begin();
233 if (propertyIt == configSection.end())
236 if (boost::iequals(propertyIt->first,
"name")) {
239 name =
Name(propertyIt->second.data());
246 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"relation")) {
250 std::string relationString = propertyIt->second.data();
255 if (propertyIt != configSection.end()) {
258 return make_unique<NameRelationChecker>(name, relation);
260 else if (boost::iequals(propertyIt->first,
"regex")) {
261 std::string regexString = propertyIt->second.data();
264 if (propertyIt != configSection.end()) {
269 return make_unique<RegexChecker>(
Regex(regexString));
275 else if (boost::iequals(propertyIt->first,
"hyper-relation")) {
277 auto hPropertyIt = hSection.begin();
280 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"k-regex")) {
281 NDN_THROW(
Error(
"Expecting <checker.key-locator.hyper-relation.k-regex>"));
284 std::string kRegex = hPropertyIt->second.data();
288 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"k-expand")) {
289 NDN_THROW(
Error(
"Expecting <checker.key-locator.hyper-relation.k-expand>"));
292 std::string kExpand = hPropertyIt->second.data();
296 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"h-relation")) {
297 NDN_THROW(
Error(
"Expecting <checker.key-locator.hyper-relation.h-relation>"));
300 std::string hRelation = hPropertyIt->second.data();
304 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"p-regex")) {
305 NDN_THROW(
Error(
"Expecting <checker.key-locator.hyper-relation.p-regex>"));
308 std::string pRegex = hPropertyIt->second.data();
312 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"p-expand")) {
313 NDN_THROW(
Error(
"Expecting <checker.key-locator.hyper-relation.p-expand>"));
316 std::string pExpand = hPropertyIt->second.data();
319 if (hPropertyIt != hSection.end()) {
320 NDN_THROW(
Error(
"Expecting end of <checker.key-locator.hyper-relation>"));
325 return make_unique<HyperRelationChecker>(pRegex, pExpand, kRegex, kExpand, relation);
332 NDN_THROW(
Error(
"Unrecognized <checker.key-locator>: " + propertyIt->first));
#define NDN_THROW_NESTED(e)
Sign Interest using Packet Specification v0.3 semantics.
PartialName getPrefix(ssize_t nComponents) const
Returns a prefix of the name.
NameRelationChecker(const Name &name, const NameRelation &relation)
bool checkNames(const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) override
const size_t MIN_SIZE
minimal number of components for Signed Interest
RegexChecker(const Regex ®ex)
provides a tag type for simple types
bool checkNameRelation(NameRelation relation, const Name &name1, const Name &name2)
check whether name1 and name2 satisfies relation
bool checkNames(const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) override
NameRelation getNameRelationFromString(const std::string &relationString)
convert relationString to NameRelation
Represents an absolute name.
size_t size() const
Returns the number of components.
boost::property_tree::ptree ConfigSection
virtual Name expand(const std::string &expand="")
bool checkNames(const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) override
bool match(const Name &name)
HyperRelationChecker(const std::string &pktNameExpr, const std::string pktNameExpand, const std::string &klNameExpr, const std::string klNameExpand, const NameRelation &hyperRelation)
bool check(uint32_t pktType, const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state)
Check if packet name ane KeyLocator satisfy the checker's conditions.
virtual bool checkNames(const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state)=0
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName.
static unique_ptr< Checker > create(const ConfigSection &configSection, const std::string &configFilename)
create a checker from configuration section