security: Add interface to request different key id generation

The option for key id include timestamp, random, and user-specified
value.

This commit only adds the interface, the support to honor the interface
will be implemented later.

Change-Id: I476381ff0fc56cd7906392cb7482b7458e386781
Refs: #2948
diff --git a/tests/unit-tests/security/key-params.t.cpp b/tests/unit-tests/security/key-params.t.cpp
index a1fefa4..f8efed1 100644
--- a/tests/unit-tests/security/key-params.t.cpp
+++ b/tests/unit-tests/security/key-params.t.cpp
@@ -23,6 +23,8 @@
 
 #include "boost-test.hpp"
 
+#include <boost/lexical_cast.hpp>
+
 namespace ndn {
 namespace tests {
 
@@ -34,14 +36,21 @@
   RsaKeyParams params;
   BOOST_CHECK_EQUAL(params.getKeyType(), KeyType::RSA);
   BOOST_CHECK_EQUAL(params.getKeySize(), 2048);
+  BOOST_CHECK(params.getKeyIdType() == KeyIdType::RANDOM);
 
-  RsaKeyParams params2(1024);
+  RsaKeyParams params2(1024, KeyIdType::SHA256);
   BOOST_CHECK_EQUAL(params2.getKeyType(), KeyType::RSA);
   BOOST_CHECK_EQUAL(params2.getKeySize(), 1024);
+  BOOST_CHECK(params2.getKeyIdType() == KeyIdType::SHA256);
 
-  RsaKeyParams params3(3);
-  BOOST_CHECK_EQUAL(params3.getKeyType(), KeyType::RSA);
-  BOOST_CHECK_EQUAL(params3.getKeySize(), 2048);
+  BOOST_CHECK_THROW(RsaKeyParams(3), KeyParams::Error);
+
+  name::Component keyId("keyId");
+  RsaKeyParams params4(keyId);
+  BOOST_CHECK(params4.getKeyType() == KeyType::RSA);
+  BOOST_CHECK_EQUAL(params4.getKeySize(), 2048);
+  BOOST_CHECK(params4.getKeyIdType() == KeyIdType::USER_SPECIFIED);
+  BOOST_CHECK_EQUAL(params4.getKeyId(), keyId);
 }
 
 BOOST_AUTO_TEST_CASE(Ecdsa)
@@ -49,44 +58,59 @@
   EcdsaKeyParams params;
   BOOST_CHECK_EQUAL(params.getKeyType(), KeyType::EC);
   BOOST_CHECK_EQUAL(params.getKeySize(), 256);
+  BOOST_CHECK(params.getKeyIdType() == KeyIdType::RANDOM);
 
-  EcdsaKeyParams params2(384);
+  EcdsaKeyParams params2(384, KeyIdType::SHA256);
   BOOST_CHECK_EQUAL(params2.getKeyType(), KeyType::EC);
   BOOST_CHECK_EQUAL(params2.getKeySize(), 384);
+  BOOST_CHECK(params2.getKeyIdType() == KeyIdType::SHA256);
 
-  EcdsaKeyParams params3(3);
-  BOOST_CHECK_EQUAL(params3.getKeyType(), KeyType::EC);
-  BOOST_CHECK_EQUAL(params3.getKeySize(), 256);
+  BOOST_CHECK_THROW(EcdsaKeyParams(3), KeyParams::Error);
+
+  name::Component keyId("keyId");
+  EcdsaKeyParams params4(keyId);
+  BOOST_CHECK(params4.getKeyType() == KeyType::EC);
+  BOOST_CHECK_EQUAL(params4.getKeySize(), 256);
+  BOOST_CHECK(params4.getKeyIdType() == KeyIdType::USER_SPECIFIED);
+  BOOST_CHECK_EQUAL(params4.getKeyId(), keyId);
 }
 
 BOOST_AUTO_TEST_CASE(Aes)
 {
-  AesKeyParams params;
+  name::Component keyId("keyId");
+  AesKeyParams params(keyId);
   BOOST_CHECK_EQUAL(params.getKeyType(), KeyType::AES);
-  BOOST_CHECK_EQUAL(params.getKeySize(), 64);
+  BOOST_CHECK_EQUAL(params.getKeySize(), 128);
+  BOOST_CHECK_EQUAL(params.getKeyIdType(), KeyIdType::USER_SPECIFIED);
 
-  AesKeyParams params2(128);
-  BOOST_CHECK_EQUAL(params2.getKeyType(), KeyType::AES);
-  BOOST_CHECK_EQUAL(params2.getKeySize(), 128);
+  AesKeyParams params2(keyId, 192);
+  BOOST_CHECK(params2.getKeyType() == KeyType::AES);
+  BOOST_CHECK_EQUAL(params2.getKeySize(), 192);
+  BOOST_CHECK(params.getKeyIdType() == KeyIdType::USER_SPECIFIED);
 
-  AesKeyParams params3(256);
+  AesKeyParams params3(keyId, 256);
   BOOST_CHECK_EQUAL(params3.getKeyType(), KeyType::AES);
   BOOST_CHECK_EQUAL(params3.getKeySize(), 256);
+  BOOST_CHECK(params.getKeyIdType() == KeyIdType::USER_SPECIFIED);
 
-  AesKeyParams params4(4);
-  BOOST_CHECK_EQUAL(params4.getKeyType(), KeyType::AES);
-  BOOST_CHECK_EQUAL(params4.getKeySize(), 64);
+  BOOST_CHECK_THROW(AesKeyParams(keyId, 4), KeyParams::Error);
+
+  AesKeyParams params5(keyId);
+  BOOST_CHECK_EQUAL(params5.getKeyType(), KeyType::AES);
+  BOOST_CHECK_EQUAL(params5.getKeySize(), 128);
+  BOOST_CHECK_EQUAL(params5.getKeyIdType(), KeyIdType::USER_SPECIFIED);
+  BOOST_CHECK_EQUAL(params5.getKeyId(), keyId);
 }
 
-BOOST_AUTO_TEST_CASE(Error)
+BOOST_AUTO_TEST_CASE(KeyIdTypeInfo)
 {
-  EcdsaKeyParams params;
-  BOOST_REQUIRE_THROW((RsaKeyParams(params)), KeyParams::Error);
-
-  AesKeyParams params2;
-  BOOST_REQUIRE_THROW((RsaKeyParams(params2)), KeyParams::Error);
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(KeyIdType::USER_SPECIFIED), "USER_SPECIFIED");
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(KeyIdType::SHA256), "SHA256");
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(KeyIdType::RANDOM), "RANDOM");
+  BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(static_cast<KeyIdType>(12345)), "12345");
 }
 
+
 BOOST_AUTO_TEST_SUITE_END() // TestKeyParams
 BOOST_AUTO_TEST_SUITE_END() // Security