DER encoding: Added CertificateDataVisitor and use in Certificate::decode.
diff --git a/ndn-cpp/encoding/der/visitor/certificate-data-visitor.cpp b/ndn-cpp/encoding/der/visitor/certificate-data-visitor.cpp
new file mode 100644
index 0000000..e2ea049
--- /dev/null
+++ b/ndn-cpp/encoding/der/visitor/certificate-data-visitor.cpp
@@ -0,0 +1,158 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Yingdi Yu <yingdi@cs.ucla.edu>
+ * @author: Jeff Thompson <jefft0@remap.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "simple-visitor.hpp"
+#include "public-key-visitor.hpp"
+#include "../der.hpp"
+
+#include <ndn-cpp/security/certificate/certificate.hpp>
+#include <ndn-cpp/security/certificate/certificate-subject-description.hpp>
+#include <ndn-cpp/security/certificate/certificate-extension.hpp>
+
+#include "../../../util/logging.hpp"
+#include "certificate-data-visitor.hpp"
+
+using namespace std;
+using namespace ndn::ptr_lib;
+
+INIT_LOGGER("ndn.der.CertificateDataVisitor");
+
+namespace ndn {
+
+namespace der {
+
+/*
+ * CertificateDataVisitor
+ */
+void
+CertificateDataVisitor::visit(DerSequence& derSeq, ndnboost::any param)
+{
+ // _LOG_DEBUG("CertificateDataVisitor::visit");
+
+ const DerNodePtrList& children = derSeq.getChildren();
+ CertValidityVisitor validityVisitor;
+ children[0]->accept(validityVisitor, param);
+ CertSubjectVisitor subjectVisitor;
+ children[1]->accept(subjectVisitor, param);
+ PublicKeyVisitor pubkeyVisitor;
+ Certificate* certData = ndnboost::any_cast<Certificate*>(param);
+ certData->setPublicKeyInfo(*ndnboost::any_cast<shared_ptr<PublicKey> >(children[2]->accept(pubkeyVisitor)));
+
+ if(children.size() > 3)
+ {
+ CertExtensionVisitor extnVisitor;
+ children[3]->accept(extnVisitor, param);
+ }
+}
+
+/*
+ * CertValidityVisitor
+ */
+void
+CertValidityVisitor::visit(DerSequence& derSeq, ndnboost::any param)
+{
+ // _LOG_DEBUG("CertValidityVisitor::visit");
+
+ Certificate* certData = ndnboost::any_cast<Certificate*>(param);
+
+ const DerNodePtrList& children = derSeq.getChildren();
+
+ SimpleVisitor simpleVisitor;
+
+ MillisecondsSince1970 notBefore = ndnboost::any_cast<MillisecondsSince1970>(children[0]->accept(simpleVisitor));
+ MillisecondsSince1970 notAfter = ndnboost::any_cast<MillisecondsSince1970>(children[1]->accept(simpleVisitor));
+
+ // _LOG_DEBUG("parsed notBefore: " << notBefore);
+ // _LOG_DEBUG("parsed notAfter: " << notAfter);
+
+ certData->setNotBefore(notBefore);
+ certData->setNotAfter(notAfter);
+}
+
+/*
+ * CertSubDescryptVisitor
+ */
+void
+CertSubDescryptVisitor::visit(DerSequence& derSeq, ndnboost::any param)
+{
+ Certificate* certData = ndnboost::any_cast<Certificate*>(param);
+
+ const DerNodePtrList& children = derSeq.getChildren();
+
+ SimpleVisitor simpleVisitor;
+
+ OID oid = ndnboost::any_cast<OID>(children[0]->accept(simpleVisitor));
+ string value = ndnboost::any_cast<string>(children[1]->accept(simpleVisitor));
+
+ CertificateSubjectDescription subDescrypt(oid, value);
+
+ certData->addSubjectDescription(subDescrypt);
+}
+
+/*
+ * CertSubjectVisitor
+ */
+void
+CertSubjectVisitor::visit(DerSequence& derSeq, ndnboost::any param)
+{
+ // _LOG_DEBUG("CertSubjectVisitor::visit");
+
+ const DerNodePtrList& children = derSeq.getChildren();
+
+ CertSubDescryptVisitor descryptVisitor;
+
+ DerNodePtrList::const_iterator it = children.begin();
+
+ while(it != children.end()) {
+ (*it)->accept(descryptVisitor, param);
+ it++;
+ }
+}
+
+/*
+ * CertExtnEntryVisitor
+ */
+void
+CertExtnEntryVisitor::visit(DerSequence& derSeq, ndnboost::any param)
+{
+ Certificate* certData = ndnboost::any_cast<Certificate*>(param);
+
+ const DerNodePtrList& children = derSeq.getChildren();
+
+ SimpleVisitor simpleVisitor;
+
+ OID oid = ndnboost::any_cast<OID>(children[0]->accept(simpleVisitor));
+ bool critical = ndnboost::any_cast<bool>(children[1]->accept(simpleVisitor));
+ const Blob& value = ndnboost::any_cast<const Blob&>(children[2]->accept(simpleVisitor));
+
+ CertificateExtension extension(oid, critical, value);
+
+ certData->addExtension(extension);
+}
+
+/*
+ * CertExtensionVisitor
+ */
+void
+CertExtensionVisitor::visit(DerSequence& derSeq, ndnboost::any param)
+{
+ const DerNodePtrList& children = derSeq.getChildren();
+
+ CertExtnEntryVisitor extnEntryVisitor;
+
+ DerNodePtrList::const_iterator it = children.begin();
+
+ while(it != children.end()) {
+ (*it)->accept(extnEntryVisitor, param);
+ it++;
+ }
+}
+
+} // der
+
+}
diff --git a/ndn-cpp/encoding/der/visitor/certificate-data-visitor.hpp b/ndn-cpp/encoding/der/visitor/certificate-data-visitor.hpp
new file mode 100644
index 0000000..3df60be
--- /dev/null
+++ b/ndn-cpp/encoding/der/visitor/certificate-data-visitor.hpp
@@ -0,0 +1,51 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Yingdi Yu <yingdi@cs.ucla.edu>
+ * @author: Jeff Thompson <jefft0@remap.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NDN_CERTIFICATE_DATA_VISITOR_HPP
+#define NDN_CERTIFICATE_DATA_VISITOR_HPP
+
+#include "void-visitor.hpp"
+
+namespace ndn {
+
+namespace der {
+
+class CertificateDataVisitor : public VoidVisitor {
+ virtual void visit(DerSequence&, ndnboost::any);
+};
+
+class CertValidityVisitor : public VoidVisitor {
+public:
+ virtual void visit(DerSequence&, ndnboost::any);
+};
+
+class CertSubDescryptVisitor : public VoidVisitor {
+public:
+ virtual void visit(DerSequence&, ndnboost::any);
+};
+
+class CertSubjectVisitor : public VoidVisitor {
+public:
+ virtual void visit(DerSequence&, ndnboost::any);
+};
+
+class CertExtnEntryVisitor : public VoidVisitor {
+public:
+ virtual void visit(DerSequence&, ndnboost::any);
+};
+
+class CertExtensionVisitor : public VoidVisitor {
+public:
+ virtual void visit(DerSequence&, ndnboost::any);
+};
+
+} // der
+
+}
+
+#endif
diff --git a/ndn-cpp/encoding/der/visitor/no-arguments-visitor.hpp b/ndn-cpp/encoding/der/visitor/no-arguments-visitor.hpp
index 8358066..09c24c1 100644
--- a/ndn-cpp/encoding/der/visitor/no-arguments-visitor.hpp
+++ b/ndn-cpp/encoding/der/visitor/no-arguments-visitor.hpp
@@ -18,15 +18,15 @@
class NoArgumentsVisitor
{
public:
- virtual ndnboost::any visit(DerBool& ) = 0;
- virtual ndnboost::any visit(DerInteger& ) = 0;
- virtual ndnboost::any visit(DerPrintableString&) = 0;
- virtual ndnboost::any visit(DerBitString& ) = 0;
- virtual ndnboost::any visit(DerNull& ) = 0;
- virtual ndnboost::any visit(DerOctetString& ) = 0;
- virtual ndnboost::any visit(DerOid& ) = 0;
- virtual ndnboost::any visit(DerSequence& ) = 0;
- virtual ndnboost::any visit(DerGtime& ) = 0;
+ virtual ndnboost::any visit(DerBool& );
+ virtual ndnboost::any visit(DerInteger& );
+ virtual ndnboost::any visit(DerPrintableString&);
+ virtual ndnboost::any visit(DerBitString& );
+ virtual ndnboost::any visit(DerNull& );
+ virtual ndnboost::any visit(DerOctetString& );
+ virtual ndnboost::any visit(DerOid& );
+ virtual ndnboost::any visit(DerSequence& );
+ virtual ndnboost::any visit(DerGtime& );
};
} // der
diff --git a/ndn-cpp/encoding/der/visitor/public-key-visitor.cpp b/ndn-cpp/encoding/der/visitor/public-key-visitor.cpp
new file mode 100644
index 0000000..87e4e6c
--- /dev/null
+++ b/ndn-cpp/encoding/der/visitor/public-key-visitor.cpp
@@ -0,0 +1,35 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Yingdi Yu <yingdi@cs.ucla.edu>
+ * @author: Jeff Thompson <jefft0@remap.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "simple-visitor.hpp"
+#include <ndn-cpp/security/certificate/public-key.hpp>
+#include "../der.hpp"
+#include "public-key-visitor.hpp"
+
+using namespace std;
+using namespace ndn::ptr_lib;
+
+namespace ndn {
+
+namespace der {
+
+ndnboost::any
+PublicKeyVisitor::visit(DerSequence& derSeq)
+{
+ const DerNodePtrList& children = derSeq.getChildren();
+
+ SimpleVisitor simpleVisitor;
+ shared_ptr<DerSequence> algoSeq = dynamic_pointer_cast<DerSequence>(children[0]);
+ OID algorithm = ndnboost::any_cast<OID>(algoSeq->getChildren()[0]->accept(simpleVisitor));
+ Blob raw = derSeq.getRaw();
+ return ndnboost::any(shared_ptr<PublicKey>(new PublicKey(algorithm, raw)));
+}
+
+} // der
+
+}
diff --git a/ndn-cpp/encoding/der/visitor/public-key-visitor.hpp b/ndn-cpp/encoding/der/visitor/public-key-visitor.hpp
new file mode 100644
index 0000000..54dfb66
--- /dev/null
+++ b/ndn-cpp/encoding/der/visitor/public-key-visitor.hpp
@@ -0,0 +1,27 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Yingdi Yu <yingdi@cs.ucla.edu>
+ * @author: Jeff Thompson <jefft0@remap.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef NDN_PUBLIC_KEY_VISITOR_HPP
+#define NDN_PUBLIC_KEY_VISITOR_HPP
+
+#include "no-arguments-visitor.hpp"
+
+namespace ndn {
+
+namespace der {
+
+class PublicKeyVisitor : public NoArgumentsVisitor {
+ public:
+ virtual ndnboost::any visit(DerSequence& );
+};
+
+} // der
+
+}
+
+#endif
diff --git a/ndn-cpp/encoding/der/visitor/simple-visitor.hpp b/ndn-cpp/encoding/der/visitor/simple-visitor.hpp
index 73991f2..3f0584e 100644
--- a/ndn-cpp/encoding/der/visitor/simple-visitor.hpp
+++ b/ndn-cpp/encoding/der/visitor/simple-visitor.hpp
@@ -18,15 +18,15 @@
class SimpleVisitor : public NoArgumentsVisitor
{
public:
- virtual ndnboost::any visit(DerBool& ) = 0;
- virtual ndnboost::any visit(DerInteger& ) = 0;
- virtual ndnboost::any visit(DerPrintableString&) = 0;
- virtual ndnboost::any visit(DerBitString& ) = 0;
- virtual ndnboost::any visit(DerNull& ) = 0;
- virtual ndnboost::any visit(DerOctetString& ) = 0;
- virtual ndnboost::any visit(DerOid& ) = 0;
- virtual ndnboost::any visit(DerSequence& ) = 0;
- virtual ndnboost::any visit(DerGtime& ) = 0;
+ virtual ndnboost::any visit(DerBool& );
+ virtual ndnboost::any visit(DerInteger& );
+ virtual ndnboost::any visit(DerPrintableString&);
+ virtual ndnboost::any visit(DerBitString& );
+ virtual ndnboost::any visit(DerNull& );
+ virtual ndnboost::any visit(DerOctetString& );
+ virtual ndnboost::any visit(DerOid& );
+ virtual ndnboost::any visit(DerSequence& );
+ virtual ndnboost::any visit(DerGtime& );
};
} // der
diff --git a/ndn-cpp/encoding/der/visitor/void-visitor.hpp b/ndn-cpp/encoding/der/visitor/void-visitor.hpp
index 7cd7999..e853ee6 100644
--- a/ndn-cpp/encoding/der/visitor/void-visitor.hpp
+++ b/ndn-cpp/encoding/der/visitor/void-visitor.hpp
@@ -18,15 +18,15 @@
class VoidVisitor
{
public:
- virtual void visit(DerBool&, ndnboost::any) = 0;
- virtual void visit(DerInteger&, ndnboost::any) = 0;
- virtual void visit(DerPrintableString&, ndnboost::any) = 0;
- virtual void visit(DerBitString&, ndnboost::any) = 0;
- virtual void visit(DerNull&, ndnboost::any) = 0;
- virtual void visit(DerOctetString&, ndnboost::any) = 0;
- virtual void visit(DerOid&, ndnboost::any) = 0;
- virtual void visit(DerSequence&, ndnboost::any) = 0;
- virtual void visit(DerGtime&, ndnboost::any) = 0;
+ virtual void visit(DerBool&, ndnboost::any);
+ virtual void visit(DerInteger&, ndnboost::any);
+ virtual void visit(DerPrintableString&, ndnboost::any);
+ virtual void visit(DerBitString&, ndnboost::any);
+ virtual void visit(DerNull&, ndnboost::any);
+ virtual void visit(DerOctetString&, ndnboost::any);
+ virtual void visit(DerOid&, ndnboost::any);
+ virtual void visit(DerSequence&, ndnboost::any);
+ virtual void visit(DerGtime&, ndnboost::any);
};
} // der