Yingdi Yu | 89da305 | 2013-10-26 15:08:37 -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 | |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 11 | #include "chat-policy-rule.h" |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 12 | #include <ndn-cpp/sha256-with-rsa-signature.hpp> |
Yingdi Yu | 89da305 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 13 | |
| 14 | using namespace ndn; |
| 15 | using namespace std; |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 16 | using namespace ndn::ptr_lib; |
Yingdi Yu | 89da305 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 17 | |
| 18 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 19 | ChatPolicyRule::ChatPolicyRule(shared_ptr<Regex> dataRegex, |
| 20 | shared_ptr<Regex> signerRegex) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 21 | : PolicyRule(PolicyRule::IDENTITY_POLICY, true) |
Yingdi Yu | 89da305 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 22 | , m_dataRegex(dataRegex) |
| 23 | , m_signerRegex(signerRegex) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 24 | {} |
| 25 | |
| 26 | ChatPolicyRule::ChatPolicyRule(const ChatPolicyRule& rule) |
| 27 | : PolicyRule(PolicyRule::IDENTITY_POLICY, true) |
| 28 | , m_dataRegex(rule.m_dataRegex) |
| 29 | , m_signerRegex(rule.m_signerRegex) |
Yingdi Yu | 89da305 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 30 | {} |
| 31 | |
| 32 | bool |
| 33 | ChatPolicyRule::matchDataName(const Data & data) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 34 | { return m_dataRegex->match(data.getName()); } |
Yingdi Yu | 89da305 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 35 | |
| 36 | bool |
| 37 | ChatPolicyRule::matchSignerName(const Data & data) |
| 38 | { |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 39 | const Sha256WithRsaSignature* sigPtr = dynamic_cast<const Sha256WithRsaSignature*> (data.getSignature()); |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 40 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 41 | if(NULL == sigPtr) |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 42 | return false; |
| 43 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 44 | if(ndn_KeyLocatorType_KEYNAME != sigPtr->getKeyLocator().getType()) |
Yingdi Yu | b35b865 | 2013-11-07 11:32:40 -0800 | [diff] [blame] | 45 | return false; |
| 46 | |
Yingdi Yu | 89da305 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 47 | Name signerName = sigPtr->getKeyLocator ().getKeyName (); |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 48 | return m_signerRegex->match(signerName); |
Yingdi Yu | 89da305 | 2013-10-26 15:08:37 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | bool |
| 52 | ChatPolicyRule::satisfy(const Data & data) |
| 53 | { return (matchDataName(data) && matchSignerName(data)) ? true : false ; } |
| 54 | |
| 55 | bool |
| 56 | ChatPolicyRule::satisfy(const Name & dataName, const Name & signerName) |
Yingdi Yu | 42f6646 | 2013-10-31 17:38:22 -0700 | [diff] [blame] | 57 | { return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); } |