blob: 7057ba5a8c2a2c0617d83aa9685b91795fc13643 [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"
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080012#include <ndn-cpp/sha256-with-rsa-signature.hpp>
Yingdi Yu43e71612013-10-30 22:19:31 -070013
14using namespace ndn;
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080015using namespace ndn::ptr_lib;
Yingdi Yu43e71612013-10-30 22:19:31 -070016using namespace std;
Yingdi Yu43e71612013-10-30 22:19:31 -070017
18
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080019SpecificPolicyRule::SpecificPolicyRule(shared_ptr<Regex> dataRegex,
20 shared_ptr<Regex> signerRegex)
Yingdi Yu43e71612013-10-30 22:19:31 -070021 : 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
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080033SpecificPolicyRule::matchDataName(const Data& data)
Yingdi Yu43e71612013-10-30 22:19:31 -070034{ return m_dataRegex->match(data.getName()); }
35
36bool
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080037SpecificPolicyRule::matchSignerName(const Data& data)
Yingdi Yu43e71612013-10-30 22:19:31 -070038{
Yingdi Yu46c9f1a2013-12-18 15:15:46 +080039 const Sha256WithRsaSignature* sigPtr = dynamic_cast<const Sha256WithRsaSignature*> (data.getSignature());
40 Name signerName = sigPtr->getKeyLocator().getKeyName ();
Yingdi Yu43e71612013-10-30 22:19:31 -070041 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)); }