Botan  1.11.15
src/lib/utils/exceptn.h
Go to the documentation of this file.
00001 /*
00002 * Exceptions
00003 * (C) 1999-2009 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_EXCEPTION_H__
00009 #define BOTAN_EXCEPTION_H__
00010 
00011 #include <botan/types.h>
00012 #include <botan/parsing.h>
00013 #include <exception>
00014 #include <stdexcept>
00015 #include <string>
00016 
00017 namespace Botan {
00018 
00019 typedef std::runtime_error Exception;
00020 typedef std::invalid_argument Invalid_Argument;
00021 
00022 /**
00023 * Invalid_State Exception
00024 */
00025 struct BOTAN_DLL Invalid_State : public Exception
00026    {
00027    Invalid_State(const std::string& err) :
00028       Exception(err)
00029       {}
00030    };
00031 
00032 /**
00033 * Lookup_Error Exception
00034 */
00035 struct BOTAN_DLL Lookup_Error : public Exception
00036    {
00037    Lookup_Error(const std::string& err) :
00038       Exception(err)
00039       {}
00040    };
00041 
00042 /**
00043 * Internal_Error Exception
00044 */
00045 struct BOTAN_DLL Internal_Error : public Exception
00046    {
00047    Internal_Error(const std::string& err) :
00048       Exception("Internal error: " + err)
00049       {}
00050    };
00051 
00052 /**
00053 * Invalid_Key_Length Exception
00054 */
00055 struct BOTAN_DLL Invalid_Key_Length : public Invalid_Argument
00056    {
00057    Invalid_Key_Length(const std::string& name, size_t length) :
00058       Invalid_Argument(name + " cannot accept a key of length " +
00059                        std::to_string(length))
00060       {}
00061    };
00062 
00063 /**
00064 * Invalid_IV_Length Exception
00065 */
00066 struct BOTAN_DLL Invalid_IV_Length : public Invalid_Argument
00067    {
00068    Invalid_IV_Length(const std::string& mode, size_t bad_len) :
00069       Invalid_Argument("IV length " + std::to_string(bad_len) +
00070                        " is invalid for " + mode)
00071       {}
00072    };
00073 
00074 /**
00075 * PRNG_Unseeded Exception
00076 */
00077 struct BOTAN_DLL PRNG_Unseeded : public Invalid_State
00078    {
00079    PRNG_Unseeded(const std::string& algo) :
00080       Invalid_State("PRNG not seeded: " + algo)
00081       {}
00082    };
00083 
00084 /**
00085 * Policy_Violation Exception
00086 */
00087 struct BOTAN_DLL Policy_Violation : public Invalid_State
00088    {
00089    Policy_Violation(const std::string& err) :
00090       Invalid_State("Policy violation: " + err)
00091       {}
00092    };
00093 
00094 /**
00095 * Algorithm_Not_Found Exception
00096 */
00097 struct BOTAN_DLL Algorithm_Not_Found : public Lookup_Error
00098    {
00099    Algorithm_Not_Found(const std::string& name) :
00100       Lookup_Error("Could not find any algorithm named \"" + name + "\"")
00101       {}
00102    };
00103 
00104 /**
00105 * Invalid_Algorithm_Name Exception
00106 */
00107 struct BOTAN_DLL Invalid_Algorithm_Name : public Invalid_Argument
00108    {
00109    Invalid_Algorithm_Name(const std::string& name):
00110       Invalid_Argument("Invalid algorithm name: " + name)
00111       {}
00112    };
00113 
00114 /**
00115 * Encoding_Error Exception
00116 */
00117 struct BOTAN_DLL Encoding_Error : public Invalid_Argument
00118    {
00119    Encoding_Error(const std::string& name) :
00120       Invalid_Argument("Encoding error: " + name) {}
00121    };
00122 
00123 /**
00124 * Decoding_Error Exception
00125 */
00126 struct BOTAN_DLL Decoding_Error : public Invalid_Argument
00127    {
00128    Decoding_Error(const std::string& name) :
00129       Invalid_Argument("Decoding error: " + name) {}
00130    };
00131 
00132 /**
00133 * Integrity_Failure Exception
00134 */
00135 struct BOTAN_DLL Integrity_Failure : public Exception
00136    {
00137    Integrity_Failure(const std::string& msg) :
00138       Exception("Integrity failure: " + msg) {}
00139    };
00140 
00141 /**
00142 * Invalid_OID Exception
00143 */
00144 struct BOTAN_DLL Invalid_OID : public Decoding_Error
00145    {
00146    Invalid_OID(const std::string& oid) :
00147       Decoding_Error("Invalid ASN.1 OID: " + oid) {}
00148    };
00149 
00150 /**
00151 * Stream_IO_Error Exception
00152 */
00153 struct BOTAN_DLL Stream_IO_Error : public Exception
00154    {
00155    Stream_IO_Error(const std::string& err) :
00156       Exception("I/O error: " + err)
00157       {}
00158    };
00159 
00160 /**
00161 * Self Test Failure Exception
00162 */
00163 struct BOTAN_DLL Self_Test_Failure : public Internal_Error
00164    {
00165    Self_Test_Failure(const std::string& err) :
00166       Internal_Error("Self test failed: " + err)
00167       {}
00168    };
00169 
00170 /**
00171 * Memory Allocation Exception
00172 */
00173 struct BOTAN_DLL Memory_Exhaustion : public std::bad_alloc
00174    {
00175    const char* what() const noexcept
00176       { return "Ran out of memory, allocation failed"; }
00177    };
00178 
00179 }
00180 
00181 #endif