aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/utils/cxx/include/aesnixx/error.hpp
blob: af61a32242c452447d3b9101ce18467b34d56f56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
 * \file
 * \author Egor Tensin <Egor.Tensin@gmail.com>
 * \date 2015
 * \copyright This file is licensed under the terms of the MIT License.
 *            See LICENSE.txt for details.
 */

#pragma once

#include <aesni/all.h>

#include <stdexcept>

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;
    };
}