security: Porting security elements to the updated framework

Change-Id: Ie9ad6ee34f94fc520b9d3c8adf871e2557eaa9b6
diff --git a/include/ndn-cpp/security/key-chain.hpp b/include/ndn-cpp/security/key-chain.hpp
index 4e804cc..da470f7 100644
--- a/include/ndn-cpp/security/key-chain.hpp
+++ b/include/ndn-cpp/security/key-chain.hpp
@@ -29,7 +29,9 @@
 public:
   struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
 
-  KeyChain(IdentityManager *identityManager, PolicyManager *policyManager);
+  KeyChain(const ptr_lib::shared_ptr<IdentityManager>   &identityManager   = DefaultIdentityManager,
+           const ptr_lib::shared_ptr<PolicyManager>     &policyManager     = DefaultPolicyManager,
+           const ptr_lib::shared_ptr<EncryptionManager> &encryptionManager = DefaultEncryptionManager);
 
   /**
    * @brief Set the Face which will be used to fetch required certificates.
@@ -47,6 +49,9 @@
   inline IdentityManager&
   identities()
   {
+    if (!identityManager_)
+      throw Error("IdentityManager is not assigned to the KeyChain");
+
     return *identityManager_;
   }
 
@@ -57,10 +62,26 @@
   inline PolicyManager&
   policies()
   {
+    if (!policyManager_)
+      throw Error("PolicyManager is not assigned to the KeyChain");
+
     return *policyManager_;
   }
 
   /*****************************************
+   *         Encryption Management         *
+   *****************************************/
+
+  inline EncryptionManager&
+  encryption()
+  {
+    if (!encryptionManager_)
+      throw Error("EncryptionManager is not assigned to the KeyChain");
+
+    return *encryptionManager_;
+  }
+
+  /*****************************************
    *              Sign/Verify              *
    *****************************************/
 
@@ -70,7 +91,6 @@
    * data.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0).
    * @param data The Data object to be signed.  This updates its signature and key locator field and wireEncoding.
    * @param certificateName The certificate name of the key to use for signing.  If omitted, infer the signing identity from the data packet name.
-   * @param wireFormat A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat().
    */
   void 
   sign(Data& data, const Name& certificateName);
@@ -91,7 +111,6 @@
    * data.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0).
    * @param data The Data object to be signed.  This updates its signature and key locator field and wireEncoding.
    * @param identityName The identity name for the key to use for signing.  If omitted, infer the signing identity from the data packet name.
-   * @param wireFormat A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat().
    */
   void 
   signByIdentity(Data& data, const Name& identityName = Name());
@@ -122,7 +141,12 @@
    *           Encrypt/Decrypt             *
    *****************************************/
   // todo
-  
+
+public:
+  static const ptr_lib::shared_ptr<IdentityManager>   DefaultIdentityManager;
+  static const ptr_lib::shared_ptr<PolicyManager>     DefaultPolicyManager;
+  static const ptr_lib::shared_ptr<EncryptionManager> DefaultEncryptionManager;
+    
 private:
   void
   onCertificateData
@@ -134,9 +158,10 @@
      const ptr_lib::shared_ptr<Data> &data, ptr_lib::shared_ptr<ValidationRequest> nextStep);
 
 private:
-  std::auto_ptr<IdentityManager>   identityManager_;
-  std::auto_ptr<PolicyManager>     policyManager_;
-  // std::auto_ptr<EncryptionManager> encryptionManager_;
+  ptr_lib::shared_ptr<IdentityManager>   identityManager_;
+  ptr_lib::shared_ptr<PolicyManager>     policyManager_;
+  ptr_lib::shared_ptr<EncryptionManager> encryptionManager_;
+
   ptr_lib::shared_ptr<Face>        face_;
   
   const int maxSteps_;