/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2013, Regents of the University of California
 *                     Yingdi Yu
 *
 * BSD license, See the LICENSE file for more information
 *
 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
 */

#include "specific-policy-rule.h"
#include <ndn-cpp/sha256-with-rsa-signature.hpp>

using namespace ndn;
using namespace ndn::ptr_lib;
using namespace std;


SpecificPolicyRule::SpecificPolicyRule(shared_ptr<Regex> dataRegex,
				       shared_ptr<Regex> signerRegex)
  : PolicyRule(PolicyRule::IDENTITY_POLICY, true)
  , m_dataRegex(dataRegex)
  , m_signerRegex(signerRegex)
{}

SpecificPolicyRule::SpecificPolicyRule(const SpecificPolicyRule& rule)
  : PolicyRule(PolicyRule::IDENTITY_POLICY, true)
  , m_dataRegex(rule.m_dataRegex)
  , m_signerRegex(rule.m_signerRegex)
{}

bool 
SpecificPolicyRule::matchDataName(const Data& data)
{ return m_dataRegex->match(data.getName()); }

bool 
SpecificPolicyRule::matchSignerName(const Data& data)
{ 
  const Sha256WithRsaSignature* sigPtr = dynamic_cast<const Sha256WithRsaSignature*> (data.getSignature());
  Name signerName = sigPtr->getKeyLocator().getKeyName ();
  return m_signerRegex->match(signerName); 
}

bool
SpecificPolicyRule::satisfy(const Data & data)
{ return (matchDataName(data) && matchSignerName(data)) ? true : false ; }

bool
SpecificPolicyRule::satisfy(const Name & dataName, const Name & signerName)
{ return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); }
