security: Moving signInTpm(Data& data, ...) from SecTpm to KeyChain.

The method is no longer a pure virtual method, and sub-classes of SecTpm do not have to implement this one.
Although the method is now a part of KeyChain, but it is still named as signInTpm to be distinguished from the other sign methods of KeyChain.
signInTpm takes the public key name as argument, well sign methods take certificate name as argument.

Change-Id: I6a1546f760a7446341a152bb2f716032f2b7bb58
diff --git a/include/ndn-cpp-dev/security/key-chain.hpp b/include/ndn-cpp-dev/security/key-chain.hpp
index fffa05d..c5df5db 100644
--- a/include/ndn-cpp-dev/security/key-chain.hpp
+++ b/include/ndn-cpp-dev/security/key-chain.hpp
@@ -153,6 +153,22 @@
     return certificate;
   }
 
+  /**
+   * Fetch the private key for keyName and sign the data, and set the signature block of the data packet.
+   * Throw Error if signing fails.
+   * @param data Reference to the input data packet.
+   * @param keyName The name of the signing key.
+   * @param digestAlgorithm the digest algorithm.
+   */  
+  void
+  signInTpm(Data &data, const Name& keyName, DigestAlgorithm digestAlgorithm)
+  {
+    data.setSignatureValue
+      (Tpm::signInTpm(data.wireEncode().value(),
+                      data.wireEncode().value_size() - data.getSignature().getValue().size(),
+                      keyName, digestAlgorithm));
+  }
+
   void
   sign(Data &data)
   {
@@ -184,7 +200,7 @@
     data.setSignature(signature);
 
     // For temporary usage, we support RSA + SHA256 only, but will support more.
-    Tpm::signInTpm(data, cert->getPublicKeyName(), DIGEST_ALGORITHM_SHA256);
+    signInTpm(data, cert->getPublicKeyName(), DIGEST_ALGORITHM_SHA256);
   }
 
   void
@@ -195,7 +211,7 @@
     data.setSignature(signature);
 
     // For temporary usage, we support RSA + SHA256 only, but will support more.
-    Tpm::signInTpm(data, certificate.getPublicKeyName(), DIGEST_ALGORITHM_SHA256);
+    signInTpm(data, certificate.getPublicKeyName(), DIGEST_ALGORITHM_SHA256);
   }
   
   /**
@@ -296,7 +312,7 @@
     cert.setSignature(signature);
 
     // For temporary usage, we support RSA + SHA256 only, but will support more.
-    Tpm::signInTpm(cert, cert.getPublicKeyName(), DIGEST_ALGORITHM_SHA256);
+    signInTpm(cert, cert.getPublicKeyName(), DIGEST_ALGORITHM_SHA256);
   }
 
 
diff --git a/include/ndn-cpp-dev/security/sec-tpm-memory.hpp b/include/ndn-cpp-dev/security/sec-tpm-memory.hpp
index 8203272..21dc272 100644
--- a/include/ndn-cpp-dev/security/sec-tpm-memory.hpp
+++ b/include/ndn-cpp-dev/security/sec-tpm-memory.hpp
@@ -68,9 +68,6 @@
    */  
   virtual Block 
   signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
-
-  virtual void 
-  signInTpm(Data &data, const Name& keyName, DigestAlgorithm digestAlgorithm);
   
   /**
    * Decrypt data.
diff --git a/include/ndn-cpp-dev/security/sec-tpm-osx.hpp b/include/ndn-cpp-dev/security/sec-tpm-osx.hpp
index 4839e3d..2ea9ff1 100644
--- a/include/ndn-cpp-dev/security/sec-tpm-osx.hpp
+++ b/include/ndn-cpp-dev/security/sec-tpm-osx.hpp
@@ -37,16 +37,13 @@
 
   // From TrustedPlatformModule
   virtual void 
-  generateKeyPairInTpm(const Name& keyName, KeyType keyType = KEY_TYPE_RSA, int keySize = 2048);
+  generateKeyPairInTpm(const Name& keyName, KeyType keyType, int keySize);
 
   virtual ptr_lib::shared_ptr<PublicKey> 
   getPublicKeyFromTpm(const Name& keyName);
   
   virtual Block
   signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm);
-
-  virtual void
-  signInTpm(Data &data, const Name& keyName, DigestAlgorithm digestAlgorithm);
   
   /**
    * Decrypt data.
diff --git a/include/ndn-cpp-dev/security/sec-tpm.hpp b/include/ndn-cpp-dev/security/sec-tpm.hpp
index c6b5328..dd9a55e 100644
--- a/include/ndn-cpp-dev/security/sec-tpm.hpp
+++ b/include/ndn-cpp-dev/security/sec-tpm.hpp
@@ -45,18 +45,16 @@
   getPublicKeyFromTpm(const Name& keyName) = 0;
   
   /**
-   * Fetch the private key for keyName and sign the data, returning a signature Blob.
+   * Fetch the private key for keyName and sign the data, returning a signature block.
    * @param data Pointer to the input byte array.
    * @param dataLength The length of data.
    * @param keyName The name of the signing key.
    * @param digestAlgorithm the digest algorithm.
-   * @return The signature, or a null pointer if signing fails.
+   * @return The signature block.
+   * @throws SecTpm::Error
    */  
   virtual Block
   signInTpm(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm) = 0;
-
-  virtual void
-  signInTpm(Data &data, const Name& keyName, DigestAlgorithm digestAlgorithm) = 0;
   
   /**
    * Decrypt data.