1#ifndef _PRIVMXLIB_ENDPOINT_CONVERTED_EXT_EXCEPTION_HPP_
2#define _PRIVMXLIB_ENDPOINT_CONVERTED_EXT_EXCEPTION_HPP_
4#include "privmx/endpoint/core/Exception.hpp"
6#define DECLARE_SCOPE_ENDPOINT_EXCEPTION(NAME, MSG, SCOPE, CODE, ...) \
7 class NAME : public privmx::endpoint::core::Exception { \
9 static constexpr unsigned int SCOPE_CODE = (CODE); \
10 NAME() : privmx::endpoint::core::Exception(MSG, #NAME, SCOPE, (CODE << 16)) {} \
11 NAME(const std::string& description) \
12 : privmx::endpoint::core::Exception(MSG, #NAME, SCOPE, (CODE << 16), description) {} \
13 NAME(const std::string& description, unsigned int code) \
14 : privmx::endpoint::core::Exception(MSG, #NAME, SCOPE, (CODE << 16) | code, description) {} \
15 NAME(const std::string& msg, const std::string& name, unsigned int code) \
16 : privmx::endpoint::core::Exception(msg, name, SCOPE, (CODE << 16) | code, std::string()) {} \
17 NAME(const std::string& msg, const std::string& name, unsigned int code, const std::string& description) \
18 : privmx::endpoint::core::Exception(msg, name, SCOPE, (CODE << 16) | code, description) {} \
19 void rethrow() const override; \
21 inline void NAME::rethrow() const { \
25#define DECLARE_ENDPOINT_EXCEPTION(BASE_SCOPED, NAME, MSG, CODE, ...) \
26 class NAME : public BASE_SCOPED { \
28 static constexpr unsigned int FULL_CODE = (BASE_SCOPED::SCOPE_CODE << 16) | (CODE); \
29 NAME() : BASE_SCOPED(MSG, #NAME, CODE) {} \
30 NAME(const std::string& new_of_description) : BASE_SCOPED(MSG, #NAME, CODE, new_of_description) {} \
31 void rethrow() const override; \
33 inline void NAME::rethrow() const { \
42DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointServerRequestException,
"Invalid request exception",
"Server request", 0xFFFF)
44#define SERVER_REQUEST_EXCEPTIONS(X) \
45 X(ParseErrorException, "Parse error", 0x8043) \
46 X(InvalidRequestAException, "Invalid request", 0x80A8) \
47 X(MethodNotFoundException, "Method not found", 0x80A7) \
48 X(InvalidParamsException, "Invalid params", 0x80A6) \
49 X(InternalErrorException, "Internal error", 0x80A5) \
50 X(InvalidRequestBException, "Invalid request", 0x80A4) \
51 X(InvalidRequestCException, "Invalid request", 0x80A3)
53#define PRIVMX_SERVER_REQUEST_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointServerRequestException, NAME, MSG, CODE)
54SERVER_REQUEST_EXCEPTIONS(PRIVMX_SERVER_REQUEST_DECLARE)
55#undef PRIVMX_SERVER_REQUEST_DECLARE
57DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointServerException,
"Unknown server exception",
"Server", 0xF000)
59#define SERVER_EXCEPTIONS(X) \
60 X(UserDoesNotExistException, "User doesn't exist", 0x0009) \
61 X(AccessDeniedException, "Access denied", 0x0030) \
62 X(InvalidKeyException, "Invalid key", 0x0070) \
63 X(ThreadDoesNotExistException, "Thread does not exist", 0x6001) \
64 X(InvalidThreadKeyException, "Invalid thread key", 0x6002) \
65 X(ThreadMessageDoesNotExistException, "Thread message does not exist", 0x600D) \
66 X(InvalidKeyIdException, "Invalid key id", 0x6015) \
67 X(ContextDoesNotExistException, "Context does not exist", 0x6116) \
68 X(StoreDoesNotExistException, "Store does not exist", 0x6117) \
69 X(StoreFileDoesNotExistException, "Store file does not exist", 0x6118) \
70 X(StoreFileVersionMismatchException, "Store file version mismatch", 0x6128) \
71 X(InboxDoesNotExistException, "Inbox does not exist", 0x611E) \
72 X(KvdbDoesNotExistException, "Kvdb does not exist", 0x613C) \
73 X(KvdbEntryDoesNotExistException, "Kvdb entry does not exist", 0x613D)
75#define PRIVMX_SERVER_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointServerException, NAME, MSG, CODE)
76SERVER_EXCEPTIONS(PRIVMX_SERVER_DECLARE)
77#undef PRIVMX_SERVER_DECLARE
80#define PRIVMX_CODE(NAME, MSG, CODE) NAME::FULL_CODE,
81static_assert(::privmx::endpoint::core::exceptionCodesUnique({
82 SERVER_REQUEST_EXCEPTIONS(PRIVMX_CODE)
83 SERVER_EXCEPTIONS(PRIVMX_CODE)
84}),
"Duplicate exception code in server scope");
86#undef SERVER_REQUEST_EXCEPTIONS
87#undef SERVER_EXCEPTIONS
92DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointNotConnectedException,
"Unknown Network Exception",
"NetConnection", 0xE001)
94#define NET_EXCEPTIONS(X) \
95 X(NotConnectedException, "RpcGateway is not connected", 0x0001) \
96 X(WebsocketDisconnectedException, "Websocket disconnected", 0x0002) \
97 X(NoMessageReceivedException, "No message received, http session lost", 0x0003)
99#define PRIVMX_NET_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointNotConnectedException, NAME, MSG, CODE)
100NET_EXCEPTIONS(PRIVMX_NET_DECLARE)
101#undef PRIVMX_NET_DECLARE
103DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointServerException,
"Unknown Server Exception",
"Server", 0xE002)
105#define NET_SERVER_EXCEPTIONS(X) \
106 X(InvalidHttpStatusException, "Unexpected server data", 0x0001) \
107 X(UnexpectedServerDataException, "Unknown Server Exception", 0x0002)
109#define PRIVMX_NET_SERVER_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointServerException, NAME, MSG, CODE)
110NET_SERVER_EXCEPTIONS(PRIVMX_NET_SERVER_DECLARE)
111#undef PRIVMX_NET_SERVER_DECLARE
113DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointRpcException,
"Unknown Rpc exception",
"Rpc", 0xE0A4)
115#define RPC_EXCEPTIONS(X) \
116 X(TicketsCountIsEqualZeroException, "Tickets count is equal zero", 0x0001) \
117 X(WsConnectException, "wsConnect", 0x0002) \
118 X(WsSend1Exception, "WsSend1", 0x0003) \
119 X(WebSocketInvalidPayloadLengthException, "Invalid payload length", 0x0004) \
120 X(InvalidWebSocketRequestIdException, "Invalid WebSocket request id", 0x0005) \
121 X(HttpConnectException, "httpConnect", 0x0006) \
122 X(HttpRequestException, "httpRequest", 0x0007) \
123 X(WebSocketPingLoopStoppedException, "Ping loop stopped", 0x0008) \
124 X(WebSocketPingTimeoutException, "Ping timeout", 0x0009) \
125 X(InvalidHandshakeStateException, "Invalid handshake state", 0x000A) \
126 X(IncorrectHashmailException, "Incorrect hashmail", 0x000B) \
127 X(UnexpectedEcdhePacketFromServerException, "Unexpected ecdhe packet from server", 0x000C) \
128 X(UnexpectedEcdhexPacketFromServerException, "Unexpected ecdhex packet from server", 0x000D) \
129 X(InvalidWsChannelIdException, "Invalid wsChannelId", 0x000E) \
130 X(ErrorDuringGettingHTTPChannelException, "Error during getting HTTP channel", 0x000F) \
131 X(ConnectionDestroyedException, "Connection destroyed", 0x0010) \
132 X(SessionLostException, "Session lost", 0x0011) \
133 X(ProbeFailException, "Probe fail", 0x0012) \
134 X(InvalidHostException, "Invalid host", 0x0013) \
135 X(WebsocketCannotBeMainChannelWhenItIsDisabledException, "Websocket cannot be main channel when it is disabled", 0x0014) \
136 X(RejectedException, "Rejected", 0x0015) \
137 X(FrameHeaderTagsAreNotEqualException, "Frame header tags are not equal", 0x0016) \
138 X(UnsupportedFrameVersionException, "Unsupported frame version", 0x0017) \
139 X(FrameMacsAreNotEqualException, "Frame macs are not equal", 0x0018) \
140 X(InvalidNextReadStateException, "Invalid next read state", 0x0019) \
141 X(WriteStateIsNotInitializedException, "Write state is not initialized", 0x001A) \
142 X(TicketHandshakeErrorException, "Ticket handshake error", 0x001B)
144#define PRIVMX_RPC_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointRpcException, NAME, MSG, CODE)
145RPC_EXCEPTIONS(PRIVMX_RPC_DECLARE)
146#undef PRIVMX_RPC_DECLARE
149#define PRIVMX_CODE(NAME, MSG, CODE) NAME::FULL_CODE,
150static_assert(::privmx::endpoint::core::exceptionCodesUnique({
151 NET_EXCEPTIONS(PRIVMX_CODE)
152 NET_SERVER_EXCEPTIONS(PRIVMX_CODE)
153 RPC_EXCEPTIONS(PRIVMX_CODE)
154}),
"Duplicate exception code in network scope");
157#undef NET_SERVER_EXCEPTIONS
163DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointLibException,
"Unknown Lib exception",
"Lib", 0xE003)
165#define LIB_EXCEPTIONS(X) \
166 X(CannotStringifyVarException, "Cannot stringify var", 0x0001) \
167 X(KeyNotExistException, "Key not exist", 0x0002) \
168 X(VarIsNotObjectException, "Var is not object", 0x0003) \
169 X(VarIsNotArrayException, "Var is not array", 0x0004) \
170 X(OperationCancelledException, "Operation canceled", 0x0005) \
171 X(NotImplementedException, "Not implemented", 0x0006) \
172 X(InvalidVersionFormatException, "Invalid version format", 0x0007) \
173 X(JSONParseException, "Cannot parse JSON", 0x0008)
175#define PRIVMX_LIB_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointLibException, NAME, MSG, CODE)
176LIB_EXCEPTIONS(PRIVMX_LIB_DECLARE)
177#undef PRIVMX_LIB_DECLARE
180#define PRIVMX_CODE(NAME, MSG, CODE) NAME::FULL_CODE,
181static_assert(::privmx::endpoint::core::exceptionCodesUnique({
182 LIB_EXCEPTIONS(PRIVMX_CODE)
183}),
"Duplicate exception code in internal scope");
190DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointCryptoException,
"Unknown Crypto exception",
"Crypto", 0xE0A1)
192#define CRYPTO_EXCEPTIONS(X) \
193 X(UnsupportedKeyFormatException, "Unsupported key format", 0x0001) \
194 X(EmptyPointException, "Empty point", 0x0002) \
195 X(InvalidSignatureSizeException, "Invalid signature size", 0x0003) \
196 X(InvalidSignatureHeaderException, "Invalid signature header", 0x0004) \
197 X(ECCIsNotInitializedException, "ECC is not initialized", 0x0005) \
198 X(EmptyBNException, "Empty BN", 0x0006) \
199 X(WrongMessageSecurityTagException, "Wrong message security tag", 0x0007) \
200 X(DecryptInvalidKeyLengthException, "Decrypt invalid key length", 0x0008) \
201 X(MissingIvException, "Missing iv", 0x0009) \
202 X(UnknownDecryptionTypeException, "Unknown decryption type", 0x000A) \
203 X(UnsupportedHashAlgorithmException, "Unsupported hash algorithm", 0x000B) \
204 X(CryptoNotImplementedException, "Not implemented", 0x000C) \
205 X(InvalidStrengthException, "Invalid strength", 0x000D) \
206 X(InvalidEntropyException, "Invalid entropy", 0x000E) \
207 X(InvalidMnemonicException, "Invalid mnemonic", 0x000F) \
208 X(InvalidChecksumException, "Invalid checksum", 0x0010) \
209 X(EncryptInvalidKeyLengthException, "Encrypt invalid key length", 0x0011) \
210 X(OnlyHmacSHA256WithIvIsSupportedForAES256CBCException, "Only hmac SHA-256 with iv is supported for AES-256-CBC", 0x0012) \
211 X(CannotPassIvToDeterministicAES256CBCHmacSHA256Exception, "Cannot pass iv to deterministic AES-256-CBC hmac SHA-256", 0x0013) \
212 X(XTEAECBEncryptionDoesntSupportHmacAndIvException, "XTEA-ECB encryption doesn't support hmac and iv", 0x0014) \
213 X(UnsupportedEncryptionAlgorithmException, "Unsupported encryption algorithm", 0x0015) \
214 X(MissingRequiredSignatureException, "Missing required signature", 0x0016) \
215 X(InvalidFirstByteOfCipherException, "Invalid first byte of cipher", 0x0017) \
216 X(GivenPrivKeyDoesNotMatchException, "Given priv key does not match", 0x0018) \
217 X(UnsupportedAlgorithmException, "Unsupported algorithm", 0x0019) \
218 X(UnsupportedVersionException, "Unsupported version", 0x001A) \
219 X(IncorrectParamsException, "Incorrect params", 0x001B) \
220 X(InvalidHandshakeStateException, "Invalid handshake state", 0x001C) \
221 X(InvalidBNException, "Invalid B N", 0x001D) \
222 X(InvalidM2Exception, "Invalid M2", 0x001E) \
223 X(InvalidVersionException, "Invalid version", 0x001F) \
224 X(InvalidParentFingerprintException, "Invalid parent fingerprint", 0x0020) \
225 X(InvalidResultSizeException, "Invalid result size", 0x0022) \
226 X(InvalidNetworkException, "Invalid network", 0x0023) \
227 X(InvalidCompressionFlagException, "Invalid network", 0x0024) \
228 X(InvalidWIFPayloadLengthException, "Invalid WIF payload length", 0x0025) \
229 X(OpenSSLException, "OpenSSL Exception", 0x0026) \
230 X(PrivmxDriverCryptoException, "privmxDrvCrypto Exception", 0x0027) \
231 X(PrivmxDriverEccException, "privmxDrvEcc Exception", 0x0028) \
232 X(GivenPublicKeyDoesNotMatchWithSignatureException, "DGiven public key does not match with signature", 0x0029) \
233 X(ExtKeyDoesNotHoldPrivateKeyException, "Ext key does not hold private key", 0x002A)
235#define PRIVMX_CRYPTO_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointCryptoException, NAME, MSG, CODE)
236CRYPTO_EXCEPTIONS(PRIVMX_CRYPTO_DECLARE)
237#undef PRIVMX_CRYPTO_DECLARE
239DECLARE_SCOPE_ENDPOINT_EXCEPTION(EndpointPrivFsException,
"Unknown PrivFs exception",
"PrivFs", 0xE0A3)
241#define PRIVFS_EXCEPTIONS(X) \
242 X(InvalidHostException, "Invalid host", 0x0001) \
243 X(NoCallbackForAdditionalLoginStepException, "No callback for additional login step", 0x0002) \
244 X(UnsupportedEmptyKeystoreException, "Unsupported empty keystore", 0x0003) \
245 X(DifferentIdentityException, "Different identity", 0x0004) \
246 X(UnsupportedMasterRecordVersionException, "Unsupported masterRecord.version", 0x0005) \
247 X(CannotDecryptLevel2OfMasterRecordException, "Cannot decrypt level 2 of master record", 0x0006) \
248 X(RpcProxyRequestNotImplementedException, "Rpc proxy request not implemented", 0x0007) \
249 X(UserDoesNotExistsException, "User does not exists", 0x0008) \
250 X(SenderCannotBeEmptyException, "Sender cannot be empty", 0x0009) \
251 X(SenderMustBeInstanceOfIdentityException, "Sender must be instance of Identity", 0x000A) \
252 X(MessageMustContainsAtLeastOneReceiverException, "Message must contains at least one receiver", 0x000B) \
253 X(InvalidSinkPrivateKeyException, "Invalid sink private key", 0x000C) \
254 X(PrivFsNotImplementedException, "Not implemented", 0x000D) \
255 X(MnemonicIsNotGeneratedYetException, "Mnemonic is not generated yet", 0x000E) \
256 X(InvalidResponseException, "INVALID_RESPONSE", 0x000F) \
257 X(UnsupportedPrivDataInfoVersionException, "Unsupported privDataInfo version", 0x0010) \
258 X(CosignerKeystoreStateAndUuidAreRequiredException, "Cosigner 'keystore', 'state' and 'uuid' are required", 0x0011) \
259 X(ExpectedDocumentsPacketExportClassException, "Expected DocumentsPacket export class", 0x0012) \
260 X(CannotGetPropertiesFromNonSrpKeySessionConnectionException, "Cannot get properties from non srp/key/session connection", 0x0013) \
261 X(CannotGetUsernameFromNonSrpKeySessionConnectionException, "Cannot get username from non srp/key/session connection", 0x0014) \
262 X(CannotReloginUserMismatchException, "Cannot relogin - user mismatch", 0x0015) \
263 X(ConnectionCannotBeRestoredBySessionException, "Connection cannot be restored by session", 0x0016) \
264 X(WorkerRunningException, "Worker running", 0x0017)
266#define PRIVMX_PRIVFS_DECLARE(NAME, MSG, CODE) DECLARE_ENDPOINT_EXCEPTION(EndpointPrivFsException, NAME, MSG, CODE)
267PRIVFS_EXCEPTIONS(PRIVMX_PRIVFS_DECLARE)
268#undef PRIVMX_PRIVFS_DECLARE
271#define PRIVMX_CODE(NAME, MSG, CODE) NAME::FULL_CODE,
272static_assert(::privmx::endpoint::core::exceptionCodesUnique({
273 CRYPTO_EXCEPTIONS(PRIVMX_CODE)
274 PRIVFS_EXCEPTIONS(PRIVMX_CODE)
275}),
"Duplicate exception code in crypto scope");
277#undef CRYPTO_EXCEPTIONS
278#undef PRIVFS_EXCEPTIONS
284#undef DECLARE_SCOPE_ENDPOINT_EXCEPTION
285#undef DECLARE_ENDPOINT_EXCEPTION