Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 1 | /* -*- 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 Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 12 | #include <ndn-cpp/sha256-with-rsa-signature.hpp> |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 13 | |
| 14 | using namespace ndn; |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 15 | using namespace ndn::ptr_lib; |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 16 | using namespace std; |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 17 | |
| 18 | |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 19 | SpecificPolicyRule::SpecificPolicyRule(shared_ptr<Regex> dataRegex, |
| 20 | shared_ptr<Regex> signerRegex) |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 21 | : PolicyRule(PolicyRule::IDENTITY_POLICY, true) |
| 22 | , m_dataRegex(dataRegex) |
| 23 | , m_signerRegex(signerRegex) |
| 24 | {} |
| 25 | |
| 26 | SpecificPolicyRule::SpecificPolicyRule(const SpecificPolicyRule& rule) |
| 27 | : PolicyRule(PolicyRule::IDENTITY_POLICY, true) |
| 28 | , m_dataRegex(rule.m_dataRegex) |
| 29 | , m_signerRegex(rule.m_signerRegex) |
| 30 | {} |
| 31 | |
| 32 | bool |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 33 | SpecificPolicyRule::matchDataName(const Data& data) |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 34 | { return m_dataRegex->match(data.getName()); } |
| 35 | |
| 36 | bool |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 37 | SpecificPolicyRule::matchSignerName(const Data& data) |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 38 | { |
Yingdi Yu | 46c9f1a | 2013-12-18 15:15:46 +0800 | [diff] [blame^] | 39 | const Sha256WithRsaSignature* sigPtr = dynamic_cast<const Sha256WithRsaSignature*> (data.getSignature()); |
| 40 | Name signerName = sigPtr->getKeyLocator().getKeyName (); |
Yingdi Yu | 43e7161 | 2013-10-30 22:19:31 -0700 | [diff] [blame] | 41 | return m_signerRegex->match(signerName); |
| 42 | } |
| 43 | |
| 44 | bool |
| 45 | SpecificPolicyRule::satisfy(const Data & data) |
| 46 | { return (matchDataName(data) && matchSignerName(data)) ? true : false ; } |
| 47 | |
| 48 | bool |
| 49 | SpecificPolicyRule::satisfy(const Name & dataName, const Name & signerName) |
| 50 | { return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); } |