security: Added PublicKey and OID classes.
diff --git a/ndn-cpp/security/certificate/oid.cpp b/ndn-cpp/security/certificate/oid.cpp
new file mode 100644
index 0000000..6ae1942
--- /dev/null
+++ b/ndn-cpp/security/certificate/oid.cpp
@@ -0,0 +1,67 @@
+/* -*- 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 <stdlib.h>
+#include <sstream>
+
+#include "oid.hpp"
+
+using namespace std;
+
+namespace ndn {
+
+OID::OID(const string& oid)
+{
+  string str = oid + ".";
+
+  size_t pos = 0;
+  size_t ppos = 0;
+
+  while(string::npos != pos){
+    ppos = pos;
+
+    pos = str.find_first_of('.', pos);
+    if(pos == string::npos)
+	    break;
+
+    oid_.push_back(atoi(str.substr(ppos, pos - ppos).c_str()));
+
+    pos++;
+  }
+}
+
+string OID::toString()
+{
+  ostringstream convert;
+  
+  vector<int>::iterator it = oid_.begin();
+  for(; it < oid_.end(); it++){
+    if(it != oid_.begin())
+      convert << ".";
+    convert << *it;
+  }
+  
+  return convert.str();
+}
+
+bool OID::equal(const OID& oid)
+{
+  vector<int>::const_iterator i = oid_.begin();
+  vector<int>::const_iterator j = oid.oid_.begin();
+    
+  for (; i != oid_.end () && j != oid.oid_.end (); i++, j++) {
+    if(*i != *j)
+      return false;
+  }
+
+  if (i == oid_.end () && j == oid.oid_.end ())
+    return true;
+  else
+    return false;
+}
+
+}
diff --git a/ndn-cpp/security/certificate/oid.hpp b/ndn-cpp/security/certificate/oid.hpp
new file mode 100644
index 0000000..bcbcfe9
--- /dev/null
+++ b/ndn-cpp/security/certificate/oid.hpp
@@ -0,0 +1,62 @@
+/* -*- 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_OID_HPP
+#define	NDN_OID_HPP
+
+#include <vector>
+#include <string>
+
+namespace ndn {
+
+class OID {
+public:
+  OID () 
+  {
+  }
+    
+  OID(const std::string& oid);
+
+  OID(const std::vector<int>& oid)
+  : oid_(oid)
+  {
+  }
+
+  const std::vector<int> &
+  getIntegerList() const
+  {
+    return oid_;
+  }
+
+  void
+  setIntegerList(const std::vector<int>& value){
+    oid_ = value;
+  }
+
+  std::string 
+  toString();
+
+  bool operator == (const OID& oid)
+  {
+    return equal(oid);
+  }
+
+  bool operator != (const OID& oid)
+  {
+    return !equal(oid);
+  }
+  
+private:
+  bool equal(const OID& oid);
+
+  std::vector<int> oid_;
+};
+
+}
+
+#endif
diff --git a/ndn-cpp/security/certificate/public-key.cpp b/ndn-cpp/security/certificate/public-key.cpp
new file mode 100644
index 0000000..1f64c07
--- /dev/null
+++ b/ndn-cpp/security/certificate/public-key.cpp
@@ -0,0 +1,57 @@
+/* -*- 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 "../security-exception.hpp"
+#include "../../c/util/crypto.h"
+#include "public-key.hpp"
+
+using namespace std;
+using namespace ndn::ptr_lib;
+
+namespace ndn {
+
+#if 0
+Ptr<der::DerNode>
+PublicKey::toDER()
+{
+  boost::iostreams::stream
+    <boost::iostreams::array_source> is (m_key.buf (), m_key.size ());
+
+  return der::DerNode::parse(reinterpret_cast<InputIterator &> (is));
+}
+#endif
+
+static int RSA_OID[] = { 1, 2, 840, 113549, 1, 1, 1 };
+
+shared_ptr<PublicKey>
+PublicKey::fromDer(const Blob& keyDer)
+{
+  // Use a temporary pointer since d2i updates it.
+  const unsigned char *derPointer = keyDer.buf();
+  RSA *publicKey = d2i_RSA_PUBKEY(NULL, &derPointer, keyDer.size());
+  if (!publicKey)
+    throw UnrecognizedKeyFormatException("Error decoding public key DER");  
+  RSA_free(publicKey);
+  
+  return shared_ptr<PublicKey>(new PublicKey(OID(vector<int>(RSA_OID, RSA_OID + sizeof(RSA_OID))), keyDer));
+}
+
+Blob
+PublicKey::getDigest(DigestAlgorithm digestAlgorithm) const
+{
+  if (digestAlgorithm == DIGEST_ALGORITHM_SHA256) {
+    unsigned char digest[SHA256_DIGEST_LENGTH];
+    ndn_digestSha256(keyDer_.buf(), keyDer_.size(), digest);
+    
+    return Blob(digest, sizeof(digest));
+  }
+  else
+    throw UnrecognizedDigestAlgorithmException("Wrong format!");
+}
+
+}
diff --git a/ndn-cpp/security/certificate/public-key.hpp b/ndn-cpp/security/certificate/public-key.hpp
new file mode 100644
index 0000000..7db3f49
--- /dev/null
+++ b/ndn-cpp/security/certificate/public-key.hpp
@@ -0,0 +1,72 @@
+/* -*- 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_HPP
+#define	NDN_PUBLIC_KEY_HPP
+
+#include "../../util/blob.hpp"
+#include "oid.hpp"
+#include "../security-common.hpp"
+
+namespace ndn {
+
+class PublicKey {
+public:    
+  /**
+   * The default constructor.
+   */
+  PublicKey() {}
+
+  /**
+   * Constructor
+   * @param algorithm The algorithm of the public key.
+   * @param keyDer The blob of the PublicKeyInfo in terms of DER.
+   */
+  PublicKey(const OID& algorithm, const Blob& keyDer)
+  : algorithm_(algorithm), keyDer_(keyDer)
+  {
+  }
+
+#if 0
+  /**
+   * Encode the public key into DER.
+   * @return the encoded DER syntax tree.
+   */
+  Ptr<der::DerNode>
+  toDer();
+#endif
+
+  /**
+   * Decode the public key from DER blob.
+   * @param keyDer The DER blob.
+   * @return The decoded public key.
+   */
+  static ptr_lib::shared_ptr<PublicKey>
+  fromDer(const Blob& keyDer);
+
+  /*
+   * @brief get the digest of the public key
+   * @param digestAlgorithm The digest algorithm. If omitted, use DIGEST_SHA256 by default.
+   */
+  Blob 
+  getDigest(DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256) const;
+
+  /*
+   * Get the raw bytes of the public key in DER format.
+   */
+  const Blob& 
+  getKeyDer() const { return keyDer_; }
+    
+private:
+  OID algorithm_; /**< Algorithm */
+  Blob keyDer_;   /**< PublicKeyInfo in DER */
+};
+
+}
+
+#endif
diff --git a/ndn-cpp/security/security-exception.cpp b/ndn-cpp/security/security-exception.cpp
new file mode 100644
index 0000000..b4bbd22
--- /dev/null
+++ b/ndn-cpp/security/security-exception.cpp
@@ -0,0 +1,23 @@
+/* -*- 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 "security-exception.hpp"
+using namespace std;
+
+namespace ndn {
+
+SecurityException::SecurityException(const string& errorMessage) throw()
+: errorMessage_(errorMessage)
+{
+}
+
+SecurityException::~SecurityException() throw()
+{
+}
+
+}
diff --git a/ndn-cpp/security/security-exception.hpp b/ndn-cpp/security/security-exception.hpp
new file mode 100644
index 0000000..0a3d20c
--- /dev/null
+++ b/ndn-cpp/security/security-exception.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_SECURITY_EXCEPTION_HPP
+#define	NDN_SECURITY_EXCEPTION_HPP
+
+#include <exception>
+#include <string>
+
+namespace ndn {
+
+class SecurityException : public std::exception {
+public:
+  SecurityException(const std::string& errorMessage) throw();
+    
+  virtual ~SecurityException() throw();
+    
+  inline std::string Msg() { return errorMessage_; }
+    
+private:
+  const std::string errorMessage_;
+};
+
+class UnrecognizedKeyFormatException : public SecurityException {
+public:
+  UnrecognizedKeyFormatException(const std::string& errorMessage)
+  : SecurityException(errorMessage)
+  {
+  }
+};
+
+class UnrecognizedDigestAlgorithmException : public SecurityException {
+public:
+  UnrecognizedDigestAlgorithmException(const std::string& errorMessage)
+  : SecurityException(errorMessage)
+  {
+  }
+};
+
+}
+
+#endif