diff options
author | Jack Lloyd <[email protected]> | 2015-12-11 09:42:06 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2015-12-11 09:42:06 -0500 |
commit | 6b9a3a534071ef84c121c406559f8fc7ad546104 (patch) | |
tree | c11480ad1f07e443ba4e992fefcd618b532c2e93 /src/lib/tls | |
parent | 79a51627ee11f4d7f55d589751b30463d1f02a76 (diff) |
Reroot the exception hierarchy into a toplevel Exception class
As the alternatives are unfortunate for applications trying to catch
all library errors, and it seems deriving from std::runtime_error
causes problems with MSVC DLLs (GH #340)
Effectively reverts 2837e915d82e43
Diffstat (limited to 'src/lib/tls')
-rw-r--r-- | src/lib/tls/credentials_manager.cpp | 6 | ||||
-rw-r--r-- | src/lib/tls/msg_client_hello.cpp | 2 | ||||
-rw-r--r-- | src/lib/tls/sessions_sql/tls_session_manager_sql.cpp | 4 | ||||
-rw-r--r-- | src/lib/tls/tls_channel.cpp | 10 | ||||
-rw-r--r-- | src/lib/tls/tls_ciphersuite.cpp | 2 | ||||
-rw-r--r-- | src/lib/tls/tls_extensions.cpp | 2 | ||||
-rw-r--r-- | src/lib/tls/tls_heartbeats.cpp | 4 | ||||
-rw-r--r-- | src/lib/tls/tls_policy.h | 2 | ||||
-rw-r--r-- | src/lib/tls/tls_reader.h | 4 | ||||
-rw-r--r-- | src/lib/tls/tls_seq_numbers.h | 2 |
10 files changed, 19 insertions, 19 deletions
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 |