DER encoding: Added CertificateDataVisitor and use in Certificate::decode.
diff --git a/Makefile.am b/Makefile.am
index eced317..89c5386 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -119,7 +119,9 @@
ndn-cpp/encoding/wire-format.cpp \
ndn-cpp/encoding/der/der-exception.cpp ndn-cpp/encoding/der/der-exception.hpp \
ndn-cpp/encoding/der/der.cpp ndn-cpp/encoding/der/der.hpp \
+ ndn-cpp/encoding/der/visitor/certificate-data-visitor.cpp ndn-cpp/encoding/der/visitor/certificate-data-visitor.hpp \
ndn-cpp/encoding/der/visitor/no-arguments-visitor.cpp ndn-cpp/encoding/der/visitor/no-arguments-visitor.hpp \
+ ndn-cpp/encoding/der/visitor/public-key-visitor.cpp ndn-cpp/encoding/der/visitor/public-key-visitor.hpp \
ndn-cpp/encoding/der/visitor/simple-visitor.cpp ndn-cpp/encoding/der/visitor/simple-visitor.hpp \
ndn-cpp/encoding/der/visitor/visitor.hpp \
ndn-cpp/encoding/der/visitor/void-no-arguments-visitor.hpp \
diff --git a/Makefile.in b/Makefile.in
index 0958a1a..5a8aa9d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -186,7 +186,9 @@
ndn-cpp/encoding/wire-format.lo \
ndn-cpp/encoding/der/der-exception.lo \
ndn-cpp/encoding/der/der.lo \
+ ndn-cpp/encoding/der/visitor/certificate-data-visitor.lo \
ndn-cpp/encoding/der/visitor/no-arguments-visitor.lo \
+ ndn-cpp/encoding/der/visitor/public-key-visitor.lo \
ndn-cpp/encoding/der/visitor/simple-visitor.lo \
ndn-cpp/encoding/der/visitor/void-visitor.lo \
ndn-cpp/security/key-chain.lo \
@@ -668,7 +670,9 @@
ndn-cpp/encoding/wire-format.cpp \
ndn-cpp/encoding/der/der-exception.cpp ndn-cpp/encoding/der/der-exception.hpp \
ndn-cpp/encoding/der/der.cpp ndn-cpp/encoding/der/der.hpp \
+ ndn-cpp/encoding/der/visitor/certificate-data-visitor.cpp ndn-cpp/encoding/der/visitor/certificate-data-visitor.hpp \
ndn-cpp/encoding/der/visitor/no-arguments-visitor.cpp ndn-cpp/encoding/der/visitor/no-arguments-visitor.hpp \
+ ndn-cpp/encoding/der/visitor/public-key-visitor.cpp ndn-cpp/encoding/der/visitor/public-key-visitor.hpp \
ndn-cpp/encoding/der/visitor/simple-visitor.cpp ndn-cpp/encoding/der/visitor/simple-visitor.hpp \
ndn-cpp/encoding/der/visitor/visitor.hpp \
ndn-cpp/encoding/der/visitor/void-no-arguments-visitor.hpp \
@@ -916,9 +920,15 @@
ndn-cpp/encoding/der/visitor/$(DEPDIR)/$(am__dirstamp):
@$(MKDIR_P) ndn-cpp/encoding/der/visitor/$(DEPDIR)
@: > ndn-cpp/encoding/der/visitor/$(DEPDIR)/$(am__dirstamp)
+ndn-cpp/encoding/der/visitor/certificate-data-visitor.lo: \
+ ndn-cpp/encoding/der/visitor/$(am__dirstamp) \
+ ndn-cpp/encoding/der/visitor/$(DEPDIR)/$(am__dirstamp)
ndn-cpp/encoding/der/visitor/no-arguments-visitor.lo: \
ndn-cpp/encoding/der/visitor/$(am__dirstamp) \
ndn-cpp/encoding/der/visitor/$(DEPDIR)/$(am__dirstamp)
+ndn-cpp/encoding/der/visitor/public-key-visitor.lo: \
+ ndn-cpp/encoding/der/visitor/$(am__dirstamp) \
+ ndn-cpp/encoding/der/visitor/$(DEPDIR)/$(am__dirstamp)
ndn-cpp/encoding/der/visitor/simple-visitor.lo: \
ndn-cpp/encoding/der/visitor/$(am__dirstamp) \
ndn-cpp/encoding/der/visitor/$(DEPDIR)/$(am__dirstamp)
@@ -1136,7 +1146,9 @@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/encoding/$(DEPDIR)/wire-format.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/encoding/der/$(DEPDIR)/der-exception.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/encoding/der/$(DEPDIR)/der.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/encoding/der/visitor/$(DEPDIR)/certificate-data-visitor.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/encoding/der/visitor/$(DEPDIR)/no-arguments-visitor.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/encoding/der/visitor/$(DEPDIR)/public-key-visitor.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/encoding/der/visitor/$(DEPDIR)/simple-visitor.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/encoding/der/visitor/$(DEPDIR)/void-visitor.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@ndn-cpp/security/$(DEPDIR)/key-chain.Plo@am__quote@
diff --git a/include/ndn-cpp/security/certificate/certificate-extension.hpp b/include/ndn-cpp/security/certificate/certificate-extension.hpp
index d71086b..c67434d 100644
--- a/include/ndn-cpp/security/certificate/certificate-extension.hpp
+++ b/include/ndn-cpp/security/certificate/certificate-extension.hpp
@@ -27,9 +27,9 @@
* Create a new CertificateExtension.
* @param oid The oid of subject description entry.
* @param isCritical If true, the extension must be handled.
- * @param value The extension value. This makes a copy of the value.
+ * @param value The extension value.
*/
- CertificateExtension(const std::string& oid, const bool isCritical, const std::vector<uint8_t>& value)
+ CertificateExtension(const std::string& oid, const bool isCritical, const Blob& value)
: extensionId_(oid), isCritical_(isCritical), extensionValue_(value)
{
}
@@ -38,9 +38,9 @@
* Create a new CertificateExtension.
* @param oid The oid of subject description entry.
* @param isCritical If true, the extension must be handled.
- * @param value The extension value. This makes a copy of the value.
+ * @param value The extension value.
*/
- CertificateExtension(const OID& oid, const bool isCritical, const std::vector<uint8_t>& value)
+ CertificateExtension(const OID& oid, const bool isCritical, const Blob& value)
: extensionId_(oid), isCritical_(isCritical), extensionValue_(value)
{
}
diff --git a/ndn-cpp/encoding/der/der.cpp b/ndn-cpp/encoding/der/der.cpp
index 419ffae..e569819 100644
--- a/ndn-cpp/encoding/der/der.cpp
+++ b/ndn-cpp/encoding/der/der.cpp
@@ -213,7 +213,7 @@
return size_ + header_.size();
}
-shared_ptr<vector<uint8_t> >
+Blob
DerComplex::getRaw()
{
shared_ptr<vector<uint8_t> > blob(new vector<uint8_t>());
@@ -221,7 +221,7 @@
DerNodePtrList::iterator it = nodeList_.begin();
for (; it != nodeList_.end(); it++) {
- shared_ptr<vector<uint8_t> > childBlob = (*it)->getRaw();
+ Blob childBlob = (*it)->getRaw();
blob->insert(blob->end(), childBlob->begin(), childBlob->end());
}
return blob;
diff --git a/ndn-cpp/encoding/der/der.hpp b/ndn-cpp/encoding/der/der.hpp
index a02a2e9..d8753be 100644
--- a/ndn-cpp/encoding/der/der.hpp
+++ b/ndn-cpp/encoding/der/der.hpp
@@ -17,6 +17,7 @@
#include <ndn-cpp/common.hpp>
#include <ndn-cpp/encoding/oid.hpp>
+#include <ndn-cpp/util/blob.hpp>
#include "visitor/visitor.hpp"
#include "visitor/void-visitor.hpp"
@@ -117,7 +118,7 @@
const DerType&
getType() { return type_; }
- virtual ptr_lib::shared_ptr<std::vector<uint8_t> >
+ virtual Blob
getRaw()
{
ptr_lib::shared_ptr<std::vector<uint8_t> > blob(new std::vector<uint8_t>());
@@ -179,7 +180,7 @@
DerNodePtrList&
getChildren() { return nodeList_; }
- virtual ptr_lib::shared_ptr<std::vector<uint8_t> >
+ virtual Blob
getRaw();
private:
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
diff --git a/ndn-cpp/security/certificate/certificate.cpp b/ndn-cpp/security/certificate/certificate.cpp
index 73f60d3..b41b739 100644
--- a/ndn-cpp/security/certificate/certificate.cpp
+++ b/ndn-cpp/security/certificate/certificate.cpp
@@ -7,13 +7,13 @@
*/
#include <float.h>
-#if 0
+// We can use ndnboost::iostreams because this is internal and will not conflict with the application if it uses boost::iostreams.
#include <ndnboost/iostreams/stream.hpp>
#include <ndnboost/iostreams/device/array.hpp>
-#endif
#include <ndn-cpp/sha256-with-rsa-signature.hpp>
-#if 0
+#include "../../encoding/der/der.hpp"
#include "../../encoding/der/visitor/certificate-data-visitor.hpp"
+#if 0
#include "../../encoding/der/visitor/print-visitor.hpp"
#endif
#include "../../util/logging.hpp"
@@ -70,32 +70,32 @@
void
Certificate::encode()
{
- Ptr<der::DerSequence> root = Ptr<der::DerSequence>::Create();
+ shared_ptr<der::DerSequence> root(new der::DerSequence());
- Ptr<der::DerSequence> validity = Ptr<der::DerSequence>::Create();
- Ptr<der::DerGtime> notBefore = Ptr<der::DerGtime>(new der::DerGtime(notBefore_));
- Ptr<der::DerGtime> notAfter = Ptr<der::DerGtime>(new der::DerGtime(notAfter_));
+ shared_ptr<der::DerSequence> validity(new der::DerSequence());
+ shared_ptr<der::DerGtime> notBefore(new der::DerGtime(notBefore_));
+ shared_ptr<der::DerGtime> notAfter(new der::DerGtime(notAfter_));
validity->addChild(notBefore);
validity->addChild(notAfter);
root->addChild(validity);
- Ptr<der::DerSequence> subjectList = Ptr<der::DerSequence>::Create();
- SubDescryptList::iterator it = m_subjectList.begin();
- for(; it != m_subjectList.end(); it++)
+ shared_ptr<der::DerSequence> subjectList(new der::DerSequence());
+ SubjectDescriptionList::iterator it = subjectDescriptionList_.begin();
+ for(; it != subjectDescriptionList_.end(); it++)
{
- Ptr<der::DerNode> child = it->toDER();
+ shared_ptr<der::DerNode> child = it->toDer();
subjectList->addChild(child);
}
root->addChild(subjectList);
- root->addChild(key_.toDER());
+ root->addChild(key_.toDer());
- if(!m_extnList.empty())
+ if(!extensionList_.empty())
{
- Ptr<der::DerSequence> extnList = Ptr<der::DerSequence>::Create();
- ExtensionList::iterator it = m_extnList.begin();
- for(; it != m_extnList.end(); it++)
- extnList->addChild(it->toDER());
+ shared_ptr<der::DerSequence> extnList(new der::DerSequence());
+ ExtensionList::iterator it = extensionList_.begin();
+ for(; it != extensionList_.end(); it++)
+ extnList->addChild(it->toDer());
root->addChild(extnList);
}
@@ -104,7 +104,7 @@
root->encode(start);
- Ptr<Blob> blob = blobStream.buf();
+ shared_ptr<Blob> blob = blobStream.buf();
Content content(blob->buf(), blob->size());
setContent(content);
}
@@ -113,19 +113,17 @@
void
Certificate::decode()
{
-#if 0
Blob blob = getContent();
ndnboost::iostreams::stream<ndnboost::iostreams::array_source> is((const char*)blob.buf(), blob.size());
- shared_ptr<der::DerNode> node = der::DerNode::parse(reinterpret_cast<InputIterator&>(is));
+ shared_ptr<der::DerNode> node = der::DerNode::parse(reinterpret_cast<der::InputIterator&>(is));
// der::PrintVisitor printVisitor;
// node->accept(printVisitor, string(""));
der::CertificateDataVisitor certDataVisitor;
node->accept(certDataVisitor, this);
-#endif
}
#if 0
@@ -145,7 +143,7 @@
boost::iostreams::stream
<boost::iostreams::array_source> is(key_.getKeyBlob().buf (), m_key.getKeyBlob().size ());
- Ptr<der::DerNode> keyRoot = der::DerNode::parse(reinterpret_cast<InputIterator&> (is));
+ shared_ptr<der::DerNode> keyRoot = der::DerNode::parse(reinterpret_cast<InputIterator&> (is));
der::PrintVisitor printVisitor;
keyRoot->accept(printVisitor, string(""));