exceptions: Make Tlv::Error a base class for all packet-processing exceptions

This commit also includes a number of code style fixes.

Change-Id: I44f83915e733b43d5f43b4266902c8262e928d91
Refs: #1528
diff --git a/src/security/certificate-extension.hpp b/src/security/certificate-extension.hpp
index a1aa5b6..83653ee 100644
--- a/src/security/certificate-extension.hpp
+++ b/src/security/certificate-extension.hpp
@@ -13,7 +13,9 @@
 #include "../encoding/buffer.hpp"
 #include "../encoding/oid.hpp"
 
-namespace CryptoPP { class BufferedTransformation; }
+namespace CryptoPP {
+class BufferedTransformation;
+}
 
 namespace ndn {
 
diff --git a/src/security/certificate-subject-description.hpp b/src/security/certificate-subject-description.hpp
index 7665a3f..e8732f0 100644
--- a/src/security/certificate-subject-description.hpp
+++ b/src/security/certificate-subject-description.hpp
@@ -12,14 +12,17 @@
 #include "../common.hpp"
 #include "../encoding/oid.hpp"
 
-namespace CryptoPP { class BufferedTransformation; }
+namespace CryptoPP {
+class BufferedTransformation;
+}
 
 namespace ndn {
 
 /**
  * A CertificateSubjectDescription represents the SubjectDescription entry in a Certificate.
  */
-class CertificateSubjectDescription {
+class CertificateSubjectDescription
+{
 public:
   CertificateSubjectDescription(CryptoPP::BufferedTransformation& in)
   {
diff --git a/src/security/certificate.hpp b/src/security/certificate.hpp
index dc96879..157b878 100644
--- a/src/security/certificate.hpp
+++ b/src/security/certificate.hpp
@@ -17,7 +17,8 @@
 
 namespace ndn {
 
-class Certificate : public Data {
+class Certificate : public Data
+{
 public:
   class Error : public std::runtime_error
   {
diff --git a/src/security/conf/checker.hpp b/src/security/conf/checker.hpp
index 72ae726..6955dfe 100644
--- a/src/security/conf/checker.hpp
+++ b/src/security/conf/checker.hpp
@@ -101,16 +101,16 @@
                             interestName[INTEREST_SIG_VALUE].blockFromValue());
         return check(interest, signature, onValidated, onValidationFailed);
       }
-    catch (const Tlv::Error& e)
-      {
-        onValidationFailed(interest.shared_from_this(), "Cannot decode signature related TLVs");
-        return -1;
-      }
-    catch (const Signature::Error& e)
+    catch (Signature::Error& e)
       {
         onValidationFailed(interest.shared_from_this(), "Invalid signature");
         return -1;
       }
+    catch (Tlv::Error& e)
+      {
+        onValidationFailed(interest.shared_from_this(), "Cannot decode signature related TLVs");
+        return -1;
+      }
   }
 
 private:
@@ -147,7 +147,7 @@
                   return -1;
                 }
             }
-          catch (const SignatureSha256WithRsa::Error& e)
+          catch (SignatureSha256WithRsa::Error& e)
             {
               onValidationFailed(packet.shared_from_this(),
                                  "Cannot decode Sha256WithRsa signature!");
@@ -221,16 +221,16 @@
                             interestName[INTEREST_SIG_VALUE].blockFromValue());
         return check(interest, signature, onValidated, onValidationFailed);
       }
-    catch (const Tlv::Error& e)
-      {
-        onValidationFailed(interest.shared_from_this(), "Cannot decode signature related TLVs");
-        return -1;
-      }
-    catch (const Signature::Error& e)
+    catch (Signature::Error& e)
       {
         onValidationFailed(interest.shared_from_this(), "Invalid signature");
         return -1;
       }
+    catch (Tlv::Error& e)
+      {
+        onValidationFailed(interest.shared_from_this(), "Cannot decode signature related TLVs");
+        return -1;
+      }
   }
 
 private:
@@ -280,13 +280,13 @@
                   return -1;
                 }
             }
-          catch (const KeyLocator::Error& e)
+          catch (KeyLocator::Error& e)
             {
               onValidationFailed(packet.shared_from_this(),
                                  "KeyLocator does not have name!");
               return -1;
             }
-          catch (const SignatureSha256WithRsa::Error& e)
+          catch (SignatureSha256WithRsa::Error& e)
             {
               onValidationFailed(packet.shared_from_this(),
                                  "Cannot decode signature!");
diff --git a/src/security/conf/filter.hpp b/src/security/conf/filter.hpp
index 7d5b833..4145222 100644
--- a/src/security/conf/filter.hpp
+++ b/src/security/conf/filter.hpp
@@ -207,7 +207,7 @@
           {
             return shared_ptr<RegexNameFilter>(new RegexNameFilter(regexString));
           }
-        catch (const Regex::Error& e)
+        catch (Regex::Error& e)
           {
             throw Error("Wrong filter.regex: " + regexString);
           }
diff --git a/src/security/conf/key-locator-checker.hpp b/src/security/conf/key-locator-checker.hpp
index 5785c59..e040d80 100644
--- a/src/security/conf/key-locator-checker.hpp
+++ b/src/security/conf/key-locator-checker.hpp
@@ -107,7 +107,7 @@
         failInfo = "KeyLocatorChecker failed!";
         return false;
       }
-    catch (const KeyLocator::Error& e)
+    catch (KeyLocator::Error& e)
       {
         failInfo = "KeyLocator does not have name";
         return false;
@@ -141,7 +141,7 @@
         failInfo = "KeyLocatorChecker failed!";
         return false;
       }
-    catch (const KeyLocator::Error& e)
+    catch (KeyLocator::Error& e)
       {
         failInfo = "KeyLocator does not have name";
         return false;
@@ -182,7 +182,7 @@
         failInfo = "KeyLocatorChecker failed!";
         return false;
       }
-    catch (const KeyLocator::Error& e)
+    catch (KeyLocator::Error& e)
       {
         failInfo = "KeyLocator does not have name";
         return false;
@@ -277,7 +277,7 @@
             return shared_ptr<RegexKeyLocatorNameChecker>
               (new RegexKeyLocatorNameChecker(regexString));
           }
-        catch (const Regex::Error& e)
+        catch (Regex::Error& e)
           {
             throw Error("Invalid checker.key-locator.regex: " + regexString);
           }
@@ -344,7 +344,7 @@
                                               kRegex, kExpand,
                                               relation));
           }
-        catch (const Regex::Error& e)
+        catch (Regex::Error& e)
           {
             throw Error("Invalid regex for key-locator.hyper-relation");
           }
diff --git a/src/security/encryption-manager.hpp b/src/security/encryption-manager.hpp
index a6f319b..f4f43b5 100644
--- a/src/security/encryption-manager.hpp
+++ b/src/security/encryption-manager.hpp
@@ -13,7 +13,8 @@
 
 namespace ndn {
 
-class EncryptionManager {
+class EncryptionManager
+{
 public:
   virtual ~EncryptionManager()
   {
diff --git a/src/security/public-key.hpp b/src/security/public-key.hpp
index 7774755..4a8f16a 100644
--- a/src/security/public-key.hpp
+++ b/src/security/public-key.hpp
@@ -16,7 +16,8 @@
 
 namespace ndn {
 
-class PublicKey {
+class PublicKey
+{
 public:
   class Error : public std::runtime_error
   {
diff --git a/src/security/sec-public-info-memory.hpp b/src/security/sec-public-info-memory.hpp
index 2ecdc43..4cbceac 100644
--- a/src/security/sec-public-info-memory.hpp
+++ b/src/security/sec-public-info-memory.hpp
@@ -17,7 +17,8 @@
  * @brief SecPublicInfoMemory extends SecPublicInfo and implements its methods to store identity,
  *        public key and certificate objects in memory.
  */
-class SecPublicInfoMemory : public SecPublicInfo {
+class SecPublicInfoMemory : public SecPublicInfo
+{
 public:
   class Error : public SecPublicInfo::Error
   {
@@ -104,7 +105,8 @@
 
 
 private:
-  class KeyRecord {
+  class KeyRecord
+  {
   public:
     KeyRecord(KeyType keyType, const PublicKey& key)
     : m_keyType(keyType), m_key(key)
diff --git a/src/security/sec-public-info-sqlite3.hpp b/src/security/sec-public-info-sqlite3.hpp
index 6241817..4f5115f 100644
--- a/src/security/sec-public-info-sqlite3.hpp
+++ b/src/security/sec-public-info-sqlite3.hpp
@@ -16,7 +16,8 @@
 
 namespace ndn {
 
-class SecPublicInfoSqlite3 : public SecPublicInfo {
+class SecPublicInfoSqlite3 : public SecPublicInfo
+{
 public:
   class Error : public SecPublicInfo::Error
   {
diff --git a/src/security/sec-public-info.hpp b/src/security/sec-public-info.hpp
index 99b4f57..ee32d05 100644
--- a/src/security/sec-public-info.hpp
+++ b/src/security/sec-public-info.hpp
@@ -23,7 +23,8 @@
  * It specify interfaces related to public information, such as identity, public keys and
  * certificates.
  */
-class SecPublicInfo {
+class SecPublicInfo
+{
 public:
   class Error : public std::runtime_error
   {
diff --git a/src/security/sec-tpm-file.cpp b/src/security/sec-tpm-file.cpp
index 5238ca4..ba3cca8 100644
--- a/src/security/sec-tpm-file.cpp
+++ b/src/security/sec-tpm-file.cpp
@@ -25,7 +25,8 @@
 
 namespace ndn {
 
-class SecTpmFile::Impl {
+class SecTpmFile::Impl
+{
 public:
   Impl(const string& dir)
   {
@@ -123,7 +124,7 @@
           throw Error("Unsupported key type!");
         }
     }
-  catch (const CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       throw Error(e.what());
     }
@@ -158,7 +159,7 @@
                  true,
                  new Base64Decoder(new FileSink(os)));
     }
-  catch (const CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       throw Error(e.what());
     }
@@ -191,7 +192,7 @@
                    new Base64Encoder(new FileSink(keyFileName.c_str())));
       return true;
     }
-  catch (const CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       return false;
     }
@@ -211,7 +212,7 @@
                    new Base64Encoder(new FileSink(keyFileName.c_str())));
       return true;
     }
-  catch (const CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       return false;
     }
@@ -258,7 +259,7 @@
           throw Error("Unsupported digest algorithm!");
         }
     }
-  catch (const CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       throw Error(e.what());
     }
@@ -294,7 +295,7 @@
 
   //       return os.buf();
   //     }
-  //     catch (const CryptoPP::Exception& e){
+  //     catch (CryptoPP::Exception& e){
   //       throw Error(e.what());
   //     }
   //   }
@@ -321,7 +322,7 @@
   //     // 	StringSource(data, dataLength, true, new StreamTransformationFilter(decryptor,new FileSink(os)));
   //     // 	return os.buf();
 
-  //     // }catch (const CryptoPP::Exception& e){
+  //     // }catch (CryptoPP::Exception& e){
   //     // 	throw Error(e.what());
   //     // }
   //   }
@@ -357,7 +358,7 @@
   //         StringSource(data, dataLength, true, new PK_EncryptorFilter(rng, encryptor, new FileSink(os)));
   //         return os.buf();
   //       }
-  //     catch (const CryptoPP::Exception& e){
+  //     catch (CryptoPP::Exception& e){
   //       throw Error(e.what());
   //     }
   //   }
@@ -383,7 +384,7 @@
   //     // 	OBufferStream os;
   //     // 	StringSource(data, dataLength, true, new StreamTransformationFilter(encryptor, new FileSink(os)));
   //     // 	return os.buf();
-  //     // }catch (const CryptoPP::Exception& e){
+  //     // }catch (CryptoPP::Exception& e){
   //     // 	throw Error(e.what());
   //     // }
   //   }
@@ -420,7 +421,7 @@
   //   default:
   //     throw Error("Unsupported symmetric key type!");
   //   }
-  // }catch (const CryptoPP::Exception& e){
+  // }catch (CryptoPP::Exception& e){
   //   throw Error(e.what());
   // }
 }
@@ -462,7 +463,7 @@
       rng.GenerateBlock(res, size);
       return true;
     }
-  catch (const CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       return false;
     }
diff --git a/src/security/sec-tpm-memory.cpp b/src/security/sec-tpm-memory.cpp
index 3475aa4..393a217 100644
--- a/src/security/sec-tpm-memory.cpp
+++ b/src/security/sec-tpm-memory.cpp
@@ -20,7 +20,8 @@
 /**
  * RsaPrivateKey is a simple class to hold an RSA private key.
  */
-class SecTpmMemory::RsaPrivateKey {
+class SecTpmMemory::RsaPrivateKey
+{
 public:
   RsaPrivateKey(const uint8_t* keyDer, size_t keyDerLength)
   {
@@ -175,7 +176,7 @@
       rng.GenerateBlock(res, size);
       return true;
     }
-  catch (const CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       return false;
     }
diff --git a/src/security/sec-tpm-memory.hpp b/src/security/sec-tpm-memory.hpp
index 61b1c8a..eb1613d 100644
--- a/src/security/sec-tpm-memory.hpp
+++ b/src/security/sec-tpm-memory.hpp
@@ -20,7 +20,8 @@
  *
  * You should initialize by calling setKeyPairForKeyName.
  */
-class SecTpmMemory : public SecTpm {
+class SecTpmMemory : public SecTpm
+{
 public:
   class Error : public SecTpm::Error
   {
diff --git a/src/security/sec-tpm-osx.cpp b/src/security/sec-tpm-osx.cpp
index d06cefe..fd21439 100644
--- a/src/security/sec-tpm-osx.cpp
+++ b/src/security/sec-tpm-osx.cpp
@@ -28,12 +28,14 @@
 
 namespace ndn {
 
-class SecTpmOsx::Impl {
+class SecTpmOsx::Impl
+{
 public:
   Impl()
     : m_passwordSet(false)
     , m_inTerminal(false)
-  {}
+  {
+  }
 
   /**
    * @brief Convert NDN name of a key to internal name of the key.
diff --git a/src/security/sec-tpm-osx.hpp b/src/security/sec-tpm-osx.hpp
index d6637ef..1a5bd1f 100644
--- a/src/security/sec-tpm-osx.hpp
+++ b/src/security/sec-tpm-osx.hpp
@@ -13,7 +13,8 @@
 
 namespace ndn {
 
-class SecTpmOsx : public SecTpm {
+class SecTpmOsx : public SecTpm
+{
 public:
   class Error : public SecTpm::Error
   {
diff --git a/src/security/sec-tpm.hpp b/src/security/sec-tpm.hpp
index 15f1770..14b5756 100644
--- a/src/security/sec-tpm.hpp
+++ b/src/security/sec-tpm.hpp
@@ -22,7 +22,8 @@
  *
  * It specifies the interfaces of private/secret key related operations.
  */
-class SecTpm {
+class SecTpm
+{
 public:
   class Error : public std::runtime_error
   {
diff --git a/src/security/signature-sha256-with-rsa.hpp b/src/security/signature-sha256-with-rsa.hpp
index 7e19a1e..f809709 100644
--- a/src/security/signature-sha256-with-rsa.hpp
+++ b/src/security/signature-sha256-with-rsa.hpp
@@ -15,8 +15,19 @@
 /**
  * Representing of SHA256-with-RSA signature in a data packet.
  */
-class SignatureSha256WithRsa : public Signature {
+class SignatureSha256WithRsa : public Signature
+{
 public:
+  class Error : public Signature::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : Signature::Error(what)
+    {
+    }
+  };
+
   SignatureSha256WithRsa()
   {
     m_info = Block(Tlv::SignatureInfo);
@@ -30,7 +41,7 @@
     : Signature(signature)
   {
     if (getType() != Signature::Sha256WithRsa)
-      throw Signature::Error("Incorrect signature type");
+      throw Error("Incorrect signature type");
 
     m_info.parse();
     Block::element_const_iterator i = m_info.find(Tlv::KeyLocator);
diff --git a/src/security/signature-sha256.hpp b/src/security/signature-sha256.hpp
index 8ef37a8..9200ac5 100644
--- a/src/security/signature-sha256.hpp
+++ b/src/security/signature-sha256.hpp
@@ -15,8 +15,19 @@
 /**
  * Representing of SHA256 signature in a data packet.
  */
-class SignatureSha256 : public Signature {
+class SignatureSha256 : public Signature
+{
 public:
+  class Error : public Signature::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : Signature::Error(what)
+    {
+    }
+  };
+
   SignatureSha256()
   {
     m_info = Block(Tlv::SignatureInfo);
@@ -29,7 +40,7 @@
     : Signature(signature)
   {
     if (getType() != Signature::Sha256)
-      throw Signature::Error("Incorrect signature type");
+      throw Error("Incorrect signature type");
   }
 };
 
diff --git a/src/security/validation-request.hpp b/src/security/validation-request.hpp
index 8846636..b525c27 100644
--- a/src/security/validation-request.hpp
+++ b/src/security/validation-request.hpp
@@ -27,7 +27,8 @@
                       const std::string&)> OnDataValidationFailed;
 
 
-class ValidationRequest {
+class ValidationRequest
+{
 public:
   ValidationRequest(const Interest& interest,
                     const OnDataValidated& onValidated,
diff --git a/src/security/validator-config.cpp b/src/security/validator-config.cpp
index 77d3354..4b430ce 100644
--- a/src/security/validator-config.cpp
+++ b/src/security/validator-config.cpp
@@ -70,7 +70,7 @@
     {
       boost::property_tree::read_info(input, tree);
     }
-  catch (const boost::property_tree::info_parser_error& error)
+  catch (boost::property_tree::info_parser_error& error)
     {
       std::stringstream msg;
       msg << "Failed to parse configuration file";
diff --git a/src/security/validator-null.hpp b/src/security/validator-null.hpp
index f389d4c..1bb6d01 100644
--- a/src/security/validator-null.hpp
+++ b/src/security/validator-null.hpp
@@ -13,7 +13,8 @@
 
 namespace ndn {
 
-class ValidatorNull : public Validator {
+class ValidatorNull : public Validator
+{
 public:
   virtual
   ~ValidatorNull()
diff --git a/src/security/validator-regex.cpp b/src/security/validator-regex.cpp
index 1eea45e..e9558c6 100644
--- a/src/security/validator-regex.cpp
+++ b/src/security/validator-regex.cpp
@@ -152,13 +152,13 @@
                   return;
                 }
             }
-          catch (const SignatureSha256WithRsa::Error& e)
+          catch (SignatureSha256WithRsa::Error& e)
             {
               return onValidationFailed(data.shared_from_this(),
                                         "Not SignatureSha256WithRsa signature: " +
                                         data.getName().toUri());
             }
-          catch (const KeyLocator::Error& e)
+          catch (KeyLocator::Error& e)
             {
               return onValidationFailed(data.shared_from_this(),
                                         "Key Locator is not a name: " +
diff --git a/src/security/validator.cpp b/src/security/validator.cpp
index 338ef9f..7f97926 100644
--- a/src/security/validator.cpp
+++ b/src/security/validator.cpp
@@ -142,7 +142,7 @@
           }
         }
     }
-  catch (const Signature::Error& e)
+  catch (Signature::Error& e)
     {
       return false;
     }
@@ -180,11 +180,11 @@
           }
         }
     }
-  catch (const Signature::Error& e)
+  catch (Signature::Error& e)
     {
       return false;
     }
-  catch (const Block::Error& e)
+  catch (Block::Error& e)
     {
       return false;
     }
@@ -209,7 +209,7 @@
           }
         }
     }
-  catch (const Signature::Error& e)
+  catch (Signature::Error& e)
     {
       return false;
     }
@@ -237,7 +237,7 @@
                                     sig.getValue().value(),
                                     sig.getValue().value_size());
     }
-  catch (const CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       return false;
     }
@@ -264,7 +264,7 @@
       else
         return false;
     }
-  catch (const CryptoPP::Exception& e)
+  catch (CryptoPP::Exception& e)
     {
       return false;
     }
diff --git a/src/security/validator.hpp b/src/security/validator.hpp
index 43ab01a..38a8db2 100644
--- a/src/security/validator.hpp
+++ b/src/security/validator.hpp
@@ -24,7 +24,8 @@
  *
  * The Validator class provides the interfaces for packet validation.
  */
-class Validator {
+class Validator
+{
 public:
   class Error : public std::runtime_error
   {