From 35f3497d371a0a05098fcfdbe6e40d91095ef06c Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 11 Jun 2015 03:25:03 +0300 Subject: add error codes & messages to the library --- utils/common.hpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 utils/common.hpp (limited to 'utils/common.hpp') diff --git a/utils/common.hpp b/utils/common.hpp new file mode 100644 index 0000000..af61a32 --- /dev/null +++ b/utils/common.hpp @@ -0,0 +1,38 @@ +/** + * \file + * \author Egor Tensin + * \date 2015 + * \copyright This file is licensed under the terms of the MIT License. + * See LICENSE.txt for details. + */ + +#pragma once + +#include + +#include + +namespace aesni +{ + class ErrorDetailsThrowsInDestructor + { + public: + ErrorDetailsThrowsInDestructor() + { + aesni_make_error_success(get()); + } + + ~ErrorDetailsThrowsInDestructor() + { + if (m_impl.ec != AESNI_ERROR_SUCCESS) + throw std::runtime_error(aesni_strerror(m_impl.ec)); + } + + AesNI_ErrorDetails* get() { return &m_impl; } + + operator AesNI_ErrorDetails*() { return get(); } + + private: + AesNI_ErrorDetails m_impl; + }; +} -- cgit v1.2.3