aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-01-07 23:40:24 +0000
committerlloyd <[email protected]>2010-01-07 23:40:24 +0000
commit9900914a225c97aca575df268f73f7c6c366e697 (patch)
tree4f5525cc27e8473379f4965bb9b1dd7e1df109a3 /src
parent667738924ba1fde5bf219d963b433594d53d63b9 (diff)
parent2837e915d82e439730624f15bfc8c820475c9d65 (diff)
merge of 'bf0e5684d8ba5fb0a21cdcd11d26995cbb250c4a'
and 'e30a741f6014987e9683842ede22c44b2db03c56'
Diffstat (limited to 'src')
-rw-r--r--src/alloc/mem_pool/mem_pool.cpp13
-rw-r--r--src/alloc/system_alloc/defalloc.cpp2
-rw-r--r--src/block/lion/lion.cpp3
-rw-r--r--src/cert/x509/x509_ext.cpp2
-rw-r--r--src/cms/cms_dalg.cpp6
-rw-r--r--src/cms/cms_ealg.cpp12
-rw-r--r--src/constructs/cryptobox/cryptobox.cpp2
-rw-r--r--src/filters/bzip2/bzip2.cpp16
-rw-r--r--src/filters/modes/cbc/cbc.cpp2
-rw-r--r--src/filters/modes/cts/cts.cpp3
-rw-r--r--src/filters/modes/eax/eax_dec.cpp4
-rw-r--r--src/filters/modes/ecb/ecb.cpp2
-rw-r--r--src/filters/modes/xts/xts.cpp4
-rw-r--r--src/filters/pipe_rw.cpp2
-rw-r--r--src/filters/pk_filts/pk_filts.cpp2
-rw-r--r--src/filters/zlib/zlib.cpp15
-rw-r--r--src/math/gfpmath/point_gfp.cpp4
-rw-r--r--src/math/numbertheory/powm_mnt.cpp7
-rw-r--r--src/mutex/pthreads/mux_pthr.cpp6
-rw-r--r--src/pk_pad/eme1/eme1.cpp2
-rw-r--r--src/pubkey/dl_group/dl_group.cpp4
-rw-r--r--src/pubkey/dlies/dlies.cpp2
-rw-r--r--src/pubkey/dsa/dsa.cpp2
-rw-r--r--src/pubkey/pubkey.cpp6
-rw-r--r--src/s2k/pbkdf1/pbkdf1.cpp4
-rw-r--r--src/stream/stream_cipher.h4
-rw-r--r--src/utils/exceptn.h83
-rw-r--r--src/utils/parsing.cpp2
28 files changed, 80 insertions, 136 deletions
diff --git a/src/alloc/mem_pool/mem_pool.cpp b/src/alloc/mem_pool/mem_pool.cpp
index 2945a4cef..4180d2602 100644
--- a/src/alloc/mem_pool/mem_pool.cpp
+++ b/src/alloc/mem_pool/mem_pool.cpp
@@ -15,19 +15,6 @@
namespace Botan {
-namespace {
-
-/*
-* Memory Allocation Exception
-*/
-struct Memory_Exhaustion : public std::bad_alloc
- {
- const char* what() const throw()
- { return "Ran out of memory, allocation failed"; }
- };
-
-}
-
/*
* Memory_Block Constructor
*/
diff --git a/src/alloc/system_alloc/defalloc.cpp b/src/alloc/system_alloc/defalloc.cpp
index faaeb3c58..311057462 100644
--- a/src/alloc/system_alloc/defalloc.cpp
+++ b/src/alloc/system_alloc/defalloc.cpp
@@ -94,7 +94,7 @@ Allocator* Allocator::get(bool locking)
if(alloc)
return alloc;
- throw Exception("Couldn't find an allocator to use in get_allocator");
+ throw Internal_Error("Couldn't find an allocator to use in get_allocator");
}
}
diff --git a/src/block/lion/lion.cpp b/src/block/lion/lion.cpp
index e590a78ce..d8dfd1fcb 100644
--- a/src/block/lion/lion.cpp
+++ b/src/block/lion/lion.cpp
@@ -116,8 +116,9 @@ Lion::Lion(HashFunction* hash_in, StreamCipher* sc_in, u32bit block_len) :
{
if(2*LEFT_SIZE + 1 > BLOCK_SIZE)
throw Invalid_Argument(name() + ": Chosen block size is too small");
+
if(!cipher->valid_keylength(LEFT_SIZE))
- throw Exception(name() + ": This stream/hash combination is invalid");
+ throw Invalid_Argument(name() + ": This stream/hash combo is invalid");
key1.resize(LEFT_SIZE);
key2.resize(LEFT_SIZE);
diff --git a/src/cert/x509/x509_ext.cpp b/src/cert/x509/x509_ext.cpp
index 9a03c9d23..69b21d8b3 100644
--- a/src/cert/x509/x509_ext.cpp
+++ b/src/cert/x509/x509_ext.cpp
@@ -473,7 +473,7 @@ MemoryVector<byte> Certificate_Policies::encode_inner() const
{
// FIXME
#if 1
- throw Exception("Certificate_Policies::encode_inner: Bugged");
+ throw Internal_Error("Certificate_Policies::encode_inner: Bugged");
#else
std::vector<Policy_Information> policies;
diff --git a/src/cms/cms_dalg.cpp b/src/cms/cms_dalg.cpp
index 7ed793f4f..1fc4e2faa 100644
--- a/src/cms/cms_dalg.cpp
+++ b/src/cms/cms_dalg.cpp
@@ -195,7 +195,7 @@ void CMS_Decoder::decode_layer()
else if(type == OIDS::lookup("CMS.SignedData"))
{
#if 1
- throw Exception("FIXME: not implemented");
+ throw Internal_Error("FIXME: not implemented");
#else
u32bit version;
@@ -258,11 +258,11 @@ void CMS_Decoder::decode_layer()
}
else if(type == OIDS::lookup("CMS.EnvelopedData"))
{
- throw Exception("FIXME: not implemented");
+ throw Internal_Error("FIXME: not implemented");
}
else if(type == OIDS::lookup("CMS.AuthenticatedData"))
{
- throw Exception("FIXME: not implemented");
+ throw Internal_Error("FIXME: not implemented");
}
else
throw Decoding_Error("CMS: Unknown content ID " + type.as_string());
diff --git a/src/cms/cms_ealg.cpp b/src/cms/cms_ealg.cpp
index 2970e8e79..5efa33254 100644
--- a/src/cms/cms_ealg.cpp
+++ b/src/cms/cms_ealg.cpp
@@ -168,7 +168,7 @@ void CMS_Encoder::encrypt_kari(RandomNumberGenerator&,
X509_PublicKey*,
const std::string&)
{
- throw Exception("FIXME: unimplemented");
+ throw Internal_Error("FIXME: unimplemented");
#if 0
SymmetricKey cek = setup_key(rng, cipher);
@@ -198,7 +198,7 @@ void CMS_Encoder::encrypt(RandomNumberGenerator& rng,
const SymmetricKey& kek,
const std::string& user_cipher)
{
- throw Exception("FIXME: untested");
+ throw Internal_Error("FIXME: untested");
const std::string cipher = choose_algo(user_cipher, "TripleDES");
SymmetricKey cek = setup_key(rng, cipher);
@@ -232,7 +232,7 @@ void CMS_Encoder::encrypt(RandomNumberGenerator&,
const std::string& user_cipher)
{
const std::string cipher = choose_algo(user_cipher, "TripleDES");
- throw Exception("FIXME: unimplemented");
+ throw Internal_Error("FIXME: unimplemented");
/*
SymmetricKey cek = setup_key(key);
@@ -375,7 +375,7 @@ void CMS_Encoder::authenticate(const X509_Certificate&,
const std::string& mac_algo)
{
const std::string mac = choose_algo(mac_algo, "HMAC(SHA-1)");
- throw Exception("FIXME: unimplemented");
+ throw Internal_Error("FIXME: unimplemented");
}
/*
@@ -385,7 +385,7 @@ void CMS_Encoder::authenticate(const SymmetricKey&,
const std::string& mac_algo)
{
const std::string mac = choose_algo(mac_algo, "HMAC(SHA-1)");
- throw Exception("FIXME: unimplemented");
+ throw Internal_Error("FIXME: unimplemented");
}
/*
@@ -395,7 +395,7 @@ void CMS_Encoder::authenticate(const std::string&,
const std::string& mac_algo)
{
const std::string mac = choose_algo(mac_algo, "HMAC(SHA-1)");
- throw Exception("FIXME: unimplemented");
+ throw Internal_Error("FIXME: unimplemented");
}
}
diff --git a/src/constructs/cryptobox/cryptobox.cpp b/src/constructs/cryptobox/cryptobox.cpp
index ba7553c55..20435fa59 100644
--- a/src/constructs/cryptobox/cryptobox.cpp
+++ b/src/constructs/cryptobox/cryptobox.cpp
@@ -135,7 +135,7 @@ std::string decrypt(const byte input[], u32bit input_len,
if(!same_mem(computed_mac, ciphertext + VERSION_CODE_LEN + PBKDF_SALT_LEN,
MAC_OUTPUT_LEN))
- throw Integrity_Failure("CryptoBox integrity failure");
+ throw Decoding_Error("CryptoBox integrity failure");
return pipe.read_all_as_string(0);
}
diff --git a/src/filters/bzip2/bzip2.cpp b/src/filters/bzip2/bzip2.cpp
index 4cdca5355..9dcee8fdf 100644
--- a/src/filters/bzip2/bzip2.cpp
+++ b/src/filters/bzip2/bzip2.cpp
@@ -96,7 +96,7 @@ void Bzip_Compression::start_msg()
clear();
bz = new Bzip_Stream;
if(BZ2_bzCompressInit(&(bz->stream), level, 0, 0) != BZ_OK)
- throw Exception("Bzip_Compression: Memory allocation error");
+ throw Memory_Exhaustion();
}
/*
@@ -196,13 +196,15 @@ void Bzip_Decompression::write(const byte input_arr[], u32bit length)
if(rc != BZ_OK && rc != BZ_STREAM_END)
{
clear();
+
if(rc == BZ_DATA_ERROR)
throw Decoding_Error("Bzip_Decompression: Data integrity error");
- if(rc == BZ_DATA_ERROR_MAGIC)
+ else if(rc == BZ_DATA_ERROR_MAGIC)
throw Decoding_Error("Bzip_Decompression: Invalid input");
- if(rc == BZ_MEM_ERROR)
- throw Exception("Bzip_Decompression: Memory allocation error");
- throw Exception("Bzip_Decompression: Unknown decompress error");
+ else if(rc == BZ_MEM_ERROR)
+ throw Memory_Exhaustion();
+ else
+ throw std::runtime_error("Bzip2 decompression: Unknown error");
}
send(buffer, buffer.size() - bz->stream.avail_out);
@@ -228,7 +230,7 @@ void Bzip_Decompression::start_msg()
bz = new Bzip_Stream;
if(BZ2_bzDecompressInit(&(bz->stream), 0, small_mem) != BZ_OK)
- throw Exception("Bzip_Decompression: Memory allocation error");
+ throw Memory_Exhaustion();
no_writes = true;
}
@@ -252,7 +254,7 @@ void Bzip_Decompression::end_msg()
if(rc != BZ_OK && rc != BZ_STREAM_END)
{
clear();
- throw Exception("Bzip_Decompression: Error finalizing decompression");
+ throw Decoding_Error("Bzip_Decompression: Error finalizing");
}
send(buffer, buffer.size() - bz->stream.avail_out);
diff --git a/src/filters/modes/cbc/cbc.cpp b/src/filters/modes/cbc/cbc.cpp
index 059b239e8..7722fad2f 100644
--- a/src/filters/modes/cbc/cbc.cpp
+++ b/src/filters/modes/cbc/cbc.cpp
@@ -79,7 +79,7 @@ void CBC_Encryption::buffered_final(const byte input[], u32bit length)
if(length % cipher->BLOCK_SIZE == 0)
buffered_block(input, length);
else if(length != 0)
- throw Exception(name() + ": Did not pad to full blocksize");
+ throw Encoding_Error(name() + ": Did not pad to full blocksize");
}
void CBC_Encryption::write(const byte input[], u32bit input_length)
diff --git a/src/filters/modes/cts/cts.cpp b/src/filters/modes/cts/cts.cpp
index 3a15a1d68..b27b9b3c5 100644
--- a/src/filters/modes/cts/cts.cpp
+++ b/src/filters/modes/cts/cts.cpp
@@ -101,7 +101,8 @@ void CTS_Encryption::write(const byte input[], u32bit length)
void CTS_Encryption::end_msg()
{
if(position < cipher->BLOCK_SIZE + 1)
- throw Exception("CTS_Encryption: insufficient data to encrypt");
+ throw Encoding_Error(name() + ": insufficient data to encrypt");
+
xor_buf(state, buffer, cipher->BLOCK_SIZE);
cipher->encrypt(state);
SecureVector<byte> cn = state;
diff --git a/src/filters/modes/eax/eax_dec.cpp b/src/filters/modes/eax/eax_dec.cpp
index f41327ffc..998773697 100644
--- a/src/filters/modes/eax/eax_dec.cpp
+++ b/src/filters/modes/eax/eax_dec.cpp
@@ -98,13 +98,13 @@ void EAX_Decryption::do_write(const byte input[], u32bit length)
void EAX_Decryption::end_msg()
{
if((queue_end - queue_start) != TAG_SIZE)
- throw Integrity_Failure(name() + ": Message authentication failure");
+ throw Decoding_Error(name() + ": Message authentication failure");
SecureVector<byte> data_mac = cmac->final();
for(u32bit j = 0; j != TAG_SIZE; ++j)
if(queue[queue_start+j] != (data_mac[j] ^ nonce_mac[j] ^ header_mac[j]))
- throw Integrity_Failure(name() + ": Message authentication failure");
+ throw Decoding_Error(name() + ": Message authentication failure");
queue_start = queue_end = 0;
}
diff --git a/src/filters/modes/ecb/ecb.cpp b/src/filters/modes/ecb/ecb.cpp
index c13d0fd37..2ce6576e3 100644
--- a/src/filters/modes/ecb/ecb.cpp
+++ b/src/filters/modes/ecb/ecb.cpp
@@ -103,7 +103,7 @@ void ECB_Encryption::buffered_final(const byte input[], u32bit input_length)
if(input_length % cipher->BLOCK_SIZE == 0)
buffered_block(input, input_length);
else if(input_length != 0)
- throw Exception(name() + ": Did not pad to full blocksize");
+ throw Encoding_Error(name() + ": Did not pad to full blocksize");
}
/*
diff --git a/src/filters/modes/xts/xts.cpp b/src/filters/modes/xts/xts.cpp
index afeea24b5..cfea0b34b 100644
--- a/src/filters/modes/xts/xts.cpp
+++ b/src/filters/modes/xts/xts.cpp
@@ -168,7 +168,7 @@ void XTS_Encryption::buffered_block(const byte input[], u32bit length)
void XTS_Encryption::buffered_final(const byte input[], u32bit length)
{
if(length <= cipher->BLOCK_SIZE)
- throw Exception("XTS_Encryption: insufficient data to encrypt");
+ throw Encoding_Error("XTS_Encryption: insufficient data to encrypt");
if(length % cipher->BLOCK_SIZE == 0)
{
@@ -323,7 +323,7 @@ void XTS_Decryption::buffered_block(const byte input[], u32bit input_length)
void XTS_Decryption::buffered_final(const byte input[], u32bit input_length)
{
if(input_length <= cipher->BLOCK_SIZE)
- throw Exception("XTS_Decryption: insufficient data to decrypt");
+ throw Decoding_Error("XTS_Decryption: insufficient data to decrypt");
if(input_length % cipher->BLOCK_SIZE == 0)
{
diff --git a/src/filters/pipe_rw.cpp b/src/filters/pipe_rw.cpp
index 756a1cf09..de77c6b43 100644
--- a/src/filters/pipe_rw.cpp
+++ b/src/filters/pipe_rw.cpp
@@ -34,7 +34,7 @@ Pipe::message_id Pipe::get_message_no(const std::string& func_name,
void Pipe::write(const byte input[], u32bit length)
{
if(!inside_msg)
- throw Exception("Cannot write to a Pipe while it is not processing");
+ throw Invalid_State("Cannot write to a Pipe while it is not processing");
pipe->write(input, length);
}
diff --git a/src/filters/pk_filts/pk_filts.cpp b/src/filters/pk_filts/pk_filts.cpp
index d604436e0..05b45227f 100644
--- a/src/filters/pk_filts/pk_filts.cpp
+++ b/src/filters/pk_filts/pk_filts.cpp
@@ -73,7 +73,7 @@ void PK_Verifier_Filter::write(const byte input[], u32bit length)
void PK_Verifier_Filter::end_msg()
{
if(signature.empty())
- throw Exception("PK_Verifier_Filter: No signature to check against");
+ throw Invalid_State("PK_Verifier_Filter: No signature to check against");
bool is_valid = verifier->check_signature(signature, signature.size());
send((is_valid ? 1 : 0));
}
diff --git a/src/filters/zlib/zlib.cpp b/src/filters/zlib/zlib.cpp
index 246e32924..171caa73f 100644
--- a/src/filters/zlib/zlib.cpp
+++ b/src/filters/zlib/zlib.cpp
@@ -95,7 +95,7 @@ void Zlib_Compression::start_msg()
clear();
zlib = new Zlib_Stream;
if(deflateInit(&(zlib->stream), level) != Z_OK)
- throw Exception("Zlib_Compression: Memory allocation error");
+ throw Memory_Exhaustion();
}
/*
@@ -187,7 +187,7 @@ void Zlib_Decompression::start_msg()
clear();
zlib = new Zlib_Stream;
if(inflateInit(&(zlib->stream)) != Z_OK)
- throw Exception("Zlib_Decompression: Memory allocation error");
+ throw Memory_Exhaustion();
}
/*
@@ -215,11 +215,12 @@ void Zlib_Decompression::write(const byte input_arr[], u32bit length)
clear();
if(rc == Z_DATA_ERROR)
throw Decoding_Error("Zlib_Decompression: Data integrity error");
- if(rc == Z_NEED_DICT)
+ else if(rc == Z_NEED_DICT)
throw Decoding_Error("Zlib_Decompression: Need preset dictionary");
- if(rc == Z_MEM_ERROR)
- throw Exception("Zlib_Decompression: Memory allocation error");
- throw Exception("Zlib_Decompression: Unknown decompress error");
+ else if(rc == Z_MEM_ERROR)
+ throw Memory_Exhaustion();
+ else
+ throw std::runtime_error("Zlib decompression: Unknown error");
}
send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
@@ -258,7 +259,7 @@ void Zlib_Decompression::end_msg()
if(rc != Z_OK && rc != Z_STREAM_END)
{
clear();
- throw Exception("Zlib_Decompression: Error finalizing decompression");
+ throw Decoding_Error("Zlib_Decompression: Error finalizing");
}
send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
diff --git a/src/math/gfpmath/point_gfp.cpp b/src/math/gfpmath/point_gfp.cpp
index f95add9f7..4203a3db3 100644
--- a/src/math/gfpmath/point_gfp.cpp
+++ b/src/math/gfpmath/point_gfp.cpp
@@ -921,7 +921,7 @@ SecureVector<byte> EC2OSP(const PointGFp& point, byte format)
}
else
{
- throw Format_Error("illegal point encoding format specification");
+ throw Invalid_Argument("illegal point encoding format specification");
}
return result;
}
@@ -1078,7 +1078,7 @@ PointGFp OS2ECP(MemoryRegion<byte> const& os, const CurveGFp& curve)
}
break;
default:
- throw Format_Error("encountered illegal format specification while decoding point");
+ throw Invalid_Argument("encountered illegal format specification while decoding point");
}
z = GFpElement(curve.get_p(), BigInt(1));
//assert((x.is_trf_to_mres() && x.is_use_montgm()) || !x.is_trf_to_mres());
diff --git a/src/math/numbertheory/powm_mnt.cpp b/src/math/numbertheory/powm_mnt.cpp
index e356387c0..2d18ccdef 100644
--- a/src/math/numbertheory/powm_mnt.cpp
+++ b/src/math/numbertheory/powm_mnt.cpp
@@ -156,10 +156,9 @@ BigInt Montgomery_Exponentiator::execute() const
Montgomery_Exponentiator::Montgomery_Exponentiator(const BigInt& mod,
Power_Mod::Usage_Hints hints)
{
- if(!mod.is_positive())
- throw Exception("Montgomery_Exponentiator: modulus must be positive");
- if(mod.is_even())
- throw Exception("Montgomery_Exponentiator: modulus must be odd");
+ // Montgomery reduction only works for positive odd moduli
+ if(!mod.is_positive() || mod.is_even())
+ throw Invalid_Argument("Montgomery_Exponentiator: invalid modulus");
window_bits = 0;
this->hints = hints;
diff --git a/src/mutex/pthreads/mux_pthr.cpp b/src/mutex/pthreads/mux_pthr.cpp
index 75a116fe8..165132239 100644
--- a/src/mutex/pthreads/mux_pthr.cpp
+++ b/src/mutex/pthreads/mux_pthr.cpp
@@ -28,19 +28,19 @@ Mutex* Pthread_Mutex_Factory::make()
void lock()
{
if(pthread_mutex_lock(&mutex) != 0)
- throw Exception("Pthread_Mutex::lock: Error occured");
+ throw Invalid_State("Pthread_Mutex::lock: Error occured");
}
void unlock()
{
if(pthread_mutex_unlock(&mutex) != 0)
- throw Exception("Pthread_Mutex::unlock: Error occured");
+ throw Invalid_State("Pthread_Mutex::unlock: Error occured");
}
Pthread_Mutex()
{
if(pthread_mutex_init(&mutex, 0) != 0)
- throw Exception("Pthread_Mutex: initialization failed");
+ throw Invalid_State("Pthread_Mutex: initialization failed");
}
~Pthread_Mutex()
diff --git a/src/pk_pad/eme1/eme1.cpp b/src/pk_pad/eme1/eme1.cpp
index 13f68f8e4..d99ffaf58 100644
--- a/src/pk_pad/eme1/eme1.cpp
+++ b/src/pk_pad/eme1/eme1.cpp
@@ -21,7 +21,7 @@ SecureVector<byte> EME1::pad(const byte in[], u32bit in_length,
key_length /= 8;
if(in_length > key_length - 2*HASH_LENGTH - 1)
- throw Exception("EME1: Input is too large");
+ throw Invalid_Argument("EME1: Input is too large");
SecureVector<byte> out(key_length);
diff --git a/src/pubkey/dl_group/dl_group.cpp b/src/pubkey/dl_group/dl_group.cpp
index a2e239783..7940e69b2 100644
--- a/src/pubkey/dl_group/dl_group.cpp
+++ b/src/pubkey/dl_group/dl_group.cpp
@@ -193,7 +193,7 @@ const BigInt& DL_Group::get_q() const
{
init_check();
if(q == 0)
- throw Format_Error("DLP group has no q prime specified");
+ throw Invalid_State("DLP group has no q prime specified");
return q;
}
@@ -325,7 +325,7 @@ BigInt DL_Group::make_dsa_generator(const BigInt& p, const BigInt& q)
}
if(g == 1)
- throw Exception("DL_Group: Couldn't create a suitable generator");
+ throw Internal_Error("DL_Group: Couldn't create a suitable generator");
return g;
}
diff --git a/src/pubkey/dlies/dlies.cpp b/src/pubkey/dlies/dlies.cpp
index 3a3ab52ee..6ef3292e1 100644
--- a/src/pubkey/dlies/dlies.cpp
+++ b/src/pubkey/dlies/dlies.cpp
@@ -127,7 +127,7 @@ SecureVector<byte> DLIES_Decryptor::dec(const byte msg[], u32bit length) const
mac->update(0);
SecureVector<byte> T2 = mac->final();
if(T != T2)
- throw Integrity_Failure("DLIES: message authentication failed");
+ throw Decoding_Error("DLIES: message authentication failed");
xor_buf(C, K.begin() + mac_keylen, C.size());
diff --git a/src/pubkey/dsa/dsa.cpp b/src/pubkey/dsa/dsa.cpp
index b0688ae0d..5be3e1d48 100644
--- a/src/pubkey/dsa/dsa.cpp
+++ b/src/pubkey/dsa/dsa.cpp
@@ -97,6 +97,8 @@ SecureVector<byte> DSA_PrivateKey::sign(const byte in[], u32bit length,
{
const BigInt& q = group_q();
+ rng.add_entropy(in, length);
+
BigInt k;
do
k.randomize(rng, q.bits());
diff --git a/src/pubkey/pubkey.cpp b/src/pubkey/pubkey.cpp
index 44e31159c..9b5c9180b 100644
--- a/src/pubkey/pubkey.cpp
+++ b/src/pubkey/pubkey.cpp
@@ -73,7 +73,7 @@ PK_Encryptor_MR_with_EME::enc(const byte msg[],
message.set(msg, length);
if(8*(message.size() - 1) + high_bit(message[0]) > key.max_input_bits())
- throw Exception("PK_Encryptor_MR_with_EME: Input is too large");
+ throw Invalid_Argument("PK_Encryptor_MR_with_EME: Input is too large");
return key.encrypt(message, message.size(), rng);
}
@@ -113,11 +113,11 @@ SecureVector<byte> PK_Decryptor_MR_with_EME::dec(const byte msg[],
}
catch(Invalid_Argument)
{
- throw Exception("PK_Decryptor_MR_with_EME: Input is invalid");
+ throw Decoding_Error("PK_Decryptor_MR_with_EME: Input is invalid");
}
catch(Decoding_Error)
{
- throw Exception("PK_Decryptor_MR_with_EME: Input is invalid");
+ throw Decoding_Error("PK_Decryptor_MR_with_EME: Input is invalid");
}
}
diff --git a/src/s2k/pbkdf1/pbkdf1.cpp b/src/s2k/pbkdf1/pbkdf1.cpp
index 04e3aa453..fcc5b9a97 100644
--- a/src/s2k/pbkdf1/pbkdf1.cpp
+++ b/src/s2k/pbkdf1/pbkdf1.cpp
@@ -18,10 +18,10 @@ OctetString PKCS5_PBKDF1::derive(u32bit key_len,
u32bit iterations) const
{
if(iterations == 0)
- throw Invalid_Argument("PKCS#5 PBKDF1: Invalid iteration count");
+ throw Invalid_Argument("PKCS5_PBKDF1: Invalid iteration count");
if(key_len > hash->OUTPUT_LENGTH)
- throw Exception("PKCS#5 PBKDF1: Requested output length too long");
+ throw Invalid_Argument("PKCS5_PBKDF1: Requested output length too long");
hash->update(passphrase);
hash->update(salt, salt_size);
diff --git a/src/stream/stream_cipher.h b/src/stream/stream_cipher.h
index 29c16c8b5..cb6fb3481 100644
--- a/src/stream/stream_cipher.h
+++ b/src/stream/stream_cipher.h
@@ -42,8 +42,8 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm
virtual void set_iv(const byte[], u32bit iv_len)
{
if(iv_len)
- throw Exception("The stream cipher " + name() +
- " does not support resyncronization");
+ throw Invalid_Argument("The stream cipher " + name() +
+ " does not support resyncronization");
}
/**
diff --git a/src/utils/exceptn.h b/src/utils/exceptn.h
index d106de1c0..86efebc7c 100644
--- a/src/utils/exceptn.h
+++ b/src/utils/exceptn.h
@@ -1,6 +1,6 @@
/*
* Exceptions
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2009 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -16,32 +16,8 @@
namespace Botan {
-/*
-* Exception Base Class
-*/
-class BOTAN_DLL Exception : public std::exception
- {
- public:
- Exception(const std::string& m = "Unknown error") :
- msg("Botan: " + m)
- {}
-
- const char* what() const throw() { return msg.c_str(); }
-
- virtual ~Exception() throw() {}
- private:
- std::string msg;
- };
-
-/*
-* Invalid_Argument Exception
-*/
-struct BOTAN_DLL Invalid_Argument : public Exception
- {
- Invalid_Argument(const std::string& err = "") :
- Exception(err)
- {}
- };
+typedef std::runtime_error Exception;
+typedef std::invalid_argument Invalid_Argument;
/*
* Invalid_State Exception
@@ -54,16 +30,6 @@ struct BOTAN_DLL Invalid_State : public Exception
};
/*
-* Format_Error Exception
-*/
-struct BOTAN_DLL Format_Error : public Exception
- {
- Format_Error(const std::string& err = "") :
- Exception(err)
- {}
- };
-
-/*
* Lookup_Error Exception
*/
struct BOTAN_DLL Lookup_Error : public Exception
@@ -150,29 +116,29 @@ struct BOTAN_DLL Algorithm_Not_Found : public Lookup_Error
/*
* Invalid_Algorithm_Name Exception
*/
-struct BOTAN_DLL Invalid_Algorithm_Name : public Format_Error
+struct BOTAN_DLL Invalid_Algorithm_Name : public Invalid_Argument
{
Invalid_Algorithm_Name(const std::string& name):
- Format_Error("Invalid algorithm name: " + name)
+ Invalid_Argument("Invalid algorithm name: " + name)
{}
};
/*
* Encoding_Error Exception
*/
-struct BOTAN_DLL Encoding_Error : public Format_Error
+struct BOTAN_DLL Encoding_Error : public Invalid_Argument
{
Encoding_Error(const std::string& name) :
- Format_Error("Encoding error: " + name) {}
+ Invalid_Argument("Encoding error: " + name) {}
};
/*
* Decoding_Error Exception
*/
-struct BOTAN_DLL Decoding_Error : public Format_Error
+struct BOTAN_DLL Decoding_Error : public Invalid_Argument
{
Decoding_Error(const std::string& name) :
- Format_Error("Decoding error: " + name) {}
+ Invalid_Argument("Decoding error: " + name) {}
};
/*
@@ -195,37 +161,22 @@ struct BOTAN_DLL Stream_IO_Error : public Exception
};
/*
-* Configuration Error Exception
-*/
-struct BOTAN_DLL Config_Error : public Format_Error
- {
- Config_Error(const std::string& err) :
- Format_Error("Config error: " + err)
- {}
-
- Config_Error(const std::string& err, u32bit line) :
- Format_Error("Config error at line " + to_string(line) + ": " + err)
- {}
- };
-
-/*
-* Integrity Failure Exception
+* Self Test Failure Exception
*/
-struct BOTAN_DLL Integrity_Failure : public Internal_Error
+struct BOTAN_DLL Self_Test_Failure : public Internal_Error
{
- Integrity_Failure(const std::string& err) :
- Internal_Error("Integrity failure: " + err)
+ Self_Test_Failure(const std::string& err) :
+ Internal_Error("Self test failed: " + err)
{}
};
/*
-* Self Test Failure Exception
+* Memory Allocation Exception
*/
-struct BOTAN_DLL Self_Test_Failure : public Internal_Error
+struct BOTAN_DLL Memory_Exhaustion : public std::bad_alloc
{
- Self_Test_Failure(const std::string& err) :
- Internal_Error("Self test failed: " + err)
- {}
+ const char* what() const throw()
+ { return "Ran out of memory, allocation failed"; }
};
}
diff --git a/src/utils/parsing.cpp b/src/utils/parsing.cpp
index 58a8e0b38..4b99ac1ec 100644
--- a/src/utils/parsing.cpp
+++ b/src/utils/parsing.cpp
@@ -168,7 +168,7 @@ std::vector<std::string> split_on(const std::string& str, char delim)
}
if(substr == "")
- throw Format_Error("Unable to split string: " + str);
+ throw Invalid_Argument("Unable to split string: " + str);
elems.push_back(substr);
return elems;