]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4633] Decorated library errors
authorFrancis Dupont <fdupont@isc.org>
Thu, 12 Jan 2017 22:35:08 +0000 (23:35 +0100)
committerFrancis Dupont <fdupont@isc.org>
Thu, 12 Jan 2017 22:35:08 +0000 (23:35 +0100)
src/lib/cryptolink/botan_hash.cc
src/lib/cryptolink/botan_hmac.cc
src/lib/cryptolink/botan_link.cc
src/lib/cryptolink/openssl_hash.cc
src/lib/cryptolink/openssl_hmac.cc

index 8e87786c42afde59ac97111c1988d66903eefad0..0ed47e50b8e242b6e1bd181d6b90f7fdc8efd80b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -74,7 +74,8 @@ public:
                       "Unknown hash algorithm: " <<
                       static_cast<int>(hash_algorithm));
         } catch (const Botan::Exception& exc) {
-            isc_throw(isc::cryptolink::LibraryError, exc.what());
+            isc_throw(isc::cryptolink::LibraryError,
+                      "Botan error: " << exc.what());
         }
 
         hash_.reset(hash);
@@ -110,7 +111,8 @@ public:
         try {
             hash_->update(static_cast<const Botan::byte*>(data), len);
         } catch (const Botan::Exception& exc) {
-            isc_throw(isc::cryptolink::LibraryError, exc.what());
+            isc_throw(isc::cryptolink::LibraryError,
+                      "Botan error: " << exc.what());
         }
     }
 
@@ -126,7 +128,8 @@ public:
             }
             result.writeData(&b_result[0], len);
         } catch (const Botan::Exception& exc) {
-            isc_throw(isc::cryptolink::LibraryError, exc.what());
+            isc_throw(isc::cryptolink::LibraryError,
+                      "Botan error: " << exc.what());
         }
     }
 
@@ -142,7 +145,8 @@ public:
             }
             std::memcpy(result, &b_result[0], output_size);
         } catch (const Botan::Exception& exc) {
-            isc_throw(isc::cryptolink::LibraryError, exc.what());
+            isc_throw(isc::cryptolink::LibraryError,
+                      "Botan error: " << exc.what());
         }
     }
 
@@ -157,7 +161,8 @@ public:
             }
             return (std::vector<uint8_t>(&b_result[0], &b_result[len]));
         } catch (const Botan::Exception& exc) {
-            isc_throw(isc::cryptolink::LibraryError, exc.what());
+            isc_throw(isc::cryptolink::LibraryError,
+                      "Botan error: " << exc.what());
         }
     }
 
index 713dad1bb06ee1d5c922fd5bcb5bbfa0008ebf57..0471e2b24ea7e559ffeff413eac2d5e885170aa9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -58,7 +58,7 @@ public:
                       "Unknown hash algorithm: " <<
                       static_cast<int>(hash_algorithm));
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
 
         hmac_.reset(new Botan::HMAC(hash));
@@ -94,7 +94,7 @@ public:
         } catch (const Botan::Invalid_Key_Length& ikl) {
             isc_throw(BadKey, ikl.what());
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
     }
 
@@ -129,7 +129,7 @@ public:
         try {
             hmac_->update(static_cast<const Botan::byte*>(data), len);
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
     }
 
@@ -145,7 +145,7 @@ public:
             }
             result.writeData(&b_result[0], len);
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
     }
 
@@ -161,7 +161,7 @@ public:
             }
             std::memcpy(result, &b_result[0], output_size);
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
     }
 
@@ -176,7 +176,7 @@ public:
             }
             return (std::vector<uint8_t>(&b_result[0], &b_result[len]));
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
     }
 
@@ -203,7 +203,7 @@ public:
                                     static_cast<const unsigned char*>(sig),
                                     len));
         } catch (const Botan::Exception& exc) {
-            isc_throw(LibraryError, exc.what());
+            isc_throw(LibraryError, "Botan error: " << exc.what());
         }
     }
 
index 965d1256e991904613403fca609efc17c315607d..b05e51d5d87a525dca573ca39e27e8de5e85a048 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2015,2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -31,7 +31,7 @@ CryptoLink::initialize() {
         try {
             c.impl_ = new CryptoLinkImpl();
         } catch (const Botan::Exception& ex) {
-            isc_throw(InitializationError, ex.what());
+            isc_throw(InitializationError, "Botan error: " << ex.what());
         }
     }
 }
index 6b19c6fcbe58383ec01615d379e0c138bc866885..4d68a3203361d8ac3d4851107cde3d48e036efe2 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -67,7 +67,8 @@ public:
 
         md_ = EVP_MD_CTX_new();
         if (md_ == 0) {
-            isc_throw(isc::cryptolink::LibraryError, "EVP_MD_CTX_new");
+            isc_throw(isc::cryptolink::LibraryError,
+                      "OpenSSL EVP_MD_CTX_new() failed");
         }
 
         EVP_DigestInit_ex(md_, algo, NULL);
index 0da7278f114473e84c8a3bd8780401ac9c79851c..55298583713563e2e266c0201ce31d347f577ede 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -46,13 +46,13 @@ public:
 
         md_ = HMAC_CTX_new();
         if (md_ == 0) {
-            isc_throw(LibraryError, "HMAC_CTX_new");
+            isc_throw(LibraryError, "OpenSSL HMAC_CTX_new() failed");
         }
 
         if (!HMAC_Init_ex(md_, secret,
                           static_cast<int>(secret_len),
                           algo, NULL)) {
-            isc_throw(LibraryError, "HMAC_Init_ex");
+            isc_throw(LibraryError, "OpenSSL HMAC_Init_ex() failed");
         }
     }
 
@@ -75,7 +75,7 @@ public:
     size_t getOutputLength() const {
         int size = HMAC_size(md_);
         if (size < 0) {
-            isc_throw(LibraryError, "HMAC_size");
+            isc_throw(LibraryError, "OpenSSL HMAC_size() failed");
         }
         return (static_cast<size_t>(size));
     }
@@ -87,7 +87,7 @@ public:
         if (!HMAC_Update(md_,
                          static_cast<const unsigned char*>(data),
                          len)) {
-            isc_throw(LibraryError, "HMAC_Update");
+            isc_throw(LibraryError, "OpenSSLHMAC_Update() failed");
         }
     }
 
@@ -98,7 +98,7 @@ public:
         size_t size = getOutputLength();
         ossl::SecBuf<unsigned char> digest(size);
         if (!HMAC_Final(md_, &digest[0], NULL)) {
-            isc_throw(LibraryError, "HMAC_Final");
+            isc_throw(LibraryError, "OpenSSL HMAC_Final() failed");
         }
         if (len > size) {
             len = size;
@@ -113,7 +113,7 @@ public:
         size_t size = getOutputLength();
         ossl::SecBuf<unsigned char> digest(size);
         if (!HMAC_Final(md_, &digest[0], NULL)) {
-            isc_throw(LibraryError, "HMAC_Final");
+            isc_throw(LibraryError, "OpenSSL HMAC_Final() failed");
         }
         if (len > size) {
             len = size;
@@ -128,7 +128,7 @@ public:
         size_t size = getOutputLength();
         ossl::SecBuf<unsigned char> digest(size);
         if (!HMAC_Final(md_, &digest[0], NULL)) {
-            isc_throw(LibraryError, "HMAC_Final");
+            isc_throw(LibraryError, "OpenSSL HMAC_Final() failed");
         }
         if (len < size) {
             digest.resize(len);
@@ -148,16 +148,16 @@ public:
         // Get the digest from a copy of the context
         HMAC_CTX* tmp = HMAC_CTX_new();
         if (tmp == 0) {
-            isc_throw(LibraryError, "HMAC_CTX_new");
+            isc_throw(LibraryError, "OpenSSL HMAC_CTX_new() failed");
         }
         if (!HMAC_CTX_copy(tmp, md_)) {
             HMAC_CTX_free(tmp);
-            isc_throw(LibraryError, "HMAC_CTX_copy");
+            isc_throw(LibraryError, "OpenSSL HMAC_CTX_copy() failed");
         }
         ossl::SecBuf<unsigned char> digest(size);
         if (!HMAC_Final(tmp, &digest[0], NULL)) {
             HMAC_CTX_free(tmp);
-            isc_throw(LibraryError, "HMAC_Final");
+            isc_throw(LibraryError, "OpenSSL HMAC_Final() failed");
         }
         HMAC_CTX_free(tmp);
         if (len > size) {