NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
sec-rule-specific.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
24 #include "common.hpp"
25 
26 #include "sec-rule-specific.hpp"
28 
29 namespace ndn {
30 
31 SecRuleSpecific::SecRuleSpecific(shared_ptr<Regex> dataRegex,
32  shared_ptr<Regex> signerRegex)
33  : SecRule(true)
34  , m_dataRegex(dataRegex)
35  , m_signerRegex(signerRegex)
36  , m_isExempted(false)
37 {
38 }
39 
40 SecRuleSpecific::SecRuleSpecific(shared_ptr<Regex> dataRegex)
41  : SecRule(true)
42  , m_dataRegex(dataRegex)
43  , m_isExempted(true)
44 {
45 }
46 
48  : SecRule(true)
49  , m_dataRegex(rule.m_dataRegex)
50  , m_signerRegex(rule.m_signerRegex)
51  , m_isExempted(rule.m_isExempted)
52 {
53 }
54 
55 bool
57 {
58  return m_dataRegex->match(data.getName());
59 }
60 
61 bool
63 {
64  if (m_isExempted)
65  return true;
66 
67  try
68  {
69  if (!data.getSignature().hasKeyLocator())
70  return false;
71 
72  const KeyLocator& keyLocator = data.getSignature().getKeyLocator();
73  if (keyLocator.getType() != KeyLocator::KeyLocator_Name)
74  return false;
75 
76  const Name& signerName = keyLocator.getName();
77  return m_signerRegex->match(signerName);
78  }
79  catch (tlv::Error& e)
80  {
81  return false;
82  }
83  catch (RegexMatcher::Error& e)
84  {
85  return false;
86  }
87 }
88 
89 bool
91 {
92  return (matchDataName(data) && matchSignerName(data)) ? true : false;
93 }
94 
95 bool
96 SecRuleSpecific::satisfy(const Name& dataName, const Name& signerName)
97 {
98  bool isSignerMatched = m_isExempted || m_signerRegex->match(signerName);
99  return m_dataRegex->match(dataName) && isSignerMatched;
100 }
101 
102 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
bool matchDataName(const Data &data)
bool matchSignerName(const Data &data)
const Name & getName() const
Get name of the Data packet.
Definition: data.hpp:360
const Name & getName() const
get Name element
indicates KeyLocator contains a Name
Definition: key-locator.hpp:49
bool hasKeyLocator() const
Check if SignatureInfo block has a KeyLocator.
Definition: signature.hpp:123
Name abstraction to represent an absolute name.
Definition: name.hpp:46
Type getType() const
SecRuleSpecific(shared_ptr< Regex > dataRegex, shared_ptr< Regex > signerRegex)
const Signature & getSignature() const
Definition: data.hpp:390
const KeyLocator & getKeyLocator() const
Get KeyLocator.
Definition: signature.hpp:134
represents a Data packet
Definition: data.hpp:39
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
bool satisfy(const Data &data)