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 | |
| 11 | #include "chat-policy-rule.cpp" |
| 12 | |
| 13 | using namespace ndn; |
| 14 | using namespace std; |
| 15 | using namespace ndn::security; |
| 16 | |
| 17 | |
| 18 | ChatPolicyRule::ChatPolicyRule(Ptr<Regex> dataRegex, const Name& dataRef, |
| 19 | Ptr<Regex> signerRegex, const Name& signerRef, |
| 20 | bool isPositive) |
| 21 | : PolicyRule(PolicyRule::IDENTITY_POLICY, isPositive) |
| 22 | , m_dataRegex(dataRegex) |
| 23 | , m_signerRegex(signerRegex) |
| 24 | , m_dataRef(dataRef) |
| 25 | , m_signerRef(signerRef) |
| 26 | {} |
| 27 | |
| 28 | bool |
| 29 | ChatPolicyRule::matchDataName(const Data & data) |
| 30 | { return (m_dataRegex.match(data.getName()) && m_dataRegex.expand() == m_dataRef) ? true : false; } |
| 31 | |
| 32 | bool |
| 33 | ChatPolicyRule::matchSignerName(const Data & data) |
| 34 | { |
| 35 | Ptr<const signature::Sha256WithRsa> sigPtr = DynamicCast<const signature::Sha256WithRsa> (data.getSignature()); |
| 36 | Name signerName = sigPtr->getKeyLocator ().getKeyName (); |
| 37 | return (m_signerRegex.match(signerName) && m_signerRegex.expand() == m_signerRef) ? true : false; |
| 38 | } |
| 39 | |
| 40 | bool |
| 41 | ChatPolicyRule::satisfy(const Data & data) |
| 42 | { return (matchDataName(data) && matchSignerName(data)) ? true : false ; } |
| 43 | |
| 44 | bool |
| 45 | ChatPolicyRule::satisfy(const Name & dataName, const Name & signerName) |
| 46 | { |
| 47 | if (m_dataRegex.match(data.getName()) |
| 48 | && m_dataRegex.expand() == m_dataRef |
| 49 | && m_signerRegex.match(signerName) |
| 50 | && m_signerRegex.expand() == m_signerRef) |
| 51 | return true; |
| 52 | else |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | TiXmlElement * |
| 57 | ChatPolicyRule::toXmlElement() |
| 58 | { |
| 59 | //TODO: |
| 60 | return NULL; |
| 61 | } |
| 62 | }; |