aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/misc
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-11-17 16:23:51 -0500
committerJack Lloyd <[email protected]>2018-11-23 11:15:25 -0500
commitb909778857b3e0b7eb86ac26c818e5f25baaddbd (patch)
treef8a5c9cbec26310bbfc9077563892b04db158a48 /src/lib/misc
parentc20a428ca2f7c1ef96e642f55bb898010444c499 (diff)
Make exceptions easier to translate to error codes
Avoid throwing base Botan::Exception type, as it is difficult to determine what the error is in that case. Add Exception::error_code and Exception::error_type which allows (for error code) more information about the error and (for error type) allows knowing the error type without requiring a sequence of catches. See GH #1742
Diffstat (limited to 'src/lib/misc')
-rw-r--r--src/lib/misc/fpe_fe1/fpe_fe1.cpp4
-rw-r--r--src/lib/misc/srp6/srp6.cpp10
2 files changed, 7 insertions, 7 deletions
diff --git a/src/lib/misc/fpe_fe1/fpe_fe1.cpp b/src/lib/misc/fpe_fe1/fpe_fe1.cpp
index 680967ea9..3bd01ce34 100644
--- a/src/lib/misc/fpe_fe1/fpe_fe1.cpp
+++ b/src/lib/misc/fpe_fe1/fpe_fe1.cpp
@@ -50,7 +50,7 @@ void factor(BigInt n, BigInt& a, BigInt& b)
a *= n;
if(a <= 1 || b <= 1)
- throw Exception("Could not factor n for use in FPE");
+ throw Internal_Error("Could not factor n for use in FPE");
}
}
@@ -69,7 +69,7 @@ FPE_FE1::FPE_FE1(const BigInt& n,
m_n_bytes = BigInt::encode(n);
if(m_n_bytes.size() > MAX_N_BYTES)
- throw Exception("N is too large for FPE encryption");
+ throw Invalid_Argument("N is too large for FPE encryption");
factor(n, m_a, m_b);
diff --git a/src/lib/misc/srp6/srp6.cpp b/src/lib/misc/srp6/srp6.cpp
index cb7e3c600..0ec4fd2bb 100644
--- a/src/lib/misc/srp6/srp6.cpp
+++ b/src/lib/misc/srp6/srp6.cpp
@@ -64,13 +64,13 @@ std::string srp6_group_identifier(const BigInt& N, const BigInt& g)
if(group.get_p() == N && group.get_g() == g)
return group_name;
-
- throw Exception("Unknown SRP params");
}
catch(...)
{
- throw Invalid_Argument("Bad SRP group parameters");
}
+
+ // If we didn't return, the group was unknown or did not match
+ throw Invalid_Argument("Invalid or unknown SRP group parameters");
}
std::pair<BigInt, SymmetricKey>
@@ -91,7 +91,7 @@ srp6_client_agree(const std::string& identifier,
const size_t p_bytes = group.p_bytes();
if(B <= 0 || B >= p)
- throw Exception("Invalid SRP parameter from server");
+ throw Decoding_Error("Invalid SRP parameter from server");
const 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 Exception("Invalid SRP parameter from client");
+ throw Decoding_Error("Invalid SRP parameter from client");
const BigInt u = hash_seq(m_hash_id, m_p_bytes, A, m_B);