blob: 1aa8b24afdb338636cf7d14500cea8e6d2b9d5c5 [file] [log] [blame]
Yingdi Yu89da3052013-10-26 15:08:37 -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 "chat-policy-rule.cpp"
12
13using namespace ndn;
14using namespace std;
15using namespace ndn::security;
16
17
18ChatPolicyRule::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
28bool
29ChatPolicyRule::matchDataName(const Data & data)
30{ return (m_dataRegex.match(data.getName()) && m_dataRegex.expand() == m_dataRef) ? true : false; }
31
32bool
33ChatPolicyRule::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
40bool
41ChatPolicyRule::satisfy(const Data & data)
42{ return (matchDataName(data) && matchSignerName(data)) ? true : false ; }
43
44bool
45ChatPolicyRule::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
56TiXmlElement *
57ChatPolicyRule::toXmlElement()
58{
59 //TODO:
60 return NULL;
61}
62};