aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2015-12-11 09:42:06 -0500
committerJack Lloyd <[email protected]>2015-12-11 09:42:06 -0500
commit6b9a3a534071ef84c121c406559f8fc7ad546104 (patch)
treec11480ad1f07e443ba4e992fefcd618b532c2e93 /src/lib/pubkey
parent79a51627ee11f4d7f55d589751b30463d1f02a76 (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/pubkey')
-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
7 files changed, 13 insertions, 13 deletions
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));
}