Virgil Security Crypto library  2.6.3
VirgilSystemCryptoError.h
1 
37 #ifndef VIRGIL_SYSTEM_CRYPTO_ERROR_H
38 #define VIRGIL_SYSTEM_CRYPTO_ERROR_H
39 
40 #include <system_error>
41 
42 #include "../VirgilCryptoError.h"
43 
44 namespace virgil { namespace crypto { namespace foundation {
45 
50 class VirgilSystemCryptoErrorCategory : public std::error_category {
51 public:
56  const char* name() const noexcept override;
57 
63  std::string message(int ev) const noexcept override;
64 };
65 
72 
84 inline int system_crypto_handler_get_result(int result) {
85  if (result >= 0) { return result; }
87 }
88 
99 inline void system_crypto_handler(int result) {
100  (void) system_crypto_handler_get_result(result);
101 }
102 
118 template<typename CatchHandler>
119 inline int system_crypto_handler_get_result(int result, CatchHandler catch_handler) {
120  if (result >= 0) { return result; }
121  try {
123  } catch (...) {
124  catch_handler(result);
125  return 0;
126  }
127 }
128 
142 template<typename CatchHandler>
143 inline void system_crypto_handler(int result, CatchHandler catch_handler) {
144  (void) system_crypto_handler_get_result<CatchHandler>(result, catch_handler);
145 }
146 
147 }}}
148 
149 #endif //VIRGIL_SYSTEM_CRYPTO_ERROR_H
const char * name() const noexceptoverride
Return name of the system crypto category.
Error category that handles error codes from the system crypto library.
Definition: VirgilSystemCryptoError.h:50
Root namespace for all Virgil Security libraries.
Definition: VirgilAsn1Compatible.h:46
This only exception that crypto library can produce.
Definition: VirgilCryptoException.h:54
const VirgilSystemCryptoErrorCategory & system_crypto_category() noexcept
Return singleton instance of the system crypto error category.
int system_crypto_handler_get_result(int result)
Handle value returned by underling system crypto library.
Definition: VirgilSystemCryptoError.h:84
std::string message(int ev) const noexceptoverride
Return description for the given error code.
void system_crypto_handler(int result)
Handle value returned by underling system crypto library.
Definition: VirgilSystemCryptoError.h:99