aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ffi/ffi.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/ffi/ffi.cpp')
-rw-r--r--src/lib/ffi/ffi.cpp88
1 files changed, 70 insertions, 18 deletions
diff --git a/src/lib/ffi/ffi.cpp b/src/lib/ffi/ffi.cpp
index 74291199b..cfc2cb2d5 100644
--- a/src/lib/ffi/ffi.cpp
+++ b/src/lib/ffi/ffi.cpp
@@ -25,6 +25,59 @@ int ffi_error_exception_thrown(const char* func_name, const char* exn, int rc)
return rc;
}
+namespace {
+
+int ffi_map_error_type(Botan::ErrorType err)
+ {
+ switch(err)
+ {
+ case Botan::ErrorType::Unknown:
+ return BOTAN_FFI_ERROR_UNKNOWN_ERROR;
+ case Botan::ErrorType::SystemError:
+ case Botan::ErrorType::IoError:
+ case Botan::ErrorType::OpenSSLError:
+ case Botan::ErrorType::Pkcs11Error:
+ case Botan::ErrorType::CommonCryptoError:
+ case Botan::ErrorType::TPMError:
+ case Botan::ErrorType::ZlibError:
+ case Botan::ErrorType::Bzip2Error:
+ case Botan::ErrorType::LzmaError:
+ return BOTAN_FFI_ERROR_SYSTEM_ERROR;
+
+ case Botan::ErrorType::NotImplemented:
+ return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
+ case Botan::ErrorType::OutOfMemory:
+ return BOTAN_FFI_ERROR_OUT_OF_MEMORY;
+ case Botan::ErrorType::InternalError:
+ return BOTAN_FFI_ERROR_INTERNAL_ERROR;
+ case Botan::ErrorType::InvalidObjectState:
+ return BOTAN_FFI_ERROR_INVALID_OBJECT_STATE;
+ case Botan::ErrorType::KeyNotSet:
+ return BOTAN_FFI_ERROR_KEY_NOT_SET;
+ case Botan::ErrorType::InvalidArgument:
+ case Botan::ErrorType::InvalidNonceLength:
+ return BOTAN_FFI_ERROR_BAD_PARAMETER;
+
+ case Botan::ErrorType::EncodingFailure:
+ case Botan::ErrorType::DecodingFailure:
+ return BOTAN_FFI_ERROR_INVALID_INPUT;
+
+ case Botan::ErrorType::InvalidKeyLength:
+ return BOTAN_FFI_ERROR_INVALID_KEY_LENGTH;
+ case Botan::ErrorType::LookupError:
+ return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
+
+ case Botan::ErrorType::HttpError:
+ return BOTAN_FFI_ERROR_HTTP_ERROR;
+ case Botan::ErrorType::TLSError:
+ return BOTAN_FFI_ERROR_TLS_ERROR;
+ }
+
+ return BOTAN_FFI_ERROR_UNKNOWN_ERROR;
+ }
+
+}
+
int ffi_guard_thunk(const char* func_name, std::function<int ()> thunk)
{
try
@@ -39,25 +92,9 @@ int ffi_guard_thunk(const char* func_name, std::function<int ()> thunk)
{
return ffi_error_exception_thrown(func_name, e.what(), e.error_code());
}
- catch(Botan::Lookup_Error& e)
- {
- return ffi_error_exception_thrown(func_name, e.what(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED);
- }
- catch(Botan::Invalid_Key_Length& e)
- {
- return ffi_error_exception_thrown(func_name, e.what(), BOTAN_FFI_ERROR_INVALID_KEY_LENGTH);
- }
- catch(Botan::Key_Not_Set& e)
- {
- return ffi_error_exception_thrown(func_name, e.what(), BOTAN_FFI_ERROR_KEY_NOT_SET);
- }
- catch(Botan::Invalid_Argument& e)
- {
- return ffi_error_exception_thrown(func_name, e.what(), BOTAN_FFI_ERROR_BAD_PARAMETER);
- }
- catch(Botan::Not_Implemented& e)
+ catch(Botan::Exception& e)
{
- return ffi_error_exception_thrown(func_name, e.what(), BOTAN_FFI_ERROR_NOT_IMPLEMENTED);
+ return ffi_error_exception_thrown(func_name, e.what(), ffi_map_error_type(e.error_type()));
}
catch(std::exception& e)
{
@@ -102,6 +139,12 @@ const char* botan_error_description(int err)
case BOTAN_FFI_ERROR_OUT_OF_MEMORY:
return "Out of memory";
+ case BOTAN_FFI_ERROR_SYSTEM_ERROR:
+ return "Error while calling system API";
+
+ case BOTAN_FFI_ERROR_INTERNAL_ERROR:
+ return "Internal error";
+
case BOTAN_FFI_ERROR_BAD_FLAG:
return "Bad flag";
@@ -117,12 +160,21 @@ const char* botan_error_description(int err)
case BOTAN_FFI_ERROR_INVALID_KEY_LENGTH:
return "Invalid key length";
+ case BOTAN_FFI_ERROR_INVALID_OBJECT_STATE:
+ return "Invalid object state";
+
case BOTAN_FFI_ERROR_NOT_IMPLEMENTED:
return "Not implemented";
case BOTAN_FFI_ERROR_INVALID_OBJECT:
return "Invalid object handle";
+ case BOTAN_FFI_ERROR_TLS_ERROR:
+ return "TLS error";
+
+ case BOTAN_FFI_ERROR_HTTP_ERROR:
+ return "HTTP error";
+
case BOTAN_FFI_ERROR_UNKNOWN_ERROR:
return "Unknown error";
}