aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/asn1/oid_lookup/oids.cpp2
-rw-r--r--src/lib/base/algo_registry.h6
-rw-r--r--src/lib/block/blowfish/blowfish.cpp4
-rw-r--r--src/lib/block/threefish/threefish.cpp2
-rw-r--r--src/lib/cert/x509/ocsp.cpp18
-rw-r--r--src/lib/cert/x509/ocsp_types.cpp2
-rw-r--r--src/lib/cert/x509/x509_ext.cpp4
-rw-r--r--src/lib/cert/x509/x509_obj.cpp2
-rw-r--r--src/lib/cert/x509/x509path.cpp6
-rw-r--r--src/lib/codec/base64/base64.cpp4
-rw-r--r--src/lib/codec/hex/hex.cpp4
-rw-r--r--src/lib/compression/bzip2/bzip2.cpp8
-rw-r--r--src/lib/compression/compression.cpp6
-rw-r--r--src/lib/compression/compression.h2
-rw-r--r--src/lib/compression/lzma/lzma.cpp6
-rw-r--r--src/lib/compression/zlib/zlib.cpp10
-rw-r--r--src/lib/entropy/egd/es_egd.cpp10
-rw-r--r--src/lib/entropy/unix_procs/unix_procs.cpp2
-rw-r--r--src/lib/ffi/ffi.cpp12
-rw-r--r--src/lib/filters/buf_filt.cpp6
-rw-r--r--src/lib/filters/codec_filt/b64_filt.cpp2
-rw-r--r--src/lib/filters/codec_filt/hex_filt.cpp2
-rw-r--r--src/lib/filters/comp_filter.cpp4
-rw-r--r--src/lib/filters/transform_filter.cpp2
-rw-r--r--src/lib/hash/comb4p/comb4p.cpp4
-rw-r--r--src/lib/mac/cmac/cmac.cpp2
-rw-r--r--src/lib/math/bigint/big_io.cpp2
-rw-r--r--src/lib/math/ec_gfp/point_gfp.cpp4
-rw-r--r--src/lib/math/mp/mp_misc.cpp2
-rw-r--r--src/lib/math/numbertheory/numthry.cpp2
-rw-r--r--src/lib/misc/benchmark/benchmark.cpp2
-rw-r--r--src/lib/misc/fpe_fe1/fpe_fe1.cpp4
-rw-r--r--src/lib/misc/rfc3394/rfc3394.cpp8
-rw-r--r--src/lib/misc/srp6/srp6.cpp6
-rw-r--r--src/lib/modes/aead/ccm/ccm.cpp6
-rw-r--r--src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp2
-rw-r--r--src/lib/modes/aead/gcm/gcm.cpp2
-rw-r--r--src/lib/modes/aead/ocb/ocb.cpp4
-rw-r--r--src/lib/modes/cbc/cbc.cpp4
-rw-r--r--src/lib/modes/cfb/cfb.cpp2
-rw-r--r--src/lib/modes/ecb/ecb.cpp4
-rw-r--r--src/lib/modes/xts/xts.cpp2
-rw-r--r--src/lib/passhash/passhash9/passhash9.cpp2
-rw-r--r--src/lib/pbkdf/pbkdf.cpp2
-rw-r--r--src/lib/pbkdf/pbkdf2/pbkdf2.cpp2
-rw-r--r--src/lib/pubkey/blinding.cpp4
-rw-r--r--src/lib/pubkey/dl_group/dl_group.cpp2
-rw-r--r--src/lib/pubkey/mce/gf2m_small_m.cpp4
-rw-r--r--src/lib/pubkey/mce/goppa_code.cpp2
-rw-r--r--src/lib/pubkey/mceies/mceies.cpp8
-rw-r--r--src/lib/pubkey/pk_ops.cpp2
-rw-r--r--src/lib/pubkey/pkcs8.cpp4
-rw-r--r--src/lib/rng/rng.h2
-rw-r--r--src/lib/rng/system_rng/system_rng.cpp8
-rw-r--r--src/lib/tls/credentials_manager.cpp6
-rw-r--r--src/lib/tls/msg_client_hello.cpp2
-rw-r--r--src/lib/tls/sessions_sql/tls_session_manager_sql.cpp4
-rw-r--r--src/lib/tls/tls_channel.cpp10
-rw-r--r--src/lib/tls/tls_ciphersuite.cpp2
-rw-r--r--src/lib/tls/tls_extensions.cpp2
-rw-r--r--src/lib/tls/tls_heartbeats.cpp4
-rw-r--r--src/lib/tls/tls_policy.h2
-rw-r--r--src/lib/tls/tls_reader.h4
-rw-r--r--src/lib/tls/tls_seq_numbers.h2
-rw-r--r--src/lib/utils/assert.cpp2
-rw-r--r--src/lib/utils/dyn_load/dyn_load.cpp4
-rw-r--r--src/lib/utils/exceptn.h33
-rw-r--r--src/lib/utils/http_util/http_util.cpp16
-rw-r--r--src/lib/utils/http_util/http_util.h2
-rw-r--r--src/lib/utils/parsing.cpp2
-rw-r--r--src/lib/utils/read_cfg.cpp2
-rw-r--r--src/lib/utils/sqlite3/sqlite3.cpp16
-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
82 files changed, 211 insertions, 194 deletions
diff --git a/src/lib/asn1/oid_lookup/oids.cpp b/src/lib/asn1/oid_lookup/oids.cpp
index 5859e118e..8ce0ec644 100644
--- a/src/lib/asn1/oid_lookup/oids.cpp
+++ b/src/lib/asn1/oid_lookup/oids.cpp
@@ -120,7 +120,7 @@ void OID_Map::read_cfg(std::istream& cfg, const std::string& source)
auto eq = s.find("=");
if(eq == std::string::npos || eq == 0 || eq == s.size() - 1)
- throw std::runtime_error("Bad config line '" + s + "' in " + source + " line " + std::to_string(line));
+ throw Exception("Bad config line '" + s + "' in " + source + " line " + std::to_string(line));
const std::string oid = clean_ws(s.substr(0, eq));
const std::string name = clean_ws(s.substr(eq + 1, std::string::npos));
diff --git a/src/lib/base/algo_registry.h b/src/lib/base/algo_registry.h
index eec1ce88d..842c4167b 100644
--- a/src/lib/base/algo_registry.h
+++ b/src/lib/base/algo_registry.h
@@ -77,7 +77,7 @@ class Algo_Registry
{
std::lock_guard<mutex> lock(m_mutex);
if(!m_algo_info[name].add_provider(provider, fn, pref))
- throw std::runtime_error("Duplicated registration of " + name + "/" + provider);
+ throw Exception("Duplicated registration of " + name + "/" + provider);
}
std::vector<std::string> providers_of(const Spec& spec)
@@ -111,7 +111,7 @@ class Algo_Registry
}
catch(std::exception& e)
{
- throw std::runtime_error("Creating '" + spec.as_string() + "' failed: " + e.what());
+ throw Exception("Creating '" + spec.as_string() + "' failed: " + e.what());
}
return nullptr;
@@ -258,7 +258,7 @@ make_new_T_1X(const typename Algo_Registry<T>::Spec& spec)
{
std::unique_ptr<X> x(Algo_Registry<X>::global_registry().make(spec.arg(0)));
if(!x)
- throw std::runtime_error(spec.arg(0));
+ throw Exception(spec.arg(0));
return new T(x.release());
}
diff --git a/src/lib/block/blowfish/blowfish.cpp b/src/lib/block/blowfish/blowfish.cpp
index 2488838c3..0b0e685a8 100644
--- a/src/lib/block/blowfish/blowfish.cpp
+++ b/src/lib/block/blowfish/blowfish.cpp
@@ -119,7 +119,7 @@ void Blowfish::eks_key_schedule(const byte key[], size_t length,
length = std::min<size_t>(length, 55);
if(workfactor == 0)
- throw std::invalid_argument("Bcrypt work factor must be at least 1");
+ throw Invalid_Argument("Bcrypt work factor must be at least 1");
/*
* On a 2.8 GHz Core-i7, workfactor == 18 takes about 25 seconds to
@@ -127,7 +127,7 @@ void Blowfish::eks_key_schedule(const byte key[], size_t length,
* time being.
*/
if(workfactor > 18)
- throw std::invalid_argument("Requested Bcrypt work factor " +
+ throw Invalid_Argument("Requested Bcrypt work factor " +
std::to_string(workfactor) + " too large");
P.resize(18);
diff --git a/src/lib/block/threefish/threefish.cpp b/src/lib/block/threefish/threefish.cpp
index 93fd122c2..958175bb8 100644
--- a/src/lib/block/threefish/threefish.cpp
+++ b/src/lib/block/threefish/threefish.cpp
@@ -221,7 +221,7 @@ void Threefish_512::decrypt_n(const byte in[], byte out[], size_t blocks) const
void Threefish_512::set_tweak(const byte tweak[], size_t len)
{
if(len != 16)
- throw std::runtime_error("Unsupported twofish tweak length");
+ throw Exception("Unsupported twofish tweak length");
m_T.resize(3);
m_T[0] = load_le<u64bit>(tweak, 0);
m_T[1] = load_le<u64bit>(tweak, 1);
diff --git a/src/lib/cert/x509/ocsp.cpp b/src/lib/cert/x509/ocsp.cpp
index feda10676..75475fe55 100644
--- a/src/lib/cert/x509/ocsp.cpp
+++ b/src/lib/cert/x509/ocsp.cpp
@@ -55,7 +55,7 @@ void check_signature(const std::vector<byte>& tbs_response,
split_on(OIDS::lookup(sig_algo.oid), '/');
if(sig_info.size() != 2 || sig_info[0] != pub_key->algo_name())
- throw std::runtime_error("Information in OCSP response does not match cert");
+ throw Exception("Information in OCSP response does not match cert");
std::string padding = sig_info[1];
Signature_Format format =
@@ -64,7 +64,7 @@ void check_signature(const std::vector<byte>& tbs_response,
PK_Verifier verifier(*pub_key, padding, format);
if(!verifier.verify_message(ASN1::put_in_sequence(tbs_response), signature))
- throw std::runtime_error("Signature on OCSP response does not verify");
+ throw Exception("Signature on OCSP response does not verify");
}
void check_signature(const std::vector<byte>& tbs_response,
@@ -74,7 +74,7 @@ void check_signature(const std::vector<byte>& tbs_response,
const std::vector<X509_Certificate>& certs)
{
if(certs.size() < 1)
- throw std::invalid_argument("Short cert chain for check_signature");
+ throw Invalid_Argument("Short cert chain for check_signature");
if(trusted_roots.certificate_known(certs[0]))
return check_signature(tbs_response, sig_algo, signature, certs[0]);
@@ -82,15 +82,15 @@ void check_signature(const std::vector<byte>& tbs_response,
// Otherwise attempt to chain the signing cert to a trust root
if(!certs[0].allowed_usage("PKIX.OCSPSigning"))
- throw std::runtime_error("OCSP response cert does not allow OCSP signing");
+ throw Exception("OCSP response cert does not allow OCSP signing");
auto result = x509_path_validate(certs, Path_Validation_Restrictions(), trusted_roots);
if(!result.successful_validation())
- throw std::runtime_error("Certificate validation failure: " + result.result_string());
+ throw Exception("Certificate validation failure: " + result.result_string());
if(!trusted_roots.certificate_known(result.trust_root())) // not needed anymore?
- throw std::runtime_error("Certificate chain roots in unknown/untrusted CA");
+ throw Exception("Certificate chain roots in unknown/untrusted CA");
const std::vector<X509_Certificate>& cert_path = result.cert_path();
@@ -132,7 +132,7 @@ Response::Response(const Certificate_Store& trusted_roots,
response_outer.decode(resp_status, ENUMERATED, UNIVERSAL);
if(resp_status != 0)
- throw std::runtime_error("OCSP response status " + std::to_string(resp_status));
+ throw Exception("OCSP response status " + std::to_string(resp_status));
if(response_outer.more_items())
{
@@ -185,7 +185,7 @@ Response::Response(const Certificate_Store& trusted_roots,
if(auto cert = trusted_roots.find_cert(name, std::vector<byte>()))
certs.push_back(*cert);
else
- throw std::runtime_error("Could not find certificate that signed OCSP response");
+ throw Exception("Could not find certificate that signed OCSP response");
}
check_signature(tbs_bits, sig_algo, signature, trusted_roots, certs);
@@ -229,7 +229,7 @@ Response online_check(const X509_Certificate& issuer,
const std::string responder_url = subject.ocsp_responder();
if(responder_url == "")
- throw std::runtime_error("No OCSP responder specified");
+ throw Exception("No OCSP responder specified");
OCSP::Request req(issuer, subject);
diff --git a/src/lib/cert/x509/ocsp_types.cpp b/src/lib/cert/x509/ocsp_types.cpp
index 04ab1ea03..ba5b825f7 100644
--- a/src/lib/cert/x509/ocsp_types.cpp
+++ b/src/lib/cert/x509/ocsp_types.cpp
@@ -92,7 +92,7 @@ void CertID::decode_from(class BER_Decoder& from)
void SingleResponse::encode_into(class DER_Encoder&) const
{
- throw std::runtime_error("Not implemented (SingleResponse::encode_into)");
+ throw Exception("Not implemented (SingleResponse::encode_into)");
}
void SingleResponse::decode_from(class BER_Decoder& from)
diff --git a/src/lib/cert/x509/x509_ext.cpp b/src/lib/cert/x509/x509_ext.cpp
index 4da7467c3..f752500c0 100644
--- a/src/lib/cert/x509/x509_ext.cpp
+++ b/src/lib/cert/x509/x509_ext.cpp
@@ -627,7 +627,7 @@ void CRL_ReasonCode::contents_to(Data_Store& info, Data_Store&) const
std::vector<byte> CRL_Distribution_Points::encode_inner() const
{
- throw std::runtime_error("CRL_Distribution_Points encoding not implemented");
+ throw Exception("CRL_Distribution_Points encoding not implemented");
}
void CRL_Distribution_Points::decode_inner(const std::vector<byte>& buf)
@@ -650,7 +650,7 @@ void CRL_Distribution_Points::contents_to(Data_Store& info, Data_Store&) const
void CRL_Distribution_Points::Distribution_Point::encode_into(class DER_Encoder&) const
{
- throw std::runtime_error("CRL_Distribution_Points encoding not implemented");
+ throw Exception("CRL_Distribution_Points encoding not implemented");
}
void CRL_Distribution_Points::Distribution_Point::decode_from(class BER_Decoder& ber)
diff --git a/src/lib/cert/x509/x509_obj.cpp b/src/lib/cert/x509/x509_obj.cpp
index 0f5999b5b..4dae68607 100644
--- a/src/lib/cert/x509/x509_obj.cpp
+++ b/src/lib/cert/x509/x509_obj.cpp
@@ -176,7 +176,7 @@ std::string X509_Object::hash_used_for_signature() const
bool X509_Object::check_signature(const Public_Key* pub_key) const
{
if(!pub_key)
- throw std::runtime_error("No key provided for " + PEM_label_pref + " signature check");
+ throw Exception("No key provided for " + PEM_label_pref + " signature check");
std::unique_ptr<const Public_Key> key(pub_key);
return check_signature(*key);
}
diff --git a/src/lib/cert/x509/x509path.cpp b/src/lib/cert/x509/x509path.cpp
index b5345c272..7e54ad9f9 100644
--- a/src/lib/cert/x509/x509path.cpp
+++ b/src/lib/cert/x509/x509path.cpp
@@ -219,7 +219,7 @@ Path_Validation_Result x509_path_validate(
Usage_Type usage)
{
if(end_certs.empty())
- throw std::invalid_argument("x509_path_validate called with no subjects");
+ throw Invalid_Argument("x509_path_validate called with no subjects");
std::vector<X509_Certificate> cert_path;
cert_path.push_back(end_certs[0]);
@@ -337,9 +337,9 @@ Path_Validation_Result::Path_Validation_Result(std::vector<std::set<Certificate_
const X509_Certificate& Path_Validation_Result::trust_root() const
{
if(m_cert_path.empty())
- throw std::runtime_error("Path_Validation_Result::trust_root no path set");
+ throw Exception("Path_Validation_Result::trust_root no path set");
if(result() != Certificate_Status_Code::VERIFIED)
- throw std::runtime_error("Path_Validation_Result::trust_root meaningless with invalid status");
+ throw Exception("Path_Validation_Result::trust_root meaningless with invalid status");
return m_cert_path[m_cert_path.size()-1];
}
diff --git a/src/lib/codec/base64/base64.cpp b/src/lib/codec/base64/base64.cpp
index a63d2b373..b5f4244a1 100644
--- a/src/lib/codec/base64/base64.cpp
+++ b/src/lib/codec/base64/base64.cpp
@@ -162,7 +162,7 @@ size_t base64_decode(byte output[],
else if(bad_char == "\r")
bad_char = "\\r";
- throw std::invalid_argument(
+ throw Invalid_Argument(
std::string("base64_decode: invalid base64 character '") +
bad_char + "'");
}
@@ -214,7 +214,7 @@ size_t base64_decode(byte output[],
consumed, true, ignore_ws);
if(consumed != input_length)
- throw std::invalid_argument("base64_decode: input did not have full bytes");
+ throw Invalid_Argument("base64_decode: input did not have full bytes");
return written;
}
diff --git a/src/lib/codec/hex/hex.cpp b/src/lib/codec/hex/hex.cpp
index 4da719320..a718cc8be 100644
--- a/src/lib/codec/hex/hex.cpp
+++ b/src/lib/codec/hex/hex.cpp
@@ -109,7 +109,7 @@ size_t hex_decode(byte output[],
else if(bad_char == "\n")
bad_char = "\\n";
- throw std::invalid_argument(
+ throw Invalid_Argument(
std::string("hex_decode: invalid hex character '") +
bad_char + "'");
}
@@ -147,7 +147,7 @@ size_t hex_decode(byte output[],
consumed, ignore_ws);
if(consumed != input_length)
- throw std::invalid_argument("hex_decode: input did not have full bytes");
+ throw Invalid_Argument("hex_decode: input did not have full bytes");
return written;
}
diff --git a/src/lib/compression/bzip2/bzip2.cpp b/src/lib/compression/bzip2/bzip2.cpp
index 857af10b1..d7527bfef 100644
--- a/src/lib/compression/bzip2/bzip2.cpp
+++ b/src/lib/compression/bzip2/bzip2.cpp
@@ -44,7 +44,7 @@ class Bzip2_Compression_Stream : public Bzip2_Stream
if(rc == BZ_MEM_ERROR)
throw std::bad_alloc();
else if(rc != BZ_OK)
- throw std::runtime_error("bzip compress initialization failed");
+ throw Exception("bzip compress initialization failed");
}
~Bzip2_Compression_Stream()
@@ -59,7 +59,7 @@ class Bzip2_Compression_Stream : public Bzip2_Stream
if(rc == BZ_MEM_ERROR)
throw std::bad_alloc();
else if(rc < 0)
- throw std::runtime_error("bzip compress error");
+ throw Exception("bzip compress error");
return (rc == BZ_STREAM_END);
}
@@ -75,7 +75,7 @@ class Bzip2_Decompression_Stream : public Bzip2_Stream
if(rc == BZ_MEM_ERROR)
throw std::bad_alloc();
else if(rc != BZ_OK)
- throw std::runtime_error("bzip decompress initialization failed");
+ throw Exception("bzip decompress initialization failed");
}
~Bzip2_Decompression_Stream()
@@ -90,7 +90,7 @@ class Bzip2_Decompression_Stream : public Bzip2_Stream
if(rc == BZ_MEM_ERROR)
throw std::bad_alloc();
else if(rc != BZ_OK && rc != BZ_STREAM_END)
- throw std::runtime_error("bzip decompress error");
+ throw Exception("bzip decompress error");
return (rc == BZ_STREAM_END);
}
diff --git a/src/lib/compression/compression.cpp b/src/lib/compression/compression.cpp
index ddbcd7cec..fc2c6192a 100644
--- a/src/lib/compression/compression.cpp
+++ b/src/lib/compression/compression.cpp
@@ -28,7 +28,7 @@ void Compression_Alloc_Info::do_free(void* ptr)
auto i = m_current_allocs.find(ptr);
if(i == m_current_allocs.end())
- throw std::runtime_error("Compression_Alloc_Info::free got pointer not allocated by us");
+ throw Exception("Compression_Alloc_Info::free got pointer not allocated by us");
zero_mem(ptr, i->second);
std::free(ptr);
@@ -64,7 +64,7 @@ Compressor_Transform* do_make_compressor(const std::string& type, const std::str
Compressor_Transform* r = dynamic_cast<Compressor_Transform*>(t.get());
if(!r)
- throw std::runtime_error("Bad cast of compression object " + t_name);
+ throw Exception("Bad cast of compression object " + t_name);
t.release();
return r;
@@ -228,7 +228,7 @@ void Stream_Decompression::finish(secure_vector<byte>& buf, size_t offset)
process(buf, offset, m_stream->finish_flag());
if(m_stream.get())
- throw std::runtime_error(name() + " finished but not at stream end");
+ throw Exception(name() + " finished but not at stream end");
}
}
diff --git a/src/lib/compression/compression.h b/src/lib/compression/compression.h
index 2c74550d6..0a8079de8 100644
--- a/src/lib/compression/compression.h
+++ b/src/lib/compression/compression.h
@@ -28,7 +28,7 @@ class BOTAN_DLL Compressor_Transform : public Transform
size_t output_length(size_t) const override final
{
- throw std::runtime_error(name() + " output length indeterminate");
+ throw Exception(name() + " output length indeterminate");
}
};
diff --git a/src/lib/compression/lzma/lzma.cpp b/src/lib/compression/lzma/lzma.cpp
index 93a969d70..6e5217767 100644
--- a/src/lib/compression/lzma/lzma.cpp
+++ b/src/lib/compression/lzma/lzma.cpp
@@ -43,7 +43,7 @@ class LZMA_Stream : public Zlib_Style_Stream<lzma_stream, byte>
if(rc == LZMA_MEM_ERROR)
throw std::bad_alloc();
else if (rc != LZMA_OK && rc != LZMA_STREAM_END)
- throw std::runtime_error("Lzma error");
+ throw Exception("Lzma error");
return (rc == LZMA_STREAM_END);
}
@@ -63,7 +63,7 @@ class LZMA_Compression_Stream : public LZMA_Stream
if(rc == LZMA_MEM_ERROR)
throw std::bad_alloc();
else if(rc != LZMA_OK)
- throw std::runtime_error("lzma compress initialization failed");
+ throw Exception("lzma compress initialization failed");
}
};
@@ -78,7 +78,7 @@ class LZMA_Decompression_Stream : public LZMA_Stream
if(rc == LZMA_MEM_ERROR)
throw std::bad_alloc();
else if(rc != LZMA_OK)
- throw std::runtime_error("Bad setting in lzma_stream_decoder");
+ throw Exception("Bad setting in lzma_stream_decoder");
}
};
diff --git a/src/lib/compression/zlib/zlib.cpp b/src/lib/compression/zlib/zlib.cpp
index a6a724754..10422fff7 100644
--- a/src/lib/compression/zlib/zlib.cpp
+++ b/src/lib/compression/zlib/zlib.cpp
@@ -53,7 +53,7 @@ class Zlib_Compression_Stream : public Zlib_Stream
int rc = deflateInit2(streamp(), level, Z_DEFLATED, wbits,
8, Z_DEFAULT_STRATEGY);
if(rc != Z_OK)
- throw std::runtime_error("zlib deflate initialization failed");
+ throw Exception("zlib deflate initialization failed");
}
~Zlib_Compression_Stream()
@@ -68,7 +68,7 @@ class Zlib_Compression_Stream : public Zlib_Stream
if(rc == Z_MEM_ERROR)
throw std::bad_alloc();
else if(rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR)
- throw std::runtime_error("zlib deflate error " + std::to_string(rc));
+ throw Exception("zlib deflate error " + std::to_string(rc));
return (rc == Z_STREAM_END);
}
@@ -84,7 +84,7 @@ class Zlib_Decompression_Stream : public Zlib_Stream
if(rc == Z_MEM_ERROR)
throw std::bad_alloc();
else if(rc != Z_OK)
- throw std::runtime_error("zlib inflate initialization failed");
+ throw Exception("zlib inflate initialization failed");
}
~Zlib_Decompression_Stream()
@@ -99,7 +99,7 @@ class Zlib_Decompression_Stream : public Zlib_Stream
if(rc == Z_MEM_ERROR)
throw std::bad_alloc();
else if(rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR)
- throw std::runtime_error("zlib inflate error " + std::to_string(rc));
+ throw Exception("zlib inflate error " + std::to_string(rc));
return (rc == Z_STREAM_END);
}
@@ -130,7 +130,7 @@ class Gzip_Compression_Stream : public Zlib_Compression_Stream
int rc = deflateSetHeader(streamp(), &m_header);
if(rc != Z_OK)
- throw std::runtime_error("setting gzip header failed");
+ throw Exception("setting gzip header failed");
}
private:
diff --git a/src/lib/entropy/egd/es_egd.cpp b/src/lib/entropy/egd/es_egd.cpp
index c3b75e8f5..8392996ab 100644
--- a/src/lib/entropy/egd/es_egd.cpp
+++ b/src/lib/entropy/egd/es_egd.cpp
@@ -44,7 +44,7 @@ int EGD_EntropySource::EGD_Socket::open_socket(const std::string& path)
addr.sun_family = PF_LOCAL;
if(path.length() >= sizeof(addr.sun_path))
- throw std::invalid_argument("EGD socket path is too long");
+ throw Invalid_Argument("EGD socket path is too long");
std::strncpy(addr.sun_path, path.c_str(), sizeof(addr.sun_path));
@@ -82,19 +82,19 @@ size_t EGD_EntropySource::EGD_Socket::read(byte outbuf[], size_t length)
1, static_cast<byte>(std::min<size_t>(length, 255)) };
if(::write(m_fd, egd_read_command, 2) != 2)
- throw std::runtime_error("Writing entropy read command to EGD failed");
+ throw Exception("Writing entropy read command to EGD failed");
byte out_len = 0;
if(::read(m_fd, &out_len, 1) != 1)
- throw std::runtime_error("Reading response length from EGD failed");
+ throw Exception("Reading response length from EGD failed");
if(out_len > egd_read_command[1])
- throw std::runtime_error("Bogus length field received from EGD");
+ throw Exception("Bogus length field received from EGD");
ssize_t count = ::read(m_fd, outbuf, out_len);
if(count != out_len)
- throw std::runtime_error("Reading entropy result from EGD failed");
+ throw Exception("Reading entropy result from EGD failed");
return static_cast<size_t>(count);
}
diff --git a/src/lib/entropy/unix_procs/unix_procs.cpp b/src/lib/entropy/unix_procs/unix_procs.cpp
index 44d9772e5..30ea6157b 100644
--- a/src/lib/entropy/unix_procs/unix_procs.cpp
+++ b/src/lib/entropy/unix_procs/unix_procs.cpp
@@ -82,7 +82,7 @@ void UnixProcessInfo_EntropySource::poll(Entropy_Accumulator& accum)
void Unix_EntropySource::Unix_Process::spawn(const std::vector<std::string>& args)
{
if(args.empty())
- throw std::invalid_argument("Cannot spawn process without path");
+ throw Invalid_Argument("Cannot spawn process without path");
shutdown();
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp
index eaf24eca6..dac4cafad 100644
--- a/src/lib/ffi/ffi.cpp
+++ b/src/lib/ffi/ffi.cpp
@@ -59,7 +59,7 @@
namespace {
#define BOTAN_ASSERT_ARG_NON_NULL(p) \
- do { if(!p) throw std::invalid_argument("Argument " #p " is null"); } while(0)
+ do { if(!p) throw Invalid_Argument("Argument " #p " is null"); } while(0)
template<typename T, uint32_t MAGIC>
struct botan_struct
@@ -71,7 +71,7 @@ struct botan_struct
T* get() const
{
if(m_magic != MAGIC)
- throw std::runtime_error("Bad magic " + std::to_string(m_magic) +
+ throw Exception("Bad magic " + std::to_string(m_magic) +
" in ffi object expected " + std::to_string(MAGIC));
return m_obj.get();
}
@@ -95,10 +95,10 @@ template<typename T, uint32_t M>
T& safe_get(botan_struct<T,M>* p)
{
if(!p)
- throw std::runtime_error("Null pointer argument");
+ throw Exception("Null pointer argument");
if(T* t = p->get())
return *t;
- throw std::runtime_error("Invalid object pointer");
+ throw Exception("Invalid object pointer");
}
template<typename T, uint32_t M, typename F>
@@ -107,7 +107,7 @@ int apply_fn(botan_struct<T, M>* o, const char* func_name, F func)
try
{
if(!o)
- throw std::runtime_error("Null object to " + std::string(func_name));
+ throw Exception("Null object to " + std::string(func_name));
if(T* t = o->get())
return func(*t);
}
@@ -677,7 +677,7 @@ int botan_bcrypt_generate(uint8_t* out, size_t* out_len,
return BOTAN_FFI_ERROR_BAD_FLAG;
if(wf < 2 || wf > 30)
- throw std::runtime_error("Bad bcrypt work factor " + std::to_string(wf));
+ throw Exception("Bad bcrypt work factor " + std::to_string(wf));
#if defined(BOTAN_HAS_BCRYPT)
Botan::RandomNumberGenerator& rng = safe_get(rng_obj);
diff --git a/src/lib/filters/buf_filt.cpp b/src/lib/filters/buf_filt.cpp
index b03e7fdab..eb978cffd 100644
--- a/src/lib/filters/buf_filt.cpp
+++ b/src/lib/filters/buf_filt.cpp
@@ -19,10 +19,10 @@ Buffered_Filter::Buffered_Filter(size_t b, size_t f) :
main_block_mod(b), final_minimum(f)
{
if(main_block_mod == 0)
- throw std::invalid_argument("main_block_mod == 0");
+ throw Invalid_Argument("main_block_mod == 0");
if(final_minimum > main_block_mod)
- throw std::invalid_argument("final_minimum > main_block_mod");
+ throw Invalid_Argument("final_minimum > main_block_mod");
buffer.resize(2 * main_block_mod);
buffer_pos = 0;
@@ -82,7 +82,7 @@ void Buffered_Filter::write(const byte input[], size_t input_size)
void Buffered_Filter::end_msg()
{
if(buffer_pos < final_minimum)
- throw std::runtime_error("Buffered filter end_msg without enough input");
+ throw Exception("Buffered filter end_msg without enough input");
size_t spare_blocks = (buffer_pos - final_minimum) / main_block_mod;
diff --git a/src/lib/filters/codec_filt/b64_filt.cpp b/src/lib/filters/codec_filt/b64_filt.cpp
index df3cad6a4..a4656dbe6 100644
--- a/src/lib/filters/codec_filt/b64_filt.cpp
+++ b/src/lib/filters/codec_filt/b64_filt.cpp
@@ -177,7 +177,7 @@ void Base64_Decoder::end_msg()
position = 0;
if(not_full_bytes)
- throw std::invalid_argument("Base64_Decoder: Input not full bytes");
+ throw Invalid_Argument("Base64_Decoder: Input not full bytes");
}
}
diff --git a/src/lib/filters/codec_filt/hex_filt.cpp b/src/lib/filters/codec_filt/hex_filt.cpp
index 05af72680..e1a7dc9a5 100644
--- a/src/lib/filters/codec_filt/hex_filt.cpp
+++ b/src/lib/filters/codec_filt/hex_filt.cpp
@@ -166,7 +166,7 @@ void Hex_Decoder::end_msg()
position = 0;
if(not_full_bytes)
- throw std::invalid_argument("Hex_Decoder: Input not full bytes");
+ throw Invalid_Argument("Hex_Decoder: Input not full bytes");
}
}
diff --git a/src/lib/filters/comp_filter.cpp b/src/lib/filters/comp_filter.cpp
index f909db4a7..ab11526dd 100644
--- a/src/lib/filters/comp_filter.cpp
+++ b/src/lib/filters/comp_filter.cpp
@@ -26,12 +26,12 @@ Compression_Decompression_Filter::Compression_Decompression_Filter(Transform* tr
{
if (!transform)
{
- throw std::invalid_argument("Transform is null");
+ throw Invalid_Argument("Transform is null");
}
m_transform.reset(dynamic_cast<Compressor_Transform*>(transform));
if(!m_transform)
{
- throw std::invalid_argument("Transform " + transform->name() + " is not a compressor");
+ throw Invalid_Argument("Transform " + transform->name() + " is not a compressor");
}
}
diff --git a/src/lib/filters/transform_filter.cpp b/src/lib/filters/transform_filter.cpp
index 1b709012e..27a22f9bd 100644
--- a/src/lib/filters/transform_filter.cpp
+++ b/src/lib/filters/transform_filter.cpp
@@ -63,7 +63,7 @@ void Transform_Filter::set_key(const SymmetricKey& key)
if(Keyed_Transform* keyed = dynamic_cast<Keyed_Transform*>(m_transform.get()))
keyed->set_key(key);
else if(key.length() != 0)
- throw std::runtime_error("Transform " + name() + " does not accept keys");
+ throw Exception("Transform " + name() + " does not accept keys");
}
Key_Length_Specification Transform_Filter::key_spec() const
diff --git a/src/lib/hash/comb4p/comb4p.cpp b/src/lib/hash/comb4p/comb4p.cpp
index 4222eaf54..791d6d950 100644
--- a/src/lib/hash/comb4p/comb4p.cpp
+++ b/src/lib/hash/comb4p/comb4p.cpp
@@ -50,10 +50,10 @@ Comb4P::Comb4P(HashFunction* h1, HashFunction* h2) :
m_hash1(h1), m_hash2(h2)
{
if(m_hash1->name() == m_hash2->name())
- throw std::invalid_argument("Comb4P: Must use two distinct hashes");
+ throw Invalid_Argument("Comb4P: Must use two distinct hashes");
if(m_hash1->output_length() != m_hash2->output_length())
- throw std::invalid_argument("Comb4P: Incompatible hashes " +
+ throw Invalid_Argument("Comb4P: Incompatible hashes " +
m_hash1->name() + " and " +
m_hash2->name());
diff --git a/src/lib/mac/cmac/cmac.cpp b/src/lib/mac/cmac/cmac.cpp
index 27edda233..1501bc316 100644
--- a/src/lib/mac/cmac/cmac.cpp
+++ b/src/lib/mac/cmac/cmac.cpp
@@ -55,7 +55,7 @@ secure_vector<byte> CMAC::poly_double(const secure_vector<byte>& in)
out[out.size()-1] ^= 0x25;
break;
default:
- throw std::runtime_error("Unsupported CMAC size " + std::to_string(in.size()));
+ throw Exception("Unsupported CMAC size " + std::to_string(in.size()));
}
}
diff --git a/src/lib/math/bigint/big_io.cpp b/src/lib/math/bigint/big_io.cpp
index 3e66f788d..779f8ccb7 100644
--- a/src/lib/math/bigint/big_io.cpp
+++ b/src/lib/math/bigint/big_io.cpp
@@ -19,7 +19,7 @@ std::ostream& operator<<(std::ostream& stream, const BigInt& n)
if(stream.flags() & std::ios::hex)
base = BigInt::Hexadecimal;
else if(stream.flags() & std::ios::oct)
- throw std::runtime_error("Octal output of BigInt not supported");
+ throw Exception("Octal output of BigInt not supported");
if(n == 0)
stream.write("0", 1);
diff --git a/src/lib/math/ec_gfp/point_gfp.cpp b/src/lib/math/ec_gfp/point_gfp.cpp
index c81c4ee5a..93508ba55 100644
--- a/src/lib/math/ec_gfp/point_gfp.cpp
+++ b/src/lib/math/ec_gfp/point_gfp.cpp
@@ -323,7 +323,7 @@ Blinded_Point_Multiply::Blinded_Point_Multiply(const PointGFp& base, const BigIn
{
// Upper bound is a sanity check rather than hard limit
if(m_h < 1 || m_h > 8)
- throw std::invalid_argument("Blinded_Point_Multiply invalid h param");
+ throw Invalid_Argument("Blinded_Point_Multiply invalid h param");
const CurveGFp& curve = base.get_curve();
@@ -362,7 +362,7 @@ PointGFp Blinded_Point_Multiply::blinded_multiply(const BigInt& scalar_in,
RandomNumberGenerator& rng)
{
if(scalar_in.is_negative())
- throw std::invalid_argument("Blinded_Point_Multiply scalar must be positive");
+ throw Invalid_Argument("Blinded_Point_Multiply scalar must be positive");
#if BOTAN_POINTGFP_SCALAR_BLINDING_BITS > 0
// Choose a small mask m and use k' = k + m*order (Coron's 1st countermeasure)
diff --git a/src/lib/math/mp/mp_misc.cpp b/src/lib/math/mp/mp_misc.cpp
index 542b0509e..adf4a0a6b 100644
--- a/src/lib/math/mp/mp_misc.cpp
+++ b/src/lib/math/mp/mp_misc.cpp
@@ -43,7 +43,7 @@ s32bit bigint_cmp(const word x[], size_t x_size,
word bigint_divop(word n1, word n0, word d)
{
if(d == 0)
- throw std::runtime_error("bigint_divop divide by zero");
+ throw Exception("bigint_divop divide by zero");
word high = n1 % d, quotient = 0;
diff --git a/src/lib/math/numbertheory/numthry.cpp b/src/lib/math/numbertheory/numthry.cpp
index 900e61724..31dd72feb 100644
--- a/src/lib/math/numbertheory/numthry.cpp
+++ b/src/lib/math/numbertheory/numthry.cpp
@@ -177,7 +177,7 @@ BigInt inverse_mod(const BigInt& n, const BigInt& mod)
word monty_inverse(word input)
{
if(input == 0)
- throw std::runtime_error("monty_inverse: divide by zero");
+ throw Exception("monty_inverse: divide by zero");
word b = input;
word x2 = 1, x1 = 0, y2 = 0, y1 = 1;
diff --git a/src/lib/misc/benchmark/benchmark.cpp b/src/lib/misc/benchmark/benchmark.cpp
index d5e3694b5..4ecca1566 100644
--- a/src/lib/misc/benchmark/benchmark.cpp
+++ b/src/lib/misc/benchmark/benchmark.cpp
@@ -119,7 +119,7 @@ double find_first_in(const std::map<std::string, double>& m,
return i->second;
}
- throw std::runtime_error("In algo benchmark no usable keys found in result");
+ throw Exception("In algo benchmark no usable keys found in result");
}
std::set<std::string> get_all_providers_of(const std::string& algo)
diff --git a/src/lib/misc/fpe_fe1/fpe_fe1.cpp b/src/lib/misc/fpe_fe1/fpe_fe1.cpp
index f2502014b..bc14c425c 100644
--- a/src/lib/misc/fpe_fe1/fpe_fe1.cpp
+++ b/src/lib/misc/fpe_fe1/fpe_fe1.cpp
@@ -57,7 +57,7 @@ void factor(BigInt n, BigInt& a, BigInt& b)
std::swap(a, b);
if(a <= 1 || b <= 1)
- throw std::runtime_error("Could not factor n for use in FPE");
+ throw Exception("Could not factor n for use in FPE");
}
/*
@@ -100,7 +100,7 @@ FPE_Encryptor::FPE_Encryptor(const SymmetricKey& key,
std::vector<byte> n_bin = BigInt::encode(n);
if(n_bin.size() > MAX_N_BYTES)
- throw std::runtime_error("N is too large for FPE encryption");
+ throw Exception("N is too large for FPE encryption");
mac->update_be(static_cast<u32bit>(n_bin.size()));
mac->update(n_bin.data(), n_bin.size());
diff --git a/src/lib/misc/rfc3394/rfc3394.cpp b/src/lib/misc/rfc3394/rfc3394.cpp
index 582e8c92d..1044e4de4 100644
--- a/src/lib/misc/rfc3394/rfc3394.cpp
+++ b/src/lib/misc/rfc3394/rfc3394.cpp
@@ -16,10 +16,10 @@ secure_vector<byte> rfc3394_keywrap(const secure_vector<byte>& key,
const SymmetricKey& kek)
{
if(key.size() % 8 != 0)
- throw std::invalid_argument("Bad input key size for NIST key wrap");
+ throw Invalid_Argument("Bad input key size for NIST key wrap");
if(kek.size() != 16 && kek.size() != 24 && kek.size() != 32)
- throw std::invalid_argument("Bad KEK length " + std::to_string(kek.size()) + " for NIST key wrap");
+ throw Invalid_Argument("Bad KEK length " + std::to_string(kek.size()) + " for NIST key wrap");
const std::string cipher_name = "AES-" + std::to_string(8*kek.size());
std::unique_ptr<BlockCipher> aes(BlockCipher::create(cipher_name));
@@ -63,10 +63,10 @@ secure_vector<byte> rfc3394_keyunwrap(const secure_vector<byte>& key,
const SymmetricKey& kek)
{
if(key.size() < 16 || key.size() % 8 != 0)
- throw std::invalid_argument("Bad input key size for NIST key unwrap");
+ throw Invalid_Argument("Bad input key size for NIST key unwrap");
if(kek.size() != 16 && kek.size() != 24 && kek.size() != 32)
- throw std::invalid_argument("Bad KEK length " + std::to_string(kek.size()) + " for NIST key unwrap");
+ throw Invalid_Argument("Bad KEK length " + std::to_string(kek.size()) + " for NIST key unwrap");
const std::string cipher_name = "AES-" + std::to_string(8*kek.size());
std::unique_ptr<BlockCipher> aes(BlockCipher::create(cipher_name));
diff --git a/src/lib/misc/srp6/srp6.cpp b/src/lib/misc/srp6/srp6.cpp
index f567db875..7fca6461f 100644
--- a/src/lib/misc/srp6/srp6.cpp
+++ b/src/lib/misc/srp6/srp6.cpp
@@ -70,7 +70,7 @@ std::string srp6_group_identifier(const BigInt& N, const BigInt& g)
if(group.get_p() == N && group.get_g() == g)
return group_name;
- throw std::runtime_error("Unknown SRP params");
+ throw Exception("Unknown SRP params");
}
catch(...)
{
@@ -94,7 +94,7 @@ srp6_client_agree(const std::string& identifier,
const size_t p_bytes = group.get_p().bytes();
if(B <= 0 || B >= p)
- throw std::runtime_error("Invalid SRP parameter from server");
+ throw Exception("Invalid SRP parameter from server");
BigInt k = hash_seq(hash_id, p_bytes, p, g);
@@ -150,7 +150,7 @@ BigInt SRP6_Server_Session::step1(const BigInt& v,
SymmetricKey SRP6_Server_Session::step2(const BigInt& A)
{
if(A <= 0 || A >= m_p)
- throw std::runtime_error("Invalid SRP parameter from client");
+ throw Exception("Invalid SRP parameter from client");
const BigInt u = hash_seq(m_hash_id, m_p_bytes, A, m_B);
diff --git a/src/lib/modes/aead/ccm/ccm.cpp b/src/lib/modes/aead/ccm/ccm.cpp
index bd4e0f4be..df33685f3 100644
--- a/src/lib/modes/aead/ccm/ccm.cpp
+++ b/src/lib/modes/aead/ccm/ccm.cpp
@@ -20,13 +20,13 @@ CCM_Mode::CCM_Mode(BlockCipher* cipher, size_t tag_size, size_t L) :
m_cipher(cipher)
{
if(m_cipher->block_size() != BS)
- throw std::invalid_argument(m_cipher->name() + " cannot be used with CCM mode");
+ throw Invalid_Argument(m_cipher->name() + " cannot be used with CCM mode");
if(L < 2 || L > 8)
- throw std::invalid_argument("Invalid CCM L value " + std::to_string(L));
+ throw Invalid_Argument("Invalid CCM L value " + std::to_string(L));
if(tag_size < 4 || tag_size > 16 || tag_size % 2 != 0)
- throw std::invalid_argument("invalid CCM tag length " + std::to_string(tag_size));
+ throw Invalid_Argument("invalid CCM tag length " + std::to_string(tag_size));
}
void CCM_Mode::clear()
diff --git a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp
index 0aef6a747..2350e2e6a 100644
--- a/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp
+++ b/src/lib/modes/aead/chacha20poly1305/chacha20poly1305.cpp
@@ -39,7 +39,7 @@ void ChaCha20Poly1305_Mode::key_schedule(const byte key[], size_t length)
void ChaCha20Poly1305_Mode::set_associated_data(const byte ad[], size_t length)
{
if(m_ctext_len)
- throw std::runtime_error("Too late to set AD for ChaCha20Poly1305");
+ throw Exception("Too late to set AD for ChaCha20Poly1305");
m_ad.assign(ad, ad + length);
}
diff --git a/src/lib/modes/aead/gcm/gcm.cpp b/src/lib/modes/aead/gcm/gcm.cpp
index 15820069d..a77c3e4d4 100644
--- a/src/lib/modes/aead/gcm/gcm.cpp
+++ b/src/lib/modes/aead/gcm/gcm.cpp
@@ -163,7 +163,7 @@ GCM_Mode::GCM_Mode(BlockCipher* cipher, size_t tag_size) :
m_cipher_name(cipher->name())
{
if(cipher->block_size() != BS)
- throw std::invalid_argument("GCM requires a 128 bit cipher so cannot be used with " +
+ throw Invalid_Argument("GCM requires a 128 bit cipher so cannot be used with " +
cipher->name());
m_ghash.reset(new GHASH);
diff --git a/src/lib/modes/aead/ocb/ocb.cpp b/src/lib/modes/aead/ocb/ocb.cpp
index ff3317dd9..08157cd47 100644
--- a/src/lib/modes/aead/ocb/ocb.cpp
+++ b/src/lib/modes/aead/ocb/ocb.cpp
@@ -123,10 +123,10 @@ OCB_Mode::OCB_Mode(BlockCipher* cipher, size_t tag_size) :
m_tag_size(tag_size)
{
if(BS() != 16)
- throw std::invalid_argument("OCB is not compatible with " + m_cipher->name());
+ throw Invalid_Argument("OCB is not compatible with " + m_cipher->name());
if(m_tag_size % 4 != 0 || m_tag_size < 8 || m_tag_size > BS())
- throw std::invalid_argument("OCB cannot produce a " + std::to_string(m_tag_size) +
+ throw Invalid_Argument("OCB cannot produce a " + std::to_string(m_tag_size) +
" byte tag");
}
diff --git a/src/lib/modes/cbc/cbc.cpp b/src/lib/modes/cbc/cbc.cpp
index 1e3c6d6e3..fedeaf20d 100644
--- a/src/lib/modes/cbc/cbc.cpp
+++ b/src/lib/modes/cbc/cbc.cpp
@@ -17,7 +17,7 @@ CBC_Mode::CBC_Mode(BlockCipher* cipher, BlockCipherModePaddingMethod* padding) :
m_state(m_cipher->block_size())
{
if(m_padding && !m_padding->valid_blocksize(cipher->block_size()))
- throw std::invalid_argument("Padding " + m_padding->name() +
+ throw Invalid_Argument("Padding " + m_padding->name() +
" cannot be used with " +
cipher->name() + "/CBC");
}
@@ -127,7 +127,7 @@ void CBC_Encryption::finish(secure_vector<byte>& buffer, size_t offset)
padding().add_padding(buffer, bytes_in_final_block, BS);
if((buffer.size()-offset) % BS)
- throw std::runtime_error("Did not pad to full block size in " + name());
+ throw Exception("Did not pad to full block size in " + name());
update(buffer, offset);
}
diff --git a/src/lib/modes/cfb/cfb.cpp b/src/lib/modes/cfb/cfb.cpp
index 7c7ed1865..6c9239e73 100644
--- a/src/lib/modes/cfb/cfb.cpp
+++ b/src/lib/modes/cfb/cfb.cpp
@@ -16,7 +16,7 @@ CFB_Mode::CFB_Mode(BlockCipher* cipher, size_t feedback_bits) :
m_feedback_bytes(feedback_bits ? feedback_bits / 8 : cipher->block_size())
{
if(feedback_bits % 8 || feedback() > cipher->block_size())
- throw std::invalid_argument(name() + ": feedback bits " +
+ throw Invalid_Argument(name() + ": feedback bits " +
std::to_string(feedback_bits) + " not supported");
}
diff --git a/src/lib/modes/ecb/ecb.cpp b/src/lib/modes/ecb/ecb.cpp
index 14e72e20b..407b5c582 100644
--- a/src/lib/modes/ecb/ecb.cpp
+++ b/src/lib/modes/ecb/ecb.cpp
@@ -15,7 +15,7 @@ ECB_Mode::ECB_Mode(BlockCipher* cipher, BlockCipherModePaddingMethod* padding) :
m_padding(padding)
{
if(!m_padding->valid_blocksize(cipher->block_size()))
- throw std::invalid_argument("Padding " + m_padding->name() +
+ throw Invalid_Argument("Padding " + m_padding->name() +
" cannot be used with " +
cipher->name() + "/ECB");
}
@@ -102,7 +102,7 @@ void ECB_Encryption::finish(secure_vector<byte>& buffer, size_t offset)
padding().add_padding(buffer, bytes_in_final_block, BS);
if(buffer.size() % BS)
- throw std::runtime_error("Did not pad to full block size in " + name());
+ throw Exception("Did not pad to full block size in " + name());
update(buffer, offset);
}
diff --git a/src/lib/modes/xts/xts.cpp b/src/lib/modes/xts/xts.cpp
index c42988d10..b369fde29 100644
--- a/src/lib/modes/xts/xts.cpp
+++ b/src/lib/modes/xts/xts.cpp
@@ -51,7 +51,7 @@ inline void poly_double(byte out[], const byte in[], size_t size)
XTS_Mode::XTS_Mode(BlockCipher* cipher) : m_cipher(cipher)
{
if(m_cipher->block_size() != 8 && m_cipher->block_size() != 16)
- throw std::invalid_argument("Bad cipher for XTS: " + cipher->name());
+ throw Invalid_Argument("Bad cipher for XTS: " + cipher->name());
m_tweak_cipher.reset(m_cipher->clone());
m_tweak.resize(update_granularity());
diff --git a/src/lib/passhash/passhash9/passhash9.cpp b/src/lib/passhash/passhash9/passhash9.cpp
index b457fc5c7..c6a2f7d9e 100644
--- a/src/lib/passhash/passhash9/passhash9.cpp
+++ b/src/lib/passhash/passhash9/passhash9.cpp
@@ -104,7 +104,7 @@ bool check_passhash9(const std::string& pass, const std::string& hash)
return false;
if(work_factor > 512)
- throw std::invalid_argument("Requested Bcrypt work factor " +
+ throw Invalid_Argument("Requested Bcrypt work factor " +
std::to_string(work_factor) + " too large");
const size_t kdf_iterations = WORK_FACTOR_SCALE * work_factor;
diff --git a/src/lib/pbkdf/pbkdf.cpp b/src/lib/pbkdf/pbkdf.cpp
index 6d7a6542f..dcaa48852 100644
--- a/src/lib/pbkdf/pbkdf.cpp
+++ b/src/lib/pbkdf/pbkdf.cpp
@@ -58,7 +58,7 @@ void PBKDF::pbkdf_iterations(byte out[], size_t out_len,
size_t iterations) const
{
if(iterations == 0)
- throw std::invalid_argument(name() + ": Invalid iteration count");
+ throw Invalid_Argument(name() + ": Invalid iteration count");
const size_t iterations_run = pbkdf(out, out_len, passphrase,
salt, salt_len, iterations,
diff --git a/src/lib/pbkdf/pbkdf2/pbkdf2.cpp b/src/lib/pbkdf/pbkdf2/pbkdf2.cpp
index c1ac2c534..30cf7cbdf 100644
--- a/src/lib/pbkdf/pbkdf2/pbkdf2.cpp
+++ b/src/lib/pbkdf/pbkdf2/pbkdf2.cpp
@@ -42,7 +42,7 @@ pbkdf2(MessageAuthenticationCode& prf,
}
catch(Invalid_Key_Length)
{
- throw std::runtime_error("PBKDF2 with " + prf.name() +
+ throw Exception("PBKDF2 with " + prf.name() +
" cannot accept passphrases of length " +
std::to_string(passphrase.size()));
}
diff --git a/src/lib/pubkey/blinding.cpp b/src/lib/pubkey/blinding.cpp
index da9def797..4a5c5acff 100644
--- a/src/lib/pubkey/blinding.cpp
+++ b/src/lib/pubkey/blinding.cpp
@@ -43,7 +43,7 @@ BigInt Blinder::blinding_nonce() const
BigInt Blinder::blind(const BigInt& i) const
{
if(!m_reducer.initialized())
- throw std::runtime_error("Blinder not initialized, cannot blind");
+ throw Exception("Blinder not initialized, cannot blind");
++m_counter;
@@ -65,7 +65,7 @@ BigInt Blinder::blind(const BigInt& i) const
BigInt Blinder::unblind(const BigInt& i) const
{
if(!m_reducer.initialized())
- throw std::runtime_error("Blinder not initialized, cannot unblind");
+ throw Exception("Blinder not initialized, cannot unblind");
return m_reducer.multiply(i, m_d);
}
diff --git a/src/lib/pubkey/dl_group/dl_group.cpp b/src/lib/pubkey/dl_group/dl_group.cpp
index 8e9c35f2a..ed9b60c7c 100644
--- a/src/lib/pubkey/dl_group/dl_group.cpp
+++ b/src/lib/pubkey/dl_group/dl_group.cpp
@@ -314,7 +314,7 @@ BigInt DL_Group::make_dsa_generator(const BigInt& p, const BigInt& q)
const BigInt e = (p - 1) / q;
if(e == 0 || (p - 1) % q > 0)
- throw std::invalid_argument("make_dsa_generator q does not divide p-1");
+ throw Invalid_Argument("make_dsa_generator q does not divide p-1");
for(size_t i = 0; i != PRIME_TABLE_SIZE; ++i)
{
diff --git a/src/lib/pubkey/mce/gf2m_small_m.cpp b/src/lib/pubkey/mce/gf2m_small_m.cpp
index 11da30962..f427ab4f3 100644
--- a/src/lib/pubkey/mce/gf2m_small_m.cpp
+++ b/src/lib/pubkey/mce/gf2m_small_m.cpp
@@ -59,7 +59,7 @@ const std::vector<gf2m>& exp_table(size_t deg)
static std::vector<gf2m> tabs[MAX_EXT_DEG + 1];
if(deg < 2 || deg > MAX_EXT_DEG)
- throw std::runtime_error("GF2m_Field does not support degree " + std::to_string(deg));
+ throw Exception("GF2m_Field does not support degree " + std::to_string(deg));
if(tabs[deg].empty())
tabs[deg] = gf_exp_table(deg, prim_poly[deg]);
@@ -84,7 +84,7 @@ const std::vector<gf2m>& log_table(size_t deg)
static std::vector<gf2m> tabs[MAX_EXT_DEG + 1];
if(deg < 2 || deg > MAX_EXT_DEG)
- throw std::runtime_error("GF2m_Field does not support degree " + std::to_string(deg));
+ throw Exception("GF2m_Field does not support degree " + std::to_string(deg));
if(tabs[deg].empty())
tabs[deg] = gf_log_table(deg, exp_table(deg));
diff --git a/src/lib/pubkey/mce/goppa_code.cpp b/src/lib/pubkey/mce/goppa_code.cpp
index 637b8175a..02908aa4f 100644
--- a/src/lib/pubkey/mce/goppa_code.cpp
+++ b/src/lib/pubkey/mce/goppa_code.cpp
@@ -147,7 +147,7 @@ void mceliece_decrypt(
{
if(pos > code_length)
{
- throw std::invalid_argument("error position larger than code size");
+ throw Invalid_Argument("error position larger than code size");
}
result[pos / 8] |= (1 << (pos % 8));
}
diff --git a/src/lib/pubkey/mceies/mceies.cpp b/src/lib/pubkey/mceies/mceies.cpp
index 301c5dda4..e83fa257e 100644
--- a/src/lib/pubkey/mceies/mceies.cpp
+++ b/src/lib/pubkey/mceies/mceies.cpp
@@ -48,7 +48,7 @@ mceies_encrypt(const McEliece_PublicKey& pubkey,
std::unique_ptr<AEAD_Mode> aead(get_aead(algo, ENCRYPTION));
if(!aead)
- throw std::runtime_error("mce_encrypt unable to create AEAD instance '" + algo + "'");
+ throw Exception("mce_encrypt unable to create AEAD instance '" + algo + "'");
const size_t nonce_len = aead->default_nonce_length();
@@ -81,12 +81,12 @@ mceies_decrypt(const McEliece_PrivateKey& privkey,
std::unique_ptr<AEAD_Mode> aead(get_aead(algo, DECRYPTION));
if(!aead)
- throw std::runtime_error("Unable to create AEAD instance '" + algo + "'");
+ throw Exception("Unable to create AEAD instance '" + algo + "'");
const size_t nonce_len = aead->default_nonce_length();
if(ct_len < mce_code_bytes + nonce_len + aead->tag_size())
- throw std::runtime_error("Input message too small to be valid");
+ throw Exception("Input message too small to be valid");
const secure_vector<byte> mce_key = kem_op.decrypt(ct, mce_code_bytes);
@@ -105,7 +105,7 @@ mceies_decrypt(const McEliece_PrivateKey& privkey,
}
catch(std::exception& e)
{
- throw std::runtime_error("mce_decrypt failed: " + std::string(e.what()));
+ throw Exception("mce_decrypt failed: " + std::string(e.what()));
}
}
diff --git a/src/lib/pubkey/pk_ops.cpp b/src/lib/pubkey/pk_ops.cpp
index 9f264af12..bc421eb90 100644
--- a/src/lib/pubkey/pk_ops.cpp
+++ b/src/lib/pubkey/pk_ops.cpp
@@ -35,7 +35,7 @@ secure_vector<byte> PK_Ops::Encryption_with_EME::encrypt(const byte msg[], size_
const std::vector<byte> encoded = unlock(m_eme->encode(msg, msg_len, max_raw, rng));
if(8*(encoded.size() - 1) + high_bit(encoded[0]) > max_raw)
- throw std::runtime_error("Input is too large to encrypt with this key");
+ throw Exception("Input is too large to encrypt with this key");
return raw_encrypt(encoded.data(), encoded.size(), rng);
}
diff --git a/src/lib/pubkey/pkcs8.cpp b/src/lib/pubkey/pkcs8.cpp
index 7b7b54891..92157a196 100644
--- a/src/lib/pubkey/pkcs8.cpp
+++ b/src/lib/pubkey/pkcs8.cpp
@@ -81,7 +81,7 @@ secure_vector<byte> PKCS8_decode(
if(is_encrypted)
{
if(OIDS::lookup(pbe_alg_id.oid) != "PBE-PKCS5v20")
- throw std::runtime_error("Unknown PBE type " + pbe_alg_id.oid.as_string());
+ throw Exception("Unknown PBE type " + pbe_alg_id.oid.as_string());
key = pbes2_decrypt(key_data, get_passphrase(), pbe_alg_id.parameters);
}
else
@@ -144,7 +144,7 @@ choose_pbe_params(const std::string& pbe_algo, const std::string& key_algo)
SCAN_Name request(pbe_algo);
if(request.algo_name() != "PBE-PKCS5v20" || request.arg_count() != 2)
- throw std::runtime_error("Unsupported PBE " + pbe_algo);
+ throw Exception("Unsupported PBE " + pbe_algo);
return std::make_pair(request.arg(1), request.arg(0));
}
diff --git a/src/lib/rng/rng.h b/src/lib/rng/rng.h
index 1ce0d5153..23e974b92 100644
--- a/src/lib/rng/rng.h
+++ b/src/lib/rng/rng.h
@@ -66,7 +66,7 @@ class BOTAN_DLL RandomNumberGenerator
u64bit gen_mask(size_t bits)
{
if(bits == 0 || bits > 64)
- throw std::invalid_argument("RandomNumberGenerator::gen_mask invalid argument");
+ throw Invalid_Argument("RandomNumberGenerator::gen_mask invalid argument");
const u64bit mask = ((1 << bits) - 1);
return this->get_random<u64bit>() & mask;
diff --git a/src/lib/rng/system_rng/system_rng.cpp b/src/lib/rng/system_rng/system_rng.cpp
index 50ec696a0..81e235a8c 100644
--- a/src/lib/rng/system_rng/system_rng.cpp
+++ b/src/lib/rng/system_rng/system_rng.cpp
@@ -66,7 +66,7 @@ System_RNG_Impl::System_RNG_Impl()
#if defined(BOTAN_TARGET_OS_HAS_CRYPTGENRANDOM)
if(!CryptAcquireContext(&m_prov, 0, 0, BOTAN_SYSTEM_RNG_CRYPTOAPI_PROV_TYPE, CRYPT_VERIFYCONTEXT))
- throw std::runtime_error("System_RNG failed to acquire crypto provider");
+ throw Exception("System_RNG failed to acquire crypto provider");
#else
@@ -76,7 +76,7 @@ System_RNG_Impl::System_RNG_Impl()
m_fd = ::open(BOTAN_SYSTEM_RNG_DEVICE, O_RDONLY | O_NOCTTY);
if(m_fd < 0)
- throw std::runtime_error("System_RNG failed to open RNG device");
+ throw Exception("System_RNG failed to open RNG device");
#endif
}
@@ -103,10 +103,10 @@ void System_RNG_Impl::randomize(byte buf[], size_t len)
{
if(errno == EINTR)
continue;
- throw std::runtime_error("System_RNG read failed error " + std::to_string(errno));
+ throw Exception("System_RNG read failed error " + std::to_string(errno));
}
if(got == 0)
- throw std::runtime_error("System_RNG EOF on device"); // ?!?
+ throw Exception("System_RNG EOF on device"); // ?!?
buf += got;
len -= got;
diff --git a/src/lib/tls/credentials_manager.cpp b/src/lib/tls/credentials_manager.cpp
index 3762dc149..650d922ce 100644
--- a/src/lib/tls/credentials_manager.cpp
+++ b/src/lib/tls/credentials_manager.cpp
@@ -123,7 +123,7 @@ void Credentials_Manager::verify_certificate_chain(
const std::vector<X509_Certificate>& cert_chain)
{
if(cert_chain.empty())
- throw std::invalid_argument("Certificate chain was empty");
+ throw Invalid_Argument("Certificate chain was empty");
auto trusted_CAs = trusted_certificate_authorities(type, purported_hostname);
@@ -136,10 +136,10 @@ void Credentials_Manager::verify_certificate_chain(
choose_leaf_usage(type));
if(!result.successful_validation())
- throw std::runtime_error("Certificate validation failure: " + result.result_string());
+ throw Exception("Certificate validation failure: " + result.result_string());
if(!cert_in_some_store(trusted_CAs, result.trust_root()))
- throw std::runtime_error("Certificate chain roots in unknown/untrusted CA");
+ throw Exception("Certificate chain roots in unknown/untrusted CA");
}
}
diff --git a/src/lib/tls/msg_client_hello.cpp b/src/lib/tls/msg_client_hello.cpp
index 77bdc5cf5..ce20d6781 100644
--- a/src/lib/tls/msg_client_hello.cpp
+++ b/src/lib/tls/msg_client_hello.cpp
@@ -155,7 +155,7 @@ Client_Hello::Client_Hello(Handshake_IO& io,
void Client_Hello::update_hello_cookie(const Hello_Verify_Request& hello_verify)
{
if(!m_version.is_datagram_protocol())
- throw std::runtime_error("Cannot use hello cookie with stream protocol");
+ throw Exception("Cannot use hello cookie with stream protocol");
m_hello_cookie = hello_verify.cookie();
}
diff --git a/src/lib/tls/sessions_sql/tls_session_manager_sql.cpp b/src/lib/tls/sessions_sql/tls_session_manager_sql.cpp
index 9f025374e..e13401c1d 100644
--- a/src/lib/tls/sessions_sql/tls_session_manager_sql.cpp
+++ b/src/lib/tls/sessions_sql/tls_session_manager_sql.cpp
@@ -68,14 +68,14 @@ Session_Manager_SQL::Session_Manager_SQL(std::shared_ptr<SQL_Database> db,
m_session_key.assign(x.begin() + 2, x.end());
if(check_val_created != check_val_db)
- throw std::runtime_error("Session database password not valid");
+ throw Exception("Session database password not valid");
}
}
else
{
// maybe just zap the salts + sessions tables in this case?
if(salts != 0)
- throw std::runtime_error("Seemingly corrupted database, multiple salts found");
+ throw Exception("Seemingly corrupted database, multiple salts found");
// new database case
diff --git a/src/lib/tls/tls_channel.cpp b/src/lib/tls/tls_channel.cpp
index 5dfcec34e..c7adc18cd 100644
--- a/src/lib/tls/tls_channel.cpp
+++ b/src/lib/tls/tls_channel.cpp
@@ -100,7 +100,7 @@ Handshake_State& Channel::create_handshake_state(Protocol_Version version)
Protocol_Version active_version = active->version();
if(active_version.is_datagram_protocol() != version.is_datagram_protocol())
- throw std::runtime_error("Active state using version " +
+ throw Exception("Active state using version " +
active_version.to_string() +
" cannot change to " +
version.to_string() +
@@ -158,7 +158,7 @@ void Channel::renegotiate(bool force_full_renegotiation)
initiate_handshake(create_handshake_state(active->version()),
force_full_renegotiation);
else
- throw std::runtime_error("Cannot renegotiate on inactive connection");
+ throw Exception("Cannot renegotiate on inactive connection");
}
size_t Channel::maximum_fragment_size() const
@@ -571,7 +571,7 @@ void Channel::send_record_under_epoch(u16bit epoch, byte record_type,
void Channel::send(const byte buf[], size_t buf_size)
{
if(!is_active())
- throw std::runtime_error("Data cannot be sent on inactive TLS connection");
+ throw Exception("Data cannot be sent on inactive TLS connection");
send_record_array(sequence_numbers().current_write_epoch(),
APPLICATION_DATA, buf, buf_size);
@@ -701,7 +701,7 @@ SymmetricKey Channel::key_material_export(const std::string& label,
{
size_t context_size = context.length();
if(context_size > 0xFFFF)
- throw std::runtime_error("key_material_export context is too long");
+ throw Exception("key_material_export context is too long");
salt.push_back(get_byte<u16bit>(0, context_size));
salt.push_back(get_byte<u16bit>(1, context_size));
salt += to_byte_vector(context);
@@ -710,7 +710,7 @@ SymmetricKey Channel::key_material_export(const std::string& label,
return prf->derive_key(length, master_secret, salt);
}
else
- throw std::runtime_error("Channel::key_material_export connection not active");
+ throw Exception("Channel::key_material_export connection not active");
}
}
diff --git a/src/lib/tls/tls_ciphersuite.cpp b/src/lib/tls/tls_ciphersuite.cpp
index 4fdf33811..d14376bdd 100644
--- a/src/lib/tls/tls_ciphersuite.cpp
+++ b/src/lib/tls/tls_ciphersuite.cpp
@@ -208,7 +208,7 @@ bool Ciphersuite::valid() const
std::string Ciphersuite::to_string() const
{
if(m_cipher_keylen == 0)
- throw std::runtime_error("Ciphersuite::to_string - no value set");
+ throw Exception("Ciphersuite::to_string - no value set");
std::ostringstream out;
diff --git a/src/lib/tls/tls_extensions.cpp b/src/lib/tls/tls_extensions.cpp
index 5f28c98b8..06efebb4b 100644
--- a/src/lib/tls/tls_extensions.cpp
+++ b/src/lib/tls/tls_extensions.cpp
@@ -228,7 +228,7 @@ std::vector<byte> Maximum_Fragment_Length::serialize() const
case 4096:
return std::vector<byte>(1, 4);
default:
- throw std::invalid_argument("Bad setting " +
+ throw Invalid_Argument("Bad setting " +
std::to_string(m_max_fragment) +
" for maximum fragment size");
}
diff --git a/src/lib/tls/tls_heartbeats.cpp b/src/lib/tls/tls_heartbeats.cpp
index 11c9a355f..14f7db51c 100644
--- a/src/lib/tls/tls_heartbeats.cpp
+++ b/src/lib/tls/tls_heartbeats.cpp
@@ -43,9 +43,9 @@ Heartbeat_Message::Heartbeat_Message(Type type,
m_padding(padding)
{
if(payload_len >= 64*1024)
- throw std::runtime_error("Heartbeat payload too long");
+ throw Exception("Heartbeat payload too long");
if(m_padding.size() < 16)
- throw std::runtime_error("Invalid heartbeat padding length");
+ throw Exception("Invalid heartbeat padding length");
}
std::vector<byte> Heartbeat_Message::contents() const
diff --git a/src/lib/tls/tls_policy.h b/src/lib/tls/tls_policy.h
index c3f8f1ee2..4d496cc7d 100644
--- a/src/lib/tls/tls_policy.h
+++ b/src/lib/tls/tls_policy.h
@@ -354,7 +354,7 @@ class BOTAN_DLL Text_Policy : public Policy
else if(v == "false" || v == "False")
return false;
else
- throw std::runtime_error("Invalid boolean '" + v + "'");
+ throw Exception("Invalid boolean '" + v + "'");
}
std::string get_str(const std::string& key, const std::string& def = "") const
diff --git a/src/lib/tls/tls_reader.h b/src/lib/tls/tls_reader.h
index 63a59625f..7dd9fde57 100644
--- a/src/lib/tls/tls_reader.h
+++ b/src/lib/tls/tls_reader.h
@@ -192,11 +192,11 @@ void append_tls_length_value(std::vector<byte, Alloc>& buf,
const size_t val_bytes = T_size * vals_size;
if(tag_size != 1 && tag_size != 2)
- throw std::invalid_argument("append_tls_length_value: invalid tag size");
+ throw Invalid_Argument("append_tls_length_value: invalid tag size");
if((tag_size == 1 && val_bytes > 255) ||
(tag_size == 2 && val_bytes > 65535))
- throw std::invalid_argument("append_tls_length_value: value too large");
+ throw Invalid_Argument("append_tls_length_value: value too large");
for(size_t i = 0; i != tag_size; ++i)
buf.push_back(get_byte(sizeof(val_bytes)-tag_size+i, val_bytes));
diff --git a/src/lib/tls/tls_seq_numbers.h b/src/lib/tls/tls_seq_numbers.h
index 8ce6ed3be..2071c810d 100644
--- a/src/lib/tls/tls_seq_numbers.h
+++ b/src/lib/tls/tls_seq_numbers.h
@@ -79,7 +79,7 @@ class Datagram_Sequence_Numbers : public Connection_Sequence_Numbers
u64bit next_read_sequence() override
{
- throw std::runtime_error("DTLS uses explicit sequence numbers");
+ throw Exception("DTLS uses explicit sequence numbers");
}
bool already_seen(u64bit sequence) const override
diff --git a/src/lib/utils/assert.cpp b/src/lib/utils/assert.cpp
index 978fc12a1..d729a8368 100644
--- a/src/lib/utils/assert.cpp
+++ b/src/lib/utils/assert.cpp
@@ -30,7 +30,7 @@ void assertion_failure(const char* expr_str,
format << "@" << file << ":" << line;
- throw std::runtime_error(format.str());
+ throw Exception(format.str());
}
}
diff --git a/src/lib/utils/dyn_load/dyn_load.cpp b/src/lib/utils/dyn_load/dyn_load.cpp
index 723d2502e..9b99331d1 100644
--- a/src/lib/utils/dyn_load/dyn_load.cpp
+++ b/src/lib/utils/dyn_load/dyn_load.cpp
@@ -22,7 +22,7 @@ namespace {
void raise_runtime_loader_exception(const std::string& lib_name,
const char* msg)
{
- throw std::runtime_error("Failed to load " + lib_name + ": " +
+ throw Exception("Failed to load " + lib_name + ": " +
(msg ? msg : "Unknown error"));
}
@@ -70,7 +70,7 @@ void* Dynamically_Loaded_Library::resolve_symbol(const std::string& symbol)
#endif
if(!addr)
- throw std::runtime_error("Failed to resolve symbol " + symbol +
+ throw Exception("Failed to resolve symbol " + symbol +
" in " + lib_name);
return addr;
diff --git a/src/lib/utils/exceptn.h b/src/lib/utils/exceptn.h
index eef1b4d43..c9b45f916 100644
--- a/src/lib/utils/exceptn.h
+++ b/src/lib/utils/exceptn.h
@@ -16,8 +16,28 @@
namespace Botan {
-typedef std::runtime_error Exception;
-typedef std::invalid_argument Invalid_Argument;
+/**
+* Base class for all exceptions thrown by the library
+*/
+class BOTAN_DLL Exception : public std::exception
+ {
+ public:
+ Exception(const std::string& what) : m_what(what) {}
+ Exception(const char* prefix, const std::string& what) : m_what(std::string(prefix) + " " + what) {}
+ const char* what() const override { return m_what.c_str(); }
+ private:
+ std::string m_what;
+ };
+
+/**
+* An invalid argument which caused
+*/
+class BOTAN_DLL Invalid_Argument : public Exception
+ {
+ public:
+ Invalid_Argument(const std::string& what) :
+ Exception("Invalid argument", what) {}
+ };
/**
* Unsupported_Argument Exception
@@ -196,15 +216,6 @@ struct BOTAN_DLL Self_Test_Failure : public Internal_Error
{}
};
-/**
-* Memory Allocation Exception
-*/
-struct BOTAN_DLL Memory_Exhaustion : public std::bad_alloc
- {
- const char* what() const BOTAN_NOEXCEPT override
- { return "Ran out of memory, allocation failed"; }
- };
-
}
#endif
diff --git a/src/lib/utils/http_util/http_util.cpp b/src/lib/utils/http_util/http_util.cpp
index 1a15d6418..c437d0148 100644
--- a/src/lib/utils/http_util/http_util.cpp
+++ b/src/lib/utils/http_util/http_util.cpp
@@ -30,7 +30,7 @@ std::string http_transact_asio(const std::string& hostname,
tcp.connect(hostname, "http");
if(!tcp)
- throw std::runtime_error("HTTP connection to " + hostname + " failed");
+ throw Exception("HTTP connection to " + hostname + " failed");
tcp << message;
tcp.flush();
@@ -45,7 +45,7 @@ std::string http_transact_asio(const std::string& hostname,
std::string http_transact_fail(const std::string& hostname,
const std::string&)
{
- throw std::runtime_error("Cannot connect to " + hostname +
+ throw Exception("Cannot connect to " + hostname +
": network code disabled in build");
}
@@ -89,7 +89,7 @@ Response http_sync(http_exch_fn http_transact,
{
const auto protocol_host_sep = url.find("://");
if(protocol_host_sep == std::string::npos)
- throw std::runtime_error("Invalid URL " + url);
+ throw Exception("Invalid URL " + url);
const std::string protocol = url.substr(0, protocol_host_sep);
const auto host_loc_sep = url.find('/', protocol_host_sep + 3);
@@ -130,7 +130,7 @@ Response http_sync(http_exch_fn http_transact,
std::string line1;
std::getline(io, line1);
if(!io || line1.empty())
- throw std::runtime_error("No response");
+ throw Exception("No response");
std::stringstream response_stream(line1);
std::string http_version;
@@ -142,7 +142,7 @@ Response http_sync(http_exch_fn http_transact,
std::getline(response_stream, status_message);
if(!response_stream || http_version.substr(0,5) != "HTTP/")
- throw std::runtime_error("Not an HTTP response");
+ throw Exception("Not an HTTP response");
std::map<std::string, std::string> headers;
std::string header_line;
@@ -150,7 +150,7 @@ Response http_sync(http_exch_fn http_transact,
{
auto sep = header_line.find(": ");
if(sep == std::string::npos || sep > header_line.size() - 2)
- throw std::runtime_error("Invalid HTTP header " + header_line);
+ throw Exception("Invalid HTTP header " + header_line);
const std::string key = header_line.substr(0, sep);
if(sep + 2 < header_line.size() - 1)
@@ -163,7 +163,7 @@ Response http_sync(http_exch_fn http_transact,
if(status_code == 301 && headers.count("Location"))
{
if(allowable_redirects == 0)
- throw std::runtime_error("HTTP redirection count exceeded");
+ throw Exception("HTTP redirection count exceeded");
return GET_sync(headers["Location"], allowable_redirects - 1);
}
@@ -180,7 +180,7 @@ Response http_sync(http_exch_fn http_transact,
if(header_size != "")
{
if(resp_body.size() != to_u32bit(header_size))
- throw std::runtime_error("Content-Length disagreement, header says " +
+ throw Exception("Content-Length disagreement, header says " +
header_size + " got " + std::to_string(resp_body.size()));
}
diff --git a/src/lib/utils/http_util/http_util.h b/src/lib/utils/http_util/http_util.h
index 2acb6c6e4..746b790f1 100644
--- a/src/lib/utils/http_util/http_util.h
+++ b/src/lib/utils/http_util/http_util.h
@@ -43,7 +43,7 @@ struct Response
void throw_unless_ok()
{
if(status_code() != 200)
- throw std::runtime_error("HTTP error: " + status_message());
+ throw Exception("HTTP error: " + status_message());
}
private:
diff --git a/src/lib/utils/parsing.cpp b/src/lib/utils/parsing.cpp
index 40eae656a..179e2e546 100644
--- a/src/lib/utils/parsing.cpp
+++ b/src/lib/utils/parsing.cpp
@@ -45,7 +45,7 @@ u32bit to_u32bit(const std::string& str)
auto message = std::string("Could not read '" + str + "' as decimal string");
auto exceptionMessage = std::string(e.what());
if (!exceptionMessage.empty()) message += ": " + exceptionMessage;
- throw std::runtime_error(message);
+ throw Exception(message);
}
}
diff --git a/src/lib/utils/read_cfg.cpp b/src/lib/utils/read_cfg.cpp
index 22e725328..0719ee681 100644
--- a/src/lib/utils/read_cfg.cpp
+++ b/src/lib/utils/read_cfg.cpp
@@ -49,7 +49,7 @@ std::map<std::string, std::string> read_cfg(std::istream& is)
auto eq = s.find("=");
if(eq == std::string::npos || eq == 0 || eq == s.size() - 1)
- throw std::runtime_error("Bad read_cfg input '" + s + "' on line " + std::to_string(line));
+ throw Exception("Bad read_cfg input '" + s + "' on line " + std::to_string(line));
const std::string key = clean_ws(s.substr(0, eq));
const std::string val = clean_ws(s.substr(eq + 1, std::string::npos));
diff --git a/src/lib/utils/sqlite3/sqlite3.cpp b/src/lib/utils/sqlite3/sqlite3.cpp
index 267d7530a..fde89b91d 100644
--- a/src/lib/utils/sqlite3/sqlite3.cpp
+++ b/src/lib/utils/sqlite3/sqlite3.cpp
@@ -20,7 +20,7 @@ Sqlite3_Database::Sqlite3_Database(const std::string& db_filename)
const std::string err_msg = ::sqlite3_errmsg(m_db);
::sqlite3_close(m_db);
m_db = nullptr;
- throw std::runtime_error("sqlite3_open failed - " + err_msg);
+ throw Exception("sqlite3_open failed - " + err_msg);
}
}
@@ -43,7 +43,7 @@ size_t Sqlite3_Database::row_count(const std::string& table_name)
if(stmt->step())
return stmt->get_size_t(0);
else
- throw std::runtime_error("Querying size of table " + table_name + " failed");
+ throw Exception("Querying size of table " + table_name + " failed");
}
void Sqlite3_Database::create_table(const std::string& table_schema)
@@ -57,7 +57,7 @@ void Sqlite3_Database::create_table(const std::string& table_schema)
::sqlite3_free(errmsg);
::sqlite3_close(m_db);
m_db = nullptr;
- throw std::runtime_error("sqlite3_exec for table failed - " + err_msg);
+ throw Exception("sqlite3_exec for table failed - " + err_msg);
}
}
@@ -66,7 +66,7 @@ Sqlite3_Database::Sqlite3_Statement::Sqlite3_Statement(sqlite3* db, const std::s
int rc = ::sqlite3_prepare_v2(db, base_sql.c_str(), -1, &m_stmt, nullptr);
if(rc != SQLITE_OK)
- throw std::runtime_error("sqlite3_prepare failed " + base_sql +
+ throw Exception("sqlite3_prepare failed " + base_sql +
", code " + std::to_string(rc));
}
@@ -74,16 +74,16 @@ void Sqlite3_Database::Sqlite3_Statement::bind(int column, const std::string& va
{
int rc = ::sqlite3_bind_text(m_stmt, column, val.c_str(), -1, SQLITE_TRANSIENT);
if(rc != SQLITE_OK)
- throw std::runtime_error("sqlite3_bind_text failed, code " + std::to_string(rc));
+ throw Exception("sqlite3_bind_text failed, code " + std::to_string(rc));
}
void Sqlite3_Database::Sqlite3_Statement::bind(int column, size_t val)
{
if(val != static_cast<size_t>(static_cast<int>(val))) // is this legit?
- throw std::runtime_error("sqlite3 cannot store " + std::to_string(val) + " without truncation");
+ throw Exception("sqlite3 cannot store " + std::to_string(val) + " without truncation");
int rc = ::sqlite3_bind_int(m_stmt, column, val);
if(rc != SQLITE_OK)
- throw std::runtime_error("sqlite3_bind_int failed, code " + std::to_string(rc));
+ throw Exception("sqlite3_bind_int failed, code " + std::to_string(rc));
}
void Sqlite3_Database::Sqlite3_Statement::bind(int column, std::chrono::system_clock::time_point time)
@@ -96,7 +96,7 @@ void Sqlite3_Database::Sqlite3_Statement::bind(int column, const std::vector<byt
{
int rc = ::sqlite3_bind_blob(m_stmt, column, val.data(), val.size(), SQLITE_TRANSIENT);
if(rc != SQLITE_OK)
- throw std::runtime_error("sqlite3_bind_text failed, code " + std::to_string(rc));
+ throw Exception("sqlite3_bind_text failed, code " + std::to_string(rc));
}
std::pair<const byte*, size_t> Sqlite3_Database::Sqlite3_Statement::get_blob(int column)
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