security: using new security interfaces of ndn-cpp, such as SecPolicy
Change-Id: Id22c8e711bee7c3723076eda7a3f96c72ca7707c
diff --git a/src/sec-rule-chrono-chat.cpp b/src/sec-rule-chrono-chat.cpp
new file mode 100644
index 0000000..b62b6a8
--- /dev/null
+++ b/src/sec-rule-chrono-chat.cpp
@@ -0,0 +1,56 @@
+/* -*- 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 "sec-rule-chrono-chat.h"
+#include <ndn-cpp/security/signature-sha256-with-rsa.hpp>
+
+using namespace ndn;
+using namespace std;
+using namespace ndn::ptr_lib;
+
+
+SecRuleChronoChat::SecRuleChronoChat(shared_ptr<Regex> dataRegex,
+ shared_ptr<Regex> signerRegex)
+ : SecRule(SecRule::IDENTITY_RULE, true)
+ , m_dataRegex(dataRegex)
+ , m_signerRegex(signerRegex)
+{}
+
+SecRuleChronoChat::SecRuleChronoChat(const SecRuleChronoChat& rule)
+ : SecRule(SecRule::IDENTITY_RULE, true)
+ , m_dataRegex(rule.m_dataRegex)
+ , m_signerRegex(rule.m_signerRegex)
+{}
+
+bool
+SecRuleChronoChat::matchDataName(const Data & data)
+{ return m_dataRegex->match(data.getName()); }
+
+bool
+SecRuleChronoChat::matchSignerName(const Data & data)
+{
+ try{
+ SignatureSha256WithRsa sig(data.getSignature());
+ Name signerName = sig.getKeyLocator().getName ();
+ return m_signerRegex->match(signerName);
+ }catch(SignatureSha256WithRsa::Error &e){
+ return false;
+ }catch(KeyLocator::Error &e){
+ return false;
+ }
+}
+
+bool
+SecRuleChronoChat::satisfy(const Data & data)
+{ return (matchDataName(data) && matchSignerName(data)) ? true : false ; }
+
+bool
+SecRuleChronoChat::satisfy(const Name & dataName, const Name & signerName)
+{ return (m_dataRegex->match(dataName) && m_signerRegex->match(signerName)); }