aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/pubkey/pkcs8.cpp4
-rw-r--r--src/lib/pubkey/x509_key.cpp4
-rw-r--r--src/lib/utils/exceptn.cpp19
-rw-r--r--src/lib/utils/exceptn.h8
-rw-r--r--src/lib/x509/x509_ext.cpp2
-rw-r--r--src/lib/x509/x509_obj.cpp2
-rw-r--r--src/lib/x509/x509cert.cpp2
7 files changed, 29 insertions, 12 deletions
diff --git a/src/lib/pubkey/pkcs8.cpp b/src/lib/pubkey/pkcs8.cpp
index 8d3eba6dc..c91e436c7 100644
--- a/src/lib/pubkey/pkcs8.cpp
+++ b/src/lib/pubkey/pkcs8.cpp
@@ -97,7 +97,7 @@ secure_vector<uint8_t> PKCS8_decode(
}
catch(Decoding_Error& e)
{
- throw Decoding_Error("PKCS #8 private key decoding failed: " + std::string(e.what()));
+ throw Decoding_Error("PKCS #8 private key decoding", e);
}
try
@@ -126,7 +126,7 @@ secure_vector<uint8_t> PKCS8_decode(
}
catch(std::exception& e)
{
- throw Decoding_Error("PKCS #8 private key decoding failed: " + std::string(e.what()));
+ throw Decoding_Error("PKCS #8 private key decoding", e);
}
return key;
}
diff --git a/src/lib/pubkey/x509_key.cpp b/src/lib/pubkey/x509_key.cpp
index 6e49d953a..fff75ec44 100644
--- a/src/lib/pubkey/x509_key.cpp
+++ b/src/lib/pubkey/x509_key.cpp
@@ -62,13 +62,13 @@ Public_Key* load_key(DataSource& source)
}
if(key_bits.empty())
- throw Decoding_Error("X.509 public key decoding failed");
+ throw Decoding_Error("X.509 public key decoding");
return load_public_key(alg_id, key_bits).release();
}
catch(Decoding_Error& e)
{
- throw Decoding_Error("X.509 public key decoding failed: " + std::string(e.what()));
+ throw Decoding_Error("X.509 public key decoding", e);
}
}
diff --git a/src/lib/utils/exceptn.cpp b/src/lib/utils/exceptn.cpp
index a72e45ba4..cc6eb9f85 100644
--- a/src/lib/utils/exceptn.cpp
+++ b/src/lib/utils/exceptn.cpp
@@ -11,18 +11,25 @@ namespace Botan {
Exception::Exception(const std::string& msg) : m_msg(msg)
{}
+Exception::Exception(const std::string& msg, const std::exception& e) :
+ m_msg(msg + " failed with " + std::string(e.what()))
+ {}
+
Exception::Exception(const char* prefix, const std::string& msg) :
m_msg(std::string(prefix) + " " + msg)
{}
Invalid_Argument::Invalid_Argument(const std::string& msg) :
- Exception("Invalid argument", msg)
+ Exception(msg)
{}
Invalid_Argument::Invalid_Argument(const std::string& msg, const std::string& where) :
- Exception("Invalid argument", msg + " in " + where)
+ Exception(msg + " in " + where)
{}
+Invalid_Argument::Invalid_Argument(const std::string& msg, const std::exception& e) :
+ Exception(msg, e) {}
+
Lookup_Error::Lookup_Error(const std::string& type,
const std::string& algo,
const std::string& provider) :
@@ -76,11 +83,15 @@ Encoding_Error::Encoding_Error(const std::string& name) :
{}
Decoding_Error::Decoding_Error(const std::string& name) :
- Invalid_Argument("Decoding error: " + name)
+ Invalid_Argument(name)
+ {}
+
+Decoding_Error::Decoding_Error(const std::string& msg, const std::exception& e) :
+ Invalid_Argument(msg, e)
{}
Decoding_Error::Decoding_Error(const std::string& name, const char* exception_message) :
- Invalid_Argument("Decoding error: " + name + " failed with exception " + exception_message) {}
+ Invalid_Argument(name + " failed with exception " + exception_message) {}
Integrity_Failure::Integrity_Failure(const std::string& msg) :
Exception("Integrity failure: " + msg)
diff --git a/src/lib/utils/exceptn.h b/src/lib/utils/exceptn.h
index f2896aa83..efa52580c 100644
--- a/src/lib/utils/exceptn.h
+++ b/src/lib/utils/exceptn.h
@@ -23,6 +23,8 @@ class BOTAN_PUBLIC_API(2,0) Exception : public std::exception
Exception(const char* prefix, const std::string& msg);
explicit Exception(const std::string& msg);
const char* what() const BOTAN_NOEXCEPT override { return m_msg.c_str(); }
+ protected:
+ Exception(const std::string& msg, const std::exception& e);
private:
std::string m_msg;
};
@@ -36,7 +38,9 @@ class BOTAN_PUBLIC_API(2,0) Invalid_Argument : public Exception
explicit Invalid_Argument(const std::string& msg);
explicit Invalid_Argument(const std::string& msg, const std::string& where);
-};
+
+ Invalid_Argument(const std::string& msg, const std::exception& e);
+ };
/**
* Unsupported_Argument Exception
@@ -178,6 +182,8 @@ class BOTAN_PUBLIC_API(2,0) Decoding_Error : public Invalid_Argument
explicit Decoding_Error(const std::string& name);
Decoding_Error(const std::string& name, const char* exception_message);
+
+ Decoding_Error(const std::string& msg, const std::exception& e);
};
/**
diff --git a/src/lib/x509/x509_ext.cpp b/src/lib/x509/x509_ext.cpp
index 122be2885..5a5ffa177 100644
--- a/src/lib/x509/x509_ext.cpp
+++ b/src/lib/x509/x509_ext.cpp
@@ -101,7 +101,7 @@ Extensions::create_extn_obj(const OID& oid,
}
catch(Decoding_Error& e)
{
- throw Decoding_Error("Decoding X.509 extension " + oid.as_string() + " failed", e.what());
+ throw Decoding_Error("Decoding X.509 extension " + oid.as_string(), e);
}
return extn;
}
diff --git a/src/lib/x509/x509_obj.cpp b/src/lib/x509/x509_obj.cpp
index 060453072..49d7fcc60 100644
--- a/src/lib/x509/x509_obj.cpp
+++ b/src/lib/x509/x509_obj.cpp
@@ -85,7 +85,7 @@ void X509_Object::load_data(DataSource& in)
}
catch(Decoding_Error& e)
{
- throw Decoding_Error(PEM_label() + " decoding failed: " + e.what());
+ throw Decoding_Error(PEM_label() + " decoding", e);
}
}
diff --git a/src/lib/x509/x509cert.cpp b/src/lib/x509/x509cert.cpp
index ddfe5d5b2..9ed521f16 100644
--- a/src/lib/x509/x509cert.cpp
+++ b/src/lib/x509/x509cert.cpp
@@ -650,7 +650,7 @@ std::unique_ptr<Public_Key> X509_Certificate::load_subject_public_key() const
}
catch(std::exception& e)
{
- throw Decoding_Error("X509_Certificate::load_subject_public_key", e.what());
+ throw Decoding_Error("X509_Certificate::load_subject_public_key", e);
}
}