Cryptolens Client API for C++
basic_Error.hpp
1 #pragma once
2 
3 #include <stdlib.h>
4 
5 #include "api.hpp"
6 
7 namespace cryptolens_io {
8 
9 namespace v20190401 {
10 
11 namespace errors {
12 
13 /*
14  * Ok means no error has occured
15  * All other values indicate error
16  */
17 namespace Subsystem {
18 
19 int constexpr Ok = 0;
20 int constexpr Main = 1;
21 int constexpr Json = 2;
22 int constexpr Base64 = 3;
23 int constexpr RequestHandler = 4;
24 int constexpr SignatureVerifier = 5;
25 
26 } // namespace Subsystem
27 
28 /*
29  * Which method caused the error
30  */
31 namespace Call {
32 
33 int constexpr BASIC_SKM_ACTIVATE_RAW = 1;
34 int constexpr BASIC_CRYPTOLENS_ACTIVATE_RAW = BASIC_SKM_ACTIVATE_RAW;
35 
36 int constexpr BASIC_SKM_HANDLE_ACTIVATE_RAW = 2;
37 int constexpr BASIC_CRYPTOLENS_HANDLE_ACTIVATE_RAW = BASIC_SKM_HANDLE_ACTIVATE_RAW;
38 
39 int constexpr SIGNATURE_VERIFIER_SET_EXPONENT_BASE64 = 3;
40 int constexpr SIGNATURE_VERIFIER_SET_MODULUS_BASE64 = 4;
41 
42 int constexpr BASIC_SKM_HANDLE_ACTIVATE = 5;
43 int constexpr BASIC_CRYPTOLENS_HANDLE_ACTIVATE = BASIC_SKM_HANDLE_ACTIVATE;
44 
45 int constexpr BASIC_SKM_ACTIVATE = 5;
46 int constexpr BASIC_CRYPTOLENS_ACTIVATE = BASIC_SKM_ACTIVATE;
47 
48 int constexpr BASIC_SKM_ACTIVATE_FLOATING = 6;
49 int constexpr BASIC_CRYPTOLENS_ACTIVATE_FLOATING = BASIC_SKM_ACTIVATE_FLOATING;
50 
51 int constexpr BASIC_SKM_MAKE_LICENSE_KEY = 7;
52 int constexpr BASIC_CRYPTOLENS_MAKE_LICENSE_KEY = BASIC_SKM_MAKE_LICENSE_KEY;
53 
54 int constexpr BASIC_SKM_LAST_MESSAGE = 8;
55 int constexpr BASIC_CRYPTOLENS_LAST_MESSAGE = BASIC_SKM_LAST_MESSAGE;
56 
57 int constexpr BASIC_SKM_CREATE_TRIAL_KEY = 9;
58 int constexpr BASIC_CRYPTOLENS_CREATE_TRIAL_KEY = BASIC_SKM_CREATE_TRIAL_KEY;
59 
60 } // namespace Call
61 
62 // Errors for the Main subsystem
63 namespace Main {
64 
65 constexpr int UNKNOWN_SERVER_REPLY = 1;
66 constexpr int INVALID_ACCESS_TOKEN = 2;
67 constexpr int ACCESS_DENIED = 3;
68 constexpr int INCORRECT_INPUT_PARAMETER = 4;
69 constexpr int PRODUCT_NOT_FOUND = 5;
70 constexpr int KEY_NOT_FOUND = 6;
71 constexpr int KEY_BLOCKED = 7;
72 constexpr int DEVICE_LIMIT_REACHED = 8;
73 constexpr int KEY_EXPIRED = 9;
74 
75 } // namespace Main
76 
77 } // namespace errors
78 
90 class basic_Error {
91 private:
92  int call_;
93  int subsystem_;
94  int reason_;
95  size_t extra_;
96 public:
97  basic_Error(): call_(0), subsystem_(errors::Subsystem::Ok), reason_(0), extra_(0) { }
98  basic_Error(basic_Error const& e) = delete;
99  basic_Error & operator=(basic_Error const& e) = delete;
100 
107  explicit operator bool() const { return subsystem_ != errors::Subsystem::Ok; }
108 
109  virtual int get_subsystem(api::main api) const noexcept { return subsystem_; }
110  virtual int get_reason(api::main api) const noexcept { return reason_; }
111  virtual size_t get_extra(api::main api) const noexcept { return extra_; }
112 
119  virtual void reset(api::main api) { subsystem_ = errors::Subsystem::Ok; reason_ = 0; extra_ = 0; }
120 
121  virtual void set(api::main api, int subsystem) { subsystem_ = subsystem; }
122  virtual void set(api::main api, int subsystem, int reason) { subsystem_ = subsystem; reason_ = reason; }
123  virtual void set(api::main api, int subsystem, int reason, size_t extra) { subsystem_ = subsystem; reason_ = reason; extra_ = extra; }
124  virtual void set_call(api::main api, int call) { call_ = call; }
125 };
126 
127 } // namespace v20190401
128 
129 namespace v20180502 {
130 
131 namespace errors {
132 
133 namespace Subsystem = ::cryptolens_io::v20190401::errors::Subsystem;
134 namespace Call = ::cryptolens_io::v20190401::errors::Call;
135 namespace Main = ::cryptolens_io::v20190401::errors::Main;
136 
137 } // namespace errors
138 
140 
141 } // namespace v20180502
142 
143 namespace latest {
144 
145 namespace errors {
146 
147 namespace Subsystem = ::cryptolens_io::v20190401::errors::Subsystem;
148 namespace Call = ::cryptolens_io::v20190401::errors::Call;
149 namespace Main = ::cryptolens_io::v20190401::errors::Main;
150 
151 } // namespace errors
152 
154 
155 } // namespace latest
156 
157 } // namespace cryptolens_io
Definition: basic_Error.hpp:31
virtual void reset(api::main api)
Definition: basic_Error.hpp:119
Definition: ActivateError.hpp:5
Definition: basic_Error.hpp:90
Definition: basic_Error.hpp:63
Definition: basic_Error.hpp:17