blob: 9fbd23aae19f64bdc89f63ffb294c5005450e08b [file] [log] [blame]
Yingdi Yu43e71612013-10-30 22:19:31 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
11#include "specific-policy-rule.h"
12#include <ndn.cxx/fields/signature-sha256-with-rsa.h>
13
14using namespace ndn;
15using namespace std;
16using namespace ndn::security;
17
18
19SpecificPolicyRule::SpecificPolicyRule(Ptr<Regex> dataRegex,
20 Ptr<Regex> signerRegex)
21 : PolicyRule(PolicyRule::IDENTITY_POLICY, true)
22 , m_dataRegex(dataRegex)
23 , m_signerRegex(signerRegex)
24{}
25
26SpecificPolicyRule::SpecificPolicyRule(const SpecificPolicyRule& rule)
27 : PolicyRule(PolicyRule::IDENTITY_POLICY, true)
28 , m_dataRegex(rule.m_dataRegex)
29 , m_signerRegex(rule.m_signerRegex)
30{}
31
32bool
33SpecificPolicyRule::matchDataName(const Data & data)
34{ return m_dataRegex->match(data.getName()); }
35
36bool
37SpecificPolicyRule::matchSignerName(const Data & data)
38{
39 Ptr<const signature::Sha256WithRsa> sigPtr = DynamicCast<const signature::Sha256WithRsa> (data.getSignature());
40 Name signerName = sigPtr->getKeyLocator ().getKeyName ();
41 return m_signerRegex->match(signerName);
42}
43
44bool
45SpecificPolicyRule::satisfy(const Data & data)
46{ return (matchDataName(data) && matchSignerName(data)) ? true : false ; }
47
48bool
49SpecificPolicyRule::satisfy(const Name & dataName, const Name & signerName)
50{ return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); }