blob: 1479b6d1c5a03dd2d63c193c62f56924bb4f1a47 [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
8#include "sec-rule-specific.hpp"
9#include "signature-sha256-with-rsa.hpp"
10
11using namespace ndn;
12using namespace std;
13
14namespace ndn{
15
16SecRuleSpecific::SecRuleSpecific(shared_ptr<Regex> dataRegex,
17 shared_ptr<Regex> signerRegex)
18 : SecRule(true)
19 , m_dataRegex(dataRegex)
20 , m_signerRegex(signerRegex)
21{}
22
23SecRuleSpecific::SecRuleSpecific(const SecRuleSpecific& rule)
24 : SecRule(true)
25 , m_dataRegex(rule.m_dataRegex)
26 , m_signerRegex(rule.m_signerRegex)
27{}
28
29bool
30SecRuleSpecific::matchDataName(const Data& data)
31{ return m_dataRegex->match(data.getName()); }
32
33bool
34SecRuleSpecific::matchSignerName(const Data& data)
35{
36 try{
37 SignatureSha256WithRsa sig(data.getSignature());
38 Name signerName = sig.getKeyLocator().getName ();
39 return m_signerRegex->match(signerName);
40 }catch(SignatureSha256WithRsa::Error &e){
41 return false;
42 }catch(KeyLocator::Error &e){
43 return false;
44 }
45}
46
47bool
48SecRuleSpecific::satisfy(const Data & data)
49{ return (matchDataName(data) && matchSignerName(data)) ? true : false ; }
50
51bool
52SecRuleSpecific::satisfy(const Name & dataName, const Name & signerName)
53{ return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); }
54
55}