aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/main.cpp2
-rw-r--r--src/tests/test_mceliece.cpp4
-rw-r--r--src/tests/test_pubkey.h4
-rw-r--r--src/tests/test_rng.h2
-rw-r--r--src/tests/test_utils.cpp4
-rw-r--r--src/tests/test_x509_path.cpp6
-rw-r--r--src/tests/tests.cpp28
-rw-r--r--src/tests/tests.h6
-rw-r--r--src/tests/unit_tls.cpp2
-rw-r--r--src/tests/unit_x509.cpp2
10 files changed, 33 insertions, 27 deletions
diff --git a/src/tests/main.cpp b/src/tests/main.cpp
index 41d29d542..b8d85cb62 100644
--- a/src/tests/main.cpp
+++ b/src/tests/main.cpp
@@ -170,7 +170,7 @@ setup_tests(std::ostream& out, size_t threads, size_t soak_level, bool log_succe
#else
if(drbg_seed != "")
- throw std::runtime_error("HMAC_DRBG disabled in build, cannot specify DRBG seed");
+ throw Test_Error("HMAC_DRBG disabled in build, cannot specify DRBG seed");
#if defined(BOTAN_HAS_SYSTEM_RNG)
out << " rng:system";
diff --git a/src/tests/test_mceliece.cpp b/src/tests/test_mceliece.cpp
index a2cf5bf8f..88379f2ea 100644
--- a/src/tests/test_mceliece.cpp
+++ b/src/tests/test_mceliece.cpp
@@ -103,7 +103,7 @@ class McEliece_Tests : public Test
{
std::unique_ptr<Botan::HashFunction> hash(Botan::HashFunction::create(hash_algo));
if(!hash)
- throw std::runtime_error("Hash " + hash_algo + " not available");
+ throw Test_Error("Hash " + hash_algo + " not available");
hash->update(key.pkcs8_private_key());
return Botan::hex_encode(hash->final());
@@ -113,7 +113,7 @@ class McEliece_Tests : public Test
{
std::unique_ptr<Botan::HashFunction> hash(Botan::HashFunction::create(hash_algo));
if(!hash)
- throw std::runtime_error("Hash " + hash_algo + " not available");
+ throw Test_Error("Hash " + hash_algo + " not available");
hash->update(key.x509_subject_public_key());
return Botan::hex_encode(hash->final());
diff --git a/src/tests/test_pubkey.h b/src/tests/test_pubkey.h
index a5a1c2799..edb36f07b 100644
--- a/src/tests/test_pubkey.h
+++ b/src/tests/test_pubkey.h
@@ -26,7 +26,7 @@ class PK_Signature_Generation_Test : public Text_Based_Test
virtual std::string default_padding(const VarMap&) const
{
- throw std::runtime_error("No default padding scheme set for " + algo_name());
+ throw Test_Error("No default padding scheme set for " + algo_name());
}
virtual std::unique_ptr<Botan::Private_Key> load_private_key(const VarMap& vars) = 0;
@@ -45,7 +45,7 @@ class PK_Signature_Verification_Test : public Text_Based_Test
virtual std::string default_padding(const VarMap&) const
{
- throw std::runtime_error("No default padding scheme set for " + algo_name());
+ throw Test_Error("No default padding scheme set for " + algo_name());
}
virtual std::unique_ptr<Botan::Public_Key> load_public_key(const VarMap& vars) = 0;
diff --git a/src/tests/test_rng.h b/src/tests/test_rng.h
index 7d30fd6cc..3016707dd 100644
--- a/src/tests/test_rng.h
+++ b/src/tests/test_rng.h
@@ -23,7 +23,7 @@ class Fixed_Output_RNG : public Botan::RandomNumberGenerator
byte random()
{
if(!is_seeded())
- throw std::runtime_error("Out of bytes");
+ throw Test_Error("Out of bytes");
byte out = buf.front();
buf.pop_front();
diff --git a/src/tests/test_utils.cpp b/src/tests/test_utils.cpp
index 9ee799519..f6611b3ae 100644
--- a/src/tests/test_utils.cpp
+++ b/src/tests/test_utils.cpp
@@ -185,7 +185,7 @@ class Date_Format_Tests : public Text_Based_Test
{
const std::vector<std::string> parts = Botan::split_on(s, ',');
if(parts.size() != 6)
- throw std::runtime_error("Bad date format '" + s + "'");
+ throw Test_Error("Bad date format '" + s + "'");
std::vector<uint32_t> u32s;
for(auto&& sub : parts)
@@ -233,7 +233,7 @@ class Date_Format_Tests : public Text_Based_Test
}
else
{
- throw std::runtime_error("Unexpected header '" + type + "' in date format tests");
+ throw Test_Error("Unexpected header '" + type + "' in date format tests");
}
return result;
diff --git a/src/tests/test_x509_path.cpp b/src/tests/test_x509_path.cpp
index 62051d021..149c6ec2a 100644
--- a/src/tests/test_x509_path.cpp
+++ b/src/tests/test_x509_path.cpp
@@ -52,7 +52,7 @@ class X509test_Path_Validation_Tests : public Test
std::vector<Botan::X509_Certificate> certs = load_cert_file(test_dir + "/" + fsname);
if(certs.empty())
- throw std::runtime_error("Failed to read certs from " + fsname);
+ throw Test_Error("Failed to read certs from " + fsname);
Botan::Path_Validation_Result path_result = Botan::x509_path_validate(
certs, default_restrictions, trusted,
@@ -90,7 +90,7 @@ class X509test_Path_Validation_Tests : public Test
{
std::ifstream in(results_file);
if(!in.good())
- throw std::runtime_error("Failed reading " + results_file);
+ throw Test_Error("Failed reading " + results_file);
std::map<std::string, std::string> m;
std::string line;
@@ -105,7 +105,7 @@ class X509test_Path_Validation_Tests : public Test
std::vector<std::string> parts = Botan::split_on(line, ':');
if(parts.size() != 2)
- throw std::runtime_error("Invalid line " + line);
+ throw Test_Error("Invalid line " + line);
m[parts[0]] = parts[1];
}
diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp
index 4db24dcc7..360d671cc 100644
--- a/src/tests/tests.cpp
+++ b/src/tests/tests.cpp
@@ -25,14 +25,14 @@ Test::Registration::Registration(const std::string& name, Test* test)
}
else
{
- throw std::runtime_error("Duplicate registration of test '" + name + "'");
+ throw Test_Error("Duplicate registration of test '" + name + "'");
}
}
void Test::Result::merge(const Result& other)
{
if(who() != other.who())
- throw std::runtime_error("Merging tests from different sources");
+ throw Test_Error("Merging tests from different sources");
m_ns_taken += other.m_ns_taken;
m_tests_passed += other.m_tests_passed;
@@ -476,7 +476,7 @@ bool Test::log_success()
Botan::RandomNumberGenerator& Test::rng()
{
if(!m_test_rng)
- throw std::runtime_error("Test RNG not initialized");
+ throw Test_Error("Test RNG not initialized");
return *m_test_rng;
}
@@ -492,7 +492,7 @@ Text_Based_Test::Text_Based_Test(const std::string& data_src,
m_data_src(data_src)
{
if(required_keys.empty())
- throw std::runtime_error("Invalid test spec");
+ throw Test_Error("Invalid test spec");
m_required_keys.insert(required_keys.begin(), required_keys.end());
m_optional_keys.insert(optional_keys.begin(), optional_keys.end());
@@ -507,7 +507,7 @@ Text_Based_Test::Text_Based_Test(const std::string& algo,
m_data_src(data_src)
{
if(required_keys.empty())
- throw std::runtime_error("Invalid test spec");
+ throw Test_Error("Invalid test spec");
m_required_keys.insert(required_keys.begin(), required_keys.end());
m_optional_keys.insert(optional_keys.begin(), optional_keys.end());
@@ -519,7 +519,7 @@ std::vector<uint8_t> Text_Based_Test::get_req_bin(const VarMap& vars,
{
auto i = vars.find(key);
if(i == vars.end())
- throw std::runtime_error("Test missing variable " + key);
+ throw Test_Error("Test missing variable " + key);
try
{
@@ -527,7 +527,7 @@ std::vector<uint8_t> Text_Based_Test::get_req_bin(const VarMap& vars,
}
catch(std::exception& e)
{
- throw std::runtime_error("Test invalid hex input '" + i->second + "'" +
+ throw Test_Error("Test invalid hex input '" + i->second + "'" +
+ " for key " + key);
}
}
@@ -546,7 +546,7 @@ size_t Text_Based_Test::get_req_sz(const VarMap& vars, const std::string& key) c
{
auto i = vars.find(key);
if(i == vars.end())
- throw std::runtime_error("Test missing variable " + key);
+ throw Test_Error("Test missing variable " + key);
return Botan::to_u32bit(i->second);
}
@@ -571,7 +571,7 @@ std::vector<uint8_t> Text_Based_Test::get_opt_bin(const VarMap& vars,
}
catch(std::exception& e)
{
- throw std::runtime_error("Test invalid hex input '" + i->second + "'" +
+ throw Test_Error("Test invalid hex input '" + i->second + "'" +
+ " for key " + key);
}
}
@@ -580,7 +580,7 @@ std::string Text_Based_Test::get_req_str(const VarMap& vars, const std::string&
{
auto i = vars.find(key);
if(i == vars.end())
- throw std::runtime_error("Test missing variable " + key);
+ throw Test_Error("Test missing variable " + key);
return i->second;
}
@@ -590,7 +590,7 @@ Botan::BigInt Text_Based_Test::get_req_bn(const VarMap& vars,
{
auto i = vars.find(key);
if(i == vars.end())
- throw std::runtime_error("Test missing variable " + key);
+ throw Test_Error("Test missing variable " + key);
try
{
@@ -598,7 +598,7 @@ Botan::BigInt Text_Based_Test::get_req_bn(const VarMap& vars,
}
catch(std::exception& e)
{
- throw std::runtime_error("Test invalid bigint input '" + i->second + "' for key " + key);
+ throw Test_Error("Test invalid bigint input '" + i->second + "' for key " + key);
}
}
#endif
@@ -622,7 +622,7 @@ std::string Text_Based_Test::get_next_line()
const auto fs = Botan::get_files_recursive(m_data_src);
m_srcs.assign(fs.begin(), fs.end());
if(m_srcs.empty())
- throw std::runtime_error("Error reading test data dir " + m_data_src);
+ throw Test_Error("Error reading test data dir " + m_data_src);
}
m_first = false;
@@ -636,7 +636,7 @@ std::string Text_Based_Test::get_next_line()
m_cur.reset(new std::ifstream(m_srcs[0]));
if(!m_cur->good())
- throw std::runtime_error("Could not open input file '" + m_srcs[0]);
+ throw Test_Error("Could not open input file '" + m_srcs[0]);
m_srcs.pop_front();
}
diff --git a/src/tests/tests.h b/src/tests/tests.h
index fddf44aaf..333cbee98 100644
--- a/src/tests/tests.h
+++ b/src/tests/tests.h
@@ -39,6 +39,12 @@ using Botan::byte;
using Botan::BigInt;
#endif
+class Test_Error : public Botan::Exception
+ {
+ public:
+ Test_Error(const std::string& what) : Exception("Test error", what) {}
+ };
+
/*
* A generic test which retuns a set of results when run.
* The tests may not all have the same type (for example test
diff --git a/src/tests/unit_tls.cpp b/src/tests/unit_tls.cpp
index ec585ed6f..0ff85bb29 100644
--- a/src/tests/unit_tls.cpp
+++ b/src/tests/unit_tls.cpp
@@ -106,7 +106,7 @@ class Credentials_Manager_Test : public Botan::Credentials_Manager
if(context == "server.example.com" && type == "tls-server")
return Botan::SymmetricKey("20B602D1475F2DF888FCB60D2AE03AFD");
- throw std::runtime_error("No PSK set for " + type + "/" + context);
+ throw Test_Error("No PSK set for " + type + "/" + context);
}
public:
diff --git a/src/tests/unit_x509.cpp b/src/tests/unit_x509.cpp
index 08ed5b578..da36459c4 100644
--- a/src/tests/unit_x509.cpp
+++ b/src/tests/unit_x509.cpp
@@ -102,7 +102,7 @@ std::unique_ptr<Botan::Private_Key> make_a_private_key()
return std::unique_ptr<Botan::Private_Key>(new Botan::ECDSA_PrivateKey(Test::rng(), grp));
#endif
- throw std::runtime_error("Skipping X.509 cert test due to missing algos");
+ throw Test_Error("Skipping X.509 cert test due to missing algos");
}
class X509_Cert_Unit_Tests : public Test