blob: b1973de07c30ffd324002fd7d26e85fcdc90dc8a [file] [log] [blame]
Yingdi Yu3715f8d2014-01-30 00:32:20 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08008#include "common.hpp"
9
Yingdi Yu3715f8d2014-01-30 00:32:20 -080010#include "sec-rule-specific.hpp"
11#include "signature-sha256-with-rsa.hpp"
12
13using namespace ndn;
14using namespace std;
15
16namespace ndn{
17
18SecRuleSpecific::SecRuleSpecific(shared_ptr<Regex> dataRegex,
19 shared_ptr<Regex> signerRegex)
20 : SecRule(true)
21 , m_dataRegex(dataRegex)
22 , m_signerRegex(signerRegex)
23{}
24
25SecRuleSpecific::SecRuleSpecific(const SecRuleSpecific& rule)
26 : SecRule(true)
27 , m_dataRegex(rule.m_dataRegex)
28 , m_signerRegex(rule.m_signerRegex)
29{}
30
31bool
32SecRuleSpecific::matchDataName(const Data& data)
33{ return m_dataRegex->match(data.getName()); }
34
35bool
36SecRuleSpecific::matchSignerName(const Data& data)
37{
38 try{
39 SignatureSha256WithRsa sig(data.getSignature());
40 Name signerName = sig.getKeyLocator().getName ();
41 return m_signerRegex->match(signerName);
42 }catch(SignatureSha256WithRsa::Error &e){
43 return false;
44 }catch(KeyLocator::Error &e){
45 return false;
46 }
47}
48
49bool
50SecRuleSpecific::satisfy(const Data & data)
51{ return (matchDataName(data) && matchSignerName(data)) ? true : false ; }
52
53bool
54SecRuleSpecific::satisfy(const Name & dataName, const Name & signerName)
55{ return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); }
56
57}