security: Added headers for der encoding.  Added CertificateExtension and CertificateSubjectDescription.
diff --git a/ndn-cpp/encoding/der/der.hpp b/ndn-cpp/encoding/der/der.hpp
new file mode 100644
index 0000000..82089d6
--- /dev/null
+++ b/ndn-cpp/encoding/der/der.hpp
@@ -0,0 +1,385 @@
+/* -*- 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_DER_HPP
+#define NDN_DER_HPP
+
+#include <vector>
+#include <string>
+#include <istream>
+#include <ostream>
+#include <sstream>
+
+#include <ndn-cpp/common.hpp>
+#include <ndn-cpp/encoding/oid.hpp>
+
+#include "visitor/visitor.hpp"
+#include "visitor/void-visitor.hpp"
+#include "visitor/no-arguments-visitor.hpp"
+#include "visitor/void-no-arguments-visitor.hpp"
+
+namespace ndn {
+
+// TODO: Implement Time values.
+class Time;
+
+namespace der {
+
+enum DerType {
+  DER_EOC = 0,
+  DER_BOOLEAN = 1,
+  DER_INTEGER = 2,
+  DER_BIT_STRING = 3,
+  DER_OCTET_STRING = 4,
+  DER_NULL = 5,
+  DER_OBJECT_IDENTIFIER = 6,
+  DER_OBJECT_DESCRIPTOR = 7,
+  DER_EXTERNAL = 40,
+  DER_REAL = 9,
+  DER_ENUMERATED = 10,
+  DER_EMBEDDED_PDV = 43,
+  DER_UTF8_STRING = 12,
+  DER_RELATIVE_OID = 13,
+  DER_SEQUENCE = 48,
+  DER_SET = 49,
+  DER_NUMERIC_STRING = 18,
+  DER_PRINTABLE_STRING = 19,
+  DER_T61_STRING = 20,
+  DER_VIDEOTEX_STRING = 21,
+  DER_IA5_STRING = 22,
+  DER_UTC_TIME = 23,
+  DER_GENERALIZED_TIME = 24,
+  DER_GRAPHIC_STRING = 25,
+  DER_VISIBLE_STRING = 26,
+  DER_GENERAL_STRING = 27,
+  DER_UNIVERSAL_STRING = 28,
+  DER_CHARACTER_STRING = 29,
+  DER_BMP_STRING = 30,
+};
+
+class DerComplex;
+
+class DerNode
+{
+public:
+  DerNode();
+
+  DerNode(DerType type);
+
+  DerNode(std::istream& start);
+
+  virtual
+  ~DerNode();
+
+  virtual int
+  getSize() { return m_header.size() + m_payload.size(); }
+
+  virtual void 
+  encode(std::ostream& start);
+  
+  void
+  setParent(DerComplex * parent) { m_parent = parent; }
+
+  static ptr_lib::shared_ptr<DerNode>
+  parse(std::istream& start);
+
+  const std::vector<uint8_t>& 
+  getHeader() const { return m_header; }
+
+  std::vector<uint8_t>& 
+  getHeader() { return m_header; }
+
+  const std::vector<uint8_t>& 
+  getPayload() const { return m_payload; }
+  
+  std::vector<uint8_t>& 
+  getPayload() { return m_payload; }
+
+  const DerType& 
+  getType() { return m_type; }
+
+  virtual ptr_lib::shared_ptr<std::vector<uint8_t> >
+  getRaw()
+  { 
+    ptr_lib::shared_ptr<std::vector<uint8_t> > blob(new std::vector<uint8_t>());
+    blob->insert(blob->end(), m_header.begin(), m_header.end());
+    blob->insert(blob->end(), m_payload.begin(), m_payload.end());
+
+    return blob;
+  }
+
+  virtual void accept(VoidNoArgumentsVisitor& visitor) = 0;
+  virtual void accept(VoidVisitor& visitor, Any param) = 0;
+  virtual Any accept(NoArgumentsVisitor& visitor) = 0;
+  virtual Any accept(Visitor& visitor, Any param) = 0;
+  
+protected:
+  void
+  decode(std::istream& start);
+
+  void
+  encodeHeader(int size);
+
+  int 
+  decodeHeader(std::istream& start);
+
+protected:
+  DerType m_type;
+  std::vector<uint8_t> m_header;
+  std::vector<uint8_t> m_payload;
+  DerComplex * m_parent;
+};
+
+
+typedef std::vector<ptr_lib::shared_ptr<DerNode> > DerNodePtrList;
+
+class DerComplex : public DerNode
+{
+public:
+  DerComplex();
+  
+  DerComplex(DerType type);
+
+  DerComplex(std::istream& start);
+
+  virtual 
+  ~DerComplex();
+
+  virtual int
+  getSize();
+
+  void 
+  addChild(ptr_lib::shared_ptr<DerNode> nodePtr, bool notifyParent = true);
+
+  virtual void
+  encode(std::ostream& start);
+
+  const DerNodePtrList& 
+  getChildren() const { return m_nodeList; }
+
+  DerNodePtrList& 
+  getChildren() { return m_nodeList; }
+
+  virtual ptr_lib::shared_ptr<std::vector<uint8_t> >
+  getRaw();
+
+private:
+  void
+  updateSize();
+
+  void
+  setChildChanged();
+
+private:
+  bool m_childChanged;
+  int m_size;
+  DerNodePtrList m_nodeList;
+};
+
+
+
+class DerByteString : public DerNode
+{
+public:
+  DerByteString(const std::string& str, DerType type);
+
+  DerByteString(const std::vector<uint8_t>& blob, DerType type);
+
+  DerByteString(std::istream& start);
+
+  virtual
+  ~DerByteString();
+};
+
+
+//0x01  
+class DerBool : public DerNode
+{
+public:
+  DerBool(bool value);
+
+  DerBool(std::istream& start);
+
+  virtual
+  ~DerBool();
+
+  virtual void accept(VoidNoArgumentsVisitor& visitor) {        visitor.visit(*this);        }
+  virtual void accept(VoidVisitor& visitor, Any param) {        visitor.visit(*this, param); }
+  virtual Any accept(NoArgumentsVisitor& visitor)      { return visitor.visit(*this);        }
+  virtual Any accept(Visitor& visitor, Any param)      { return visitor.visit(*this, param); }
+
+};
+
+//0x02  
+class DerInteger : public DerNode
+{
+public:
+  DerInteger(const std::vector<uint8_t>& blob);
+
+  DerInteger(std::istream& start);
+
+  virtual 
+  ~DerInteger();
+
+  virtual void accept(VoidNoArgumentsVisitor& visitor) {        visitor.visit(*this);        }
+  virtual void accept(VoidVisitor& visitor, Any param) {        visitor.visit(*this, param); }
+  virtual Any accept(NoArgumentsVisitor& visitor)      { return visitor.visit(*this);        }
+  virtual Any accept(Visitor& visitor, Any param)      { return visitor.visit(*this, param); }
+
+};
+
+//0x03
+class DerBitString : public DerNode
+{
+public:
+  DerBitString(const std::vector<uint8_t>& blob, uint8_t paddingLen);
+
+  DerBitString(std::istream& start);
+  
+  virtual
+  ~DerBitString();
+
+  virtual void accept(VoidNoArgumentsVisitor& visitor) {        visitor.visit(*this);        }
+  virtual void accept(VoidVisitor& visitor, Any param) {        visitor.visit(*this, param); }
+  virtual Any accept(NoArgumentsVisitor& visitor)      { return visitor.visit(*this);        }
+  virtual Any accept(Visitor& visitor, Any param)      { return visitor.visit(*this, param); }
+
+};
+
+//0x04
+class DerOctetString : public DerByteString
+{
+public:
+  DerOctetString(const std::string& str);
+  
+  DerOctetString(const std::vector<uint8_t>& blob);
+
+  DerOctetString(std::istream& start);
+
+  virtual
+  ~DerOctetString();
+
+  virtual void accept(VoidNoArgumentsVisitor& visitor) {        visitor.visit(*this);        }
+  virtual void accept(VoidVisitor& visitor, Any param) {        visitor.visit(*this, param); }
+  virtual Any accept(NoArgumentsVisitor& visitor)      { return visitor.visit(*this);        }
+  virtual Any accept(Visitor& visitor, Any param)      { return visitor.visit(*this, param); }
+
+};
+
+
+//0x05
+class DerNull : public DerNode
+{
+public:
+  DerNull();
+
+  DerNull(std::istream& start);
+  
+  virtual
+  ~DerNull();
+
+  virtual void accept(VoidNoArgumentsVisitor& visitor) {        visitor.visit(*this);        }
+  virtual void accept(VoidVisitor& visitor, Any param) {        visitor.visit(*this, param); }
+  virtual Any accept(NoArgumentsVisitor& visitor)      { return visitor.visit(*this);        }
+  virtual Any accept(Visitor& visitor, Any param)      { return visitor.visit(*this, param); }
+
+};
+
+
+//0x06
+class DerOid : public DerNode
+{
+public:
+  DerOid(const OID& oid);
+  
+  DerOid(const std::string& oidStr);
+
+  DerOid(const std::vector<int>& value);
+
+  DerOid(std::istream& start);
+  
+  virtual
+  ~DerOid();
+  
+  virtual void accept(VoidNoArgumentsVisitor& visitor) {        visitor.visit(*this);        }
+  virtual void accept(VoidVisitor& visitor, Any param) {        visitor.visit(*this, param); }
+  virtual Any accept(NoArgumentsVisitor& visitor)      { return visitor.visit(*this);        }
+  virtual Any accept(Visitor& visitor, Any param)      { return visitor.visit(*this, param); }
+
+  int 
+  decode128(int& offset);
+
+private:
+  void 
+  prepareEncoding(const std::vector<int>& value);
+
+  void 
+  encode128(int value, std::ostringstream& os);    
+};
+
+
+//0x10
+class DerSequence : public DerComplex
+{
+public:
+  DerSequence();
+
+  DerSequence(std::istream& start);
+  
+  virtual
+  ~DerSequence();
+
+  virtual void accept(VoidNoArgumentsVisitor& visitor) {        visitor.visit(*this);        }
+  virtual void accept(VoidVisitor& visitor, Any param) {        visitor.visit(*this, param); }
+  virtual Any accept(NoArgumentsVisitor& visitor)      { return visitor.visit(*this);        }
+  virtual Any accept(Visitor& visitor, Any param)      { return visitor.visit(*this, param); }
+
+};
+
+//0x13
+class DerPrintableString : public DerByteString
+{
+public:
+  DerPrintableString(const std::string& str);
+
+  DerPrintableString(const std::vector<uint8_t>& blob);
+
+  DerPrintableString(std::istream& start);
+
+  virtual 
+  ~DerPrintableString();
+
+  virtual void accept(VoidNoArgumentsVisitor& visitor) {        visitor.visit(*this);        }
+  virtual void accept(VoidVisitor& visitor, Any param) {        visitor.visit(*this, param); }
+  virtual Any accept(NoArgumentsVisitor& visitor)      { return visitor.visit(*this);        }
+  virtual Any accept(Visitor& visitor, Any param)      { return visitor.visit(*this, param); }
+};
+
+//0x1b
+class DerGtime : public DerNode
+{
+public:
+  DerGtime(const Time& time);
+
+  DerGtime(std::istream& start);
+  
+  virtual 
+  ~DerGtime();
+
+  virtual void accept(VoidNoArgumentsVisitor& visitor) {        visitor.visit(*this);        }
+  virtual void accept(VoidVisitor& visitor, Any param) {        visitor.visit(*this, param); }
+  virtual Any accept(NoArgumentsVisitor& visitor)      { return visitor.visit(*this);        }
+  virtual Any accept(Visitor& visitor, Any param)      { return visitor.visit(*this, param); }
+
+};
+ 
+} // der
+
+}
+
+#endif
diff --git a/ndn-cpp/encoding/der/visitor/no-arguments-visitor.hpp b/ndn-cpp/encoding/der/visitor/no-arguments-visitor.hpp
new file mode 100644
index 0000000..61b0a65
--- /dev/null
+++ b/ndn-cpp/encoding/der/visitor/no-arguments-visitor.hpp
@@ -0,0 +1,36 @@
+/* -*- 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_DER_NO_ARGUMENTS_VISITOR_HPP
+#define NDN_DER_NO_ARGUMENTS_VISITOR_HPP
+
+#include "visitor.hpp"
+
+namespace ndn {
+
+namespace der {
+
+class NoArgumentsVisitor
+{
+public:
+  virtual Any visit(DerBool&           ) = 0;
+  virtual Any visit(DerInteger&        ) = 0;
+  virtual Any visit(DerPrintableString&) = 0;
+  virtual Any visit(DerBitString&      ) = 0;
+  virtual Any visit(DerNull&           ) = 0;
+  virtual Any visit(DerOctetString&    ) = 0;
+  virtual Any visit(DerOid&            ) = 0;
+  virtual Any visit(DerSequence&       ) = 0;
+  virtual Any visit(DerGtime&          ) = 0;
+};
+
+} // der
+
+}
+
+#endif
diff --git a/ndn-cpp/encoding/der/visitor/simple-visitor.hpp b/ndn-cpp/encoding/der/visitor/simple-visitor.hpp
new file mode 100644
index 0000000..4ec3a8c
--- /dev/null
+++ b/ndn-cpp/encoding/der/visitor/simple-visitor.hpp
@@ -0,0 +1,36 @@
+/* -*- 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_DER_SIMPLE_VISITOR_HPP
+#define NDN_DER_SIMPLE_VISITOR_HPP
+
+#include "no-arguments-visitor.hpp"
+
+namespace ndn {
+
+namespace der {
+
+class NoArgumentsVisitor : public NoArgumentsVisitor
+{
+public:
+  virtual Any visit(DerBool&           ) = 0;
+  virtual Any visit(DerInteger&        ) = 0;
+  virtual Any visit(DerPrintableString&) = 0;
+  virtual Any visit(DerBitString&      ) = 0;
+  virtual Any visit(DerNull&           ) = 0;
+  virtual Any visit(DerOctetString&    ) = 0;
+  virtual Any visit(DerOid&            ) = 0;
+  virtual Any visit(DerSequence&       ) = 0;
+  virtual Any visit(DerGtime&          ) = 0;
+};
+
+} // der
+
+}
+
+#endif
diff --git a/ndn-cpp/encoding/der/visitor/visitor.hpp b/ndn-cpp/encoding/der/visitor/visitor.hpp
new file mode 100644
index 0000000..a251701
--- /dev/null
+++ b/ndn-cpp/encoding/der/visitor/visitor.hpp
@@ -0,0 +1,47 @@
+/* -*- 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_DER_VISITOR_HPP
+#define NDN_DER_VISITOR_HPP
+
+namespace ndn {
+
+namespace der {
+  
+// TODO: We want to implement an any type, but avoid boost::any which is not in the C++ standard library.
+typedef void *Any;
+
+class DerBool;
+class DerInteger;
+class DerPrintableString;
+class DerBitString;
+class DerNull;
+class DerOctetString;
+class DerOid;
+class DerSequence;
+class DerGtime;
+
+class Visitor
+{
+public:
+  virtual Any visit(DerBool&,             Any) = 0;
+  virtual Any visit(DerInteger&,          Any) = 0;
+  virtual Any visit(DerPrintableString&,  Any) = 0;
+  virtual Any visit(DerBitString&,        Any) = 0;
+  virtual Any visit(DerNull&,             Any) = 0;
+  virtual Any visit(DerOctetString&,      Any) = 0;
+  virtual Any visit(DerOid&,              Any) = 0;
+  virtual Any visit(DerSequence&,         Any) = 0;
+  virtual Any visit(DerGtime&,            Any) = 0;
+};
+
+} // der
+
+}
+
+#endif
diff --git a/ndn-cpp/encoding/der/visitor/void-no-arguments-visitor.hpp b/ndn-cpp/encoding/der/visitor/void-no-arguments-visitor.hpp
new file mode 100644
index 0000000..7e60d38
--- /dev/null
+++ b/ndn-cpp/encoding/der/visitor/void-no-arguments-visitor.hpp
@@ -0,0 +1,36 @@
+/* -*- 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_DER_VOID_NO_ARGUMENTS_VISITOR_HPP
+#define NDN_DER_VOID_NO_ARGUMENTS_VISITOR_HPP
+
+#include "visitor.hpp"
+
+namespace ndn {
+
+namespace der {
+
+class VoidNoArgumentsVisitor
+{
+public:
+  virtual void visit(DerBool&           ) = 0;
+  virtual void visit(DerInteger&        ) = 0;
+  virtual void visit(DerPrintableString&) = 0;
+  virtual void visit(DerBitString&      ) = 0;
+  virtual void visit(DerNull&           ) = 0;
+  virtual void visit(DerOctetString&    ) = 0;
+  virtual void visit(DerOid&            ) = 0;
+  virtual void visit(DerSequence&       ) = 0;
+  virtual void visit(DerGtime&          ) = 0;
+};
+
+} // der
+
+}
+
+#endif
diff --git a/ndn-cpp/encoding/der/visitor/void-visitor.hpp b/ndn-cpp/encoding/der/visitor/void-visitor.hpp
new file mode 100644
index 0000000..a041c10
--- /dev/null
+++ b/ndn-cpp/encoding/der/visitor/void-visitor.hpp
@@ -0,0 +1,36 @@
+/* -*- 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_DER_VOID_VISITOR_HPP
+#define NDN_DER_VOID_VISITOR_HPP
+
+#include "visitor.hpp"
+
+namespace ndn {
+
+namespace der {
+
+class VoidVisitor
+{
+public:
+  virtual void visit(DerBool&,             Any) = 0;
+  virtual void visit(DerInteger&,          Any) = 0;
+  virtual void visit(DerPrintableString&,  Any) = 0;
+  virtual void visit(DerBitString&,        Any) = 0;
+  virtual void visit(DerNull&,             Any) = 0;
+  virtual void visit(DerOctetString&,      Any) = 0;
+  virtual void visit(DerOid&,              Any) = 0;
+  virtual void visit(DerSequence&,         Any) = 0;
+  virtual void visit(DerGtime&,            Any) = 0;
+};
+
+} // der
+
+}
+
+#endif
diff --git a/ndn-cpp/security/certificate/certificate-extension.cpp b/ndn-cpp/security/certificate/certificate-extension.cpp
new file mode 100644
index 0000000..9f6c39a
--- /dev/null
+++ b/ndn-cpp/security/certificate/certificate-extension.cpp
@@ -0,0 +1,50 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Jeff Thompson <jefft0@remap.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "../../encoding/der/der.hpp"
+#include <ndn-cpp/security/certificate/certificate-extension.hpp>
+
+using namespace std;
+using namespace ndn::ptr_lib;
+
+namespace ndn {
+
+shared_ptr<der::DerNode> 
+CertificateExtension::toDer()
+{
+  shared_ptr<der::DerSequence> root(new der::DerSequence);
+    
+  shared_ptr<der::DerOid> extensionId(new der::DerOid(extensionId_));
+  shared_ptr<der::DerBool> isCritical(new der::DerBool(isCritical_));
+  shared_ptr<der::DerOctetString> extensionValue(new der::DerOctetString(*extensionValue_));
+
+  root->addChild(extensionId);
+  root->addChild(isCritical);
+  root->addChild(extensionValue);
+
+  root->getSize();
+
+  return root;
+}
+
+Blob
+CertificateExtension::toDerBlob()
+{
+#if 0 // Need to convert blob_stream.
+  blob_stream blobStream;
+  ostream& start = reinterpret_cast<ostream&>(blobStream);
+
+  toDer()->encode(start);
+
+  return blobStream.buf();
+#else
+  throw std::runtime_error("not implemented");
+#endif
+}
+
+
+}
diff --git a/ndn-cpp/security/certificate/certificate-subject-description.cpp b/ndn-cpp/security/certificate/certificate-subject-description.cpp
new file mode 100644
index 0000000..ee2310c
--- /dev/null
+++ b/ndn-cpp/security/certificate/certificate-subject-description.cpp
@@ -0,0 +1,31 @@
+/* -*- 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 "../../encoding/der/der.hpp"
+#include <ndn-cpp/security/certificate/certificate-subject-description.hpp>
+
+using namespace std;
+using namespace ndn::ptr_lib;
+
+namespace ndn {
+
+shared_ptr<der::DerNode> 
+CertificateSubjectDescription::toDer()
+{
+  shared_ptr<der::DerSequence> root(new der::DerSequence());
+
+  shared_ptr<der::DerOid> oid(new der::DerOid(oid_));
+  shared_ptr<der::DerPrintableString> value(new der::DerPrintableString(value_));
+
+  root->addChild(oid);
+  root->addChild(value);
+
+  return root;
+}
+
+}