DER encoding: Added CertificateDataVisitor and use in Certificate::decode.
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(""));