10Duke Enterprise C++ Client
Loading...
Searching...
No Matches
NCryptHandle.h
1#ifndef TENDUKE_CRYPT_WIN_CNG_NCRYPTHANDLE_H
2#define TENDUKE_CRYPT_WIN_CNG_NCRYPTHANDLE_H
3
4#include "log/log.h"
5#include "../WinCNG_utils.h"
6#include <windows.h>
7#include <ncrypt.h>
8
9namespace tenduke { namespace crypto { namespace win { namespace cng {
10
11template<class H>
12class NCryptHandle
13{
14public:
15 explicit NCryptHandle(const H handle)
16 : handle(handle)
17 {
18 }
19
20 virtual ~NCryptHandle()
21 {
22 if (handle != 0) {
23 auto status = ::NCryptFreeObject(handle);
24
25 if (status != ERROR_SUCCESS) {
27 std::string("NCryptFreeObject failed. Ignored. Error code: ")
28 + std::to_string(status)
29 + ", message: "
30 + ::tenduke::crypto::win::cng::getNCryptErrorMessage(status)
31 );
32 }
33 }
34 }
35
36 virtual H getHandle() const
37 {
38 return handle;
39 }
40
41protected:
42 H handle;
43};
44
45
46}}}}
47
48#endif //TENDUKE_CRYPT_WIN_CNG_NCRYPTHANDLE_H
Cryptography services.
Definition CryptoException.h:7
void warning(const char *message)
Write message to global logger at WARNING-level.
Definition log.cpp:94
Root for classes, functions and globals of 10Duke C++ Client.
Definition APIRequest.h:4