security: Add key type in PublicKey (in order to support multiple signature type)

Change-Id: Ic3cb7276a3bc6d1d1daf066dbe865503fe66c762
Refs: #1648
Refs: #1649
Refs: #1660
diff --git a/src/security/public-key.cpp b/src/security/public-key.cpp
index ff44dd2..212bc3a 100644
--- a/src/security/public-key.cpp
+++ b/src/security/public-key.cpp
@@ -33,12 +33,15 @@
 namespace ndn {
 
 static OID RSA_OID("1.2.840.113549.1.1.1");
+static OID ECDSA_OID("1.2.840.10045.2.1");
 
 PublicKey::PublicKey()
+  : m_type(KEY_TYPE_NULL)
 {
 }
 
 PublicKey::PublicKey(const uint8_t* keyDerBuf, size_t keyDerSize)
+  : m_type(KEY_TYPE_NULL)
 {
   StringSource src(keyDerBuf, keyDerSize, true);
   decode(src);
@@ -90,8 +93,12 @@
           OID algorithm;
           algorithm.decode(algorithmInfo);
 
-          if (algorithm != RSA_OID)
-            throw Error("Only RSA public keys are supported for now (" +
+          if (algorithm == RSA_OID)
+            m_type = KEY_TYPE_RSA;
+          else if (algorithm == ECDSA_OID)
+            m_type = KEY_TYPE_ECDSA;
+          else
+            throw Error("Only RSA/ECDSA public keys are supported for now (" +
                         algorithm.toString() + " requested)");
         }
       }
@@ -100,6 +107,7 @@
     }
   catch (CryptoPP::BERDecodeErr& err)
     {
+      m_type = KEY_TYPE_NULL;
       throw Error("PublicKey decoding error");
     }
 }
diff --git a/src/security/public-key.hpp b/src/security/public-key.hpp
index 8c2154f..243bccc 100644
--- a/src/security/public-key.hpp
+++ b/src/security/public-key.hpp
@@ -65,38 +65,45 @@
    */
   PublicKey(const uint8_t* keyDerBuf, size_t keyDerSize);
 
-  inline const Buffer&
+  const Buffer&
   get() const
   {
     return m_key;
   }
 
-  inline void
+  void
   set(const uint8_t* keyDerBuf, size_t keyDerSize)
   {
     Buffer buf(keyDerBuf, keyDerSize);
     m_key.swap(buf);
   }
 
+  KeyType
+  getKeyType() const
+  {
+    return m_type;
+  }
+
   void
   encode(CryptoPP::BufferedTransformation& out) const;
 
   void
   decode(CryptoPP::BufferedTransformation& in);
 
-  inline bool
+  bool
   operator==(const PublicKey& key) const
   {
     return m_key == key.m_key;
   }
 
-  inline bool
+  bool
   operator!=(const PublicKey& key) const
   {
     return m_key != key.m_key;
   }
 
 private:
+  KeyType m_type;
   Buffer m_key;
 };
 
diff --git a/src/security/security-common.hpp b/src/security/security-common.hpp
index 24c424b..072ea74 100644
--- a/src/security/security-common.hpp
+++ b/src/security/security-common.hpp
@@ -26,11 +26,13 @@
 
 enum KeyType {
   KEY_TYPE_RSA,
+  KEY_TYPE_ECDSA,
   // KEY_TYPE_DSA,
-  KEY_TYPE_AES
+  KEY_TYPE_AES,
   // KEY_TYPE_DES,
   // KEY_TYPE_RC4,
   // KEY_TYPE_RC2
+  KEY_TYPE_NULL
 };
 
 enum KeyClass {