aboutsummaryrefslogtreecommitdiffstats
path: root/checks
diff options
context:
space:
mode:
authorlloyd <[email protected]>2007-02-19 23:42:37 +0000
committerlloyd <[email protected]>2007-02-19 23:42:37 +0000
commit8253bc1e62ea10b80b4bbfdc8e95c8849237cda2 (patch)
treec05937e167cf6629d34404b5d0073fb39eca3c3f /checks
parent54b95e6be5d3788497d461674869c0e0efc6e15c (diff)
Eliminate most uses of exit() to bail on an error; instead throw an
exception upto the top level, that's what it's there for.
Diffstat (limited to 'checks')
-rw-r--r--checks/bigint.cpp12
-rw-r--r--checks/pk.cpp18
-rw-r--r--checks/validate.cpp17
3 files changed, 14 insertions, 33 deletions
diff --git a/checks/bigint.cpp b/checks/bigint.cpp
index 8ace987e0..e4fec12b4 100644
--- a/checks/bigint.cpp
+++ b/checks/bigint.cpp
@@ -5,6 +5,7 @@
#include <cstdlib>
#include <botan/bigint.h>
+#include <botan/exceptn.h>
#include <botan/numthry.h>
#include <botan/rng.h>
using namespace Botan;
@@ -30,10 +31,7 @@ u32bit do_bigint_tests(const std::string& filename)
std::ifstream test_data(filename.c_str());
if(!test_data)
- {
- std::cout << "Couldn't open test file " << filename << std::endl;
- std::exit(1);
- }
+ throw Botan::Stream_IO_Error("Couldn't open test file " + filename);
u32bit errors = 0, alg_count = 0;
std::string algorithm;
@@ -43,10 +41,8 @@ u32bit do_bigint_tests(const std::string& filename)
while(!test_data.eof())
{
if(test_data.bad() || test_data.fail())
- {
- std::cout << "File I/O error." << std::endl;
- std::exit(1);
- }
+ throw Botan::Stream_IO_Error("File I/O error reading from " +
+ filename);
std::string line;
std::getline(test_data, line);
diff --git a/checks/pk.cpp b/checks/pk.cpp
index 4ff798e00..b8bf0fc51 100644
--- a/checks/pk.cpp
+++ b/checks/pk.cpp
@@ -52,11 +52,8 @@ class Fixed_Output_RNG : public RandomNumberGenerator
{
if(position < output.size())
return output[position++];
- std::cout << "Fixed_Output_RNG: Ran out of bits" << std::endl;
- std::exit(1);
- // Annoying: some compilers warn if a return is here (unreachable
- // code), others warn if it's not (no return from function).
- /* return 0; */
+
+ throw Botan::Invalid_State("Fixed_Output_RNG: out of bits");
}
void randomize(byte out[], u32bit len) throw()
{
@@ -101,10 +98,7 @@ u32bit do_pk_validation_tests(const std::string& filename)
std::ifstream test_data(filename.c_str());
if(!test_data)
- {
- std::cout << "Couldn't open test file " << filename << std::endl;
- std::exit(1);
- }
+ throw Botan::Stream_IO_Error("Couldn't open test file " + filename);
u32bit errors = 0, alg_count = 0;
std::string algorithm, print_algorithm;
@@ -112,10 +106,8 @@ u32bit do_pk_validation_tests(const std::string& filename)
while(!test_data.eof())
{
if(test_data.bad() || test_data.fail())
- {
- std::cout << "File I/O error." << std::endl;
- std::exit(1);
- }
+ throw Botan::Stream_IO_Error("File I/O error reading from " +
+ filename);
std::string line;
std::getline(test_data, line);
diff --git a/checks/validate.cpp b/checks/validate.cpp
index 2bdd6181b..b10b53b98 100644
--- a/checks/validate.cpp
+++ b/checks/validate.cpp
@@ -9,6 +9,7 @@
#include <cstdlib>
#include <botan/filters.h>
+#include <botan/exceptn.h>
#include <botan/rng.h>
using namespace Botan_types;
@@ -51,10 +52,7 @@ u32bit do_validation_tests(const std::string& filename, bool should_pass)
bool first_mark = true;
if(!test_data)
- {
- std::cout << "Couldn't open test file " << filename << std::endl;
- std::exit(1);
- }
+ throw Botan::Stream_IO_Error("Couldn't open test file " + filename);
u32bit errors = 0, alg_count = 0;
std::string algorithm;
@@ -66,10 +64,8 @@ u32bit do_validation_tests(const std::string& filename, bool should_pass)
while(!test_data.eof())
{
if(test_data.bad() || test_data.fail())
- {
- std::cout << "File I/O error." << std::endl;
- std::exit(1);
- }
+ throw Botan::Stream_IO_Error("File I/O error reading from " +
+ filename);
std::string line;
std::getline(test_data, line);
@@ -271,10 +267,7 @@ bool failed_test(const std::string& algo,
OK = false;
if(!OK)
- {
- std::cout << "Peek testing failed!" << std::endl;
- std::exit(1);
- }
+ throw Botan::Self_Test_Failure("Peek testing failed in validate.cpp");
}
if(output == expected && !exp_pass)