diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-11 19:48:49 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2015-06-11 19:48:49 +0300 |
commit | e484372bf3f618eb30b8e6970fd13efa20c48509 (patch) | |
tree | 54a5f9cc4cc3eb8d787bf123a84630bda19db12f /utils | |
parent | add utils/cxx (diff) | |
download | aes-tools-e484372bf3f618eb30b8e6970fd13efa20c48509.tar.gz aes-tools-e484372bf3f618eb30b8e6970fd13efa20c48509.zip |
add error message formatting functions
Diffstat (limited to 'utils')
-rw-r--r-- | utils/cxx/include/aesnixx/error.hpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/utils/cxx/include/aesnixx/error.hpp b/utils/cxx/include/aesnixx/error.hpp index af61a32..db390ea 100644 --- a/utils/cxx/include/aesnixx/error.hpp +++ b/utils/cxx/include/aesnixx/error.hpp @@ -10,7 +10,11 @@ #include <aesni/all.h> +#include <cstdlib> + #include <stdexcept> +#include <string> +#include <vector> namespace aesni { @@ -24,8 +28,13 @@ namespace aesni ~ErrorDetailsThrowsInDestructor() { - if (m_impl.ec != AESNI_ERROR_SUCCESS) - throw std::runtime_error(aesni_strerror(m_impl.ec)); + if (aesni_get_error_code(get()) != AESNI_ERROR_SUCCESS) + { + std::vector<char> msg; + msg.resize(aesni_format_error(get(), NULL, 0)); + aesni_format_error(get(), msg.data(), msg.size()); + throw std::runtime_error(std::string(msg.begin(), msg.end())); + } } AesNI_ErrorDetails* get() { return &m_impl; } |