Offline Transaction Signing (OTS) 0.1.0
Loading...
Searching...
No Matches
ots-exceptions.hpp
Go to the documentation of this file.
1#pragma once
2#include <vector>
3
9#ifdef __PRETTY_FUNCTION__
10#define NOT_IMPLEMENTED_YET() throw ots::exception::NotImplementedYet(__PRETTY_FUNCTION__)
11#else
12#define NOT_IMPLEMENTED_YET() throw ots::exception::NotImplementedYet(__func__)
13#endif
14
15#define REGISTER_EXCEPTION(CLASS, CODE, NAME) \
16 static constexpr int32_t error_code = CODE; \
17 static constexpr const char* error_class = NAME; \
18 protected: \
19 static inline bool registered = ots::exception::Exception::registerException<CLASS>(error_code, error_class);
20
21
22#include <stdexcept>
23#include <string>
24
25namespace ots {
35 namespace exception {
41 class Exception {
42 public:
44 int32_t error_code;
45 const char* error_class;
46 const std::type_info& type;
47 };
48
49 static std::vector<RegisteredException>& registry() {
50 static std::vector<RegisteredException> instances;
51 return instances;
52 }
53
54 protected:
55 template<typename T>
56 static bool registerException(int32_t code, const char* cls) {
57 registry().push_back({code, cls, typeid(T)});
58 return true;
59 }
60
61 public:
62 virtual ~Exception() = default;
63 virtual const char* what() const noexcept = 0;
64 };
65
72 class RuntimeError: public std::runtime_error, public Exception {
73 REGISTER_EXCEPTION(RuntimeError, -1, "RuntimeError")
74 public:
75 inline explicit RuntimeError(const std::string& msg): std::runtime_error(msg) {};
76 const char* what() const noexcept override { return std::runtime_error::what(); }
77 };
78
85 class LogicError: public std::logic_error, public Exception {
86 REGISTER_EXCEPTION(LogicError, -2, "LogicError")
87 public:
88 inline explicit LogicError(const std::string& msg): std::logic_error(msg) {};
89 const char* what() const noexcept override { return std::logic_error::what(); }
90 };
91
98 class InvalidArgument: public std::invalid_argument, public Exception {
99 REGISTER_EXCEPTION(InvalidArgument, -3, "InvalidArgument")
100 public:
101 inline explicit InvalidArgument(const std::string& msg): std::invalid_argument(msg) {};
102 const char* what() const noexcept override { return std::invalid_argument::what(); }
103 };
104
110 class RangeError: public std::range_error, public Exception {
111 REGISTER_EXCEPTION(RangeError, -4, "RangeError")
112 public:
113 inline explicit RangeError(const std::string& msg): std::range_error(msg) {};
114 const char* what() const noexcept override { return std::range_error::what(); }
115 };
116
121 class NotImplementedYet: public std::logic_error, public Exception {
122 REGISTER_EXCEPTION(NotImplementedYet, -5, "NotImplementedYet")
123 public:
124 inline NotImplementedYet(): std::logic_error("Not implemented yet") {};
125 inline explicit NotImplementedYet(const std::string& msg): std::logic_error(std::string("Not implemented yet: ") + msg) {};
126 const char* what() const noexcept override { return std::logic_error::what(); }
127 };
128
134 class DomainError: public std::domain_error, public Exception {
135 REGISTER_EXCEPTION(DomainError, -6, "DomainError")
136 public:
137 inline explicit DomainError(const std::string& msg): std::domain_error(msg) {};
138 const char* what() const noexcept override { return std::domain_error::what(); }
139 };
140
147 class OutOfRange: public std::out_of_range, public Exception {
148 REGISTER_EXCEPTION(OutOfRange, -7, "OutOfRange")
149 public:
150 inline explicit OutOfRange(const std::string& msg): std::out_of_range(msg) {};
151 const char* what() const noexcept override { return std::out_of_range::what(); }
152 };
153
159 REGISTER_EXCEPTION(BufferOverflowException, -71, "BufferOverflowException")
160 public:
161 inline explicit BufferOverflowException(): OutOfRange("The size is bigger as the buffer! Security related exception!") {};
162 inline explicit BufferOverflowException(const std::string& msg): OutOfRange(msg) {};
163 };
164
170 REGISTER_EXCEPTION(MemoryAllocationError, -11, "MemoryAllocationError")
171 public:
172 inline explicit MemoryAllocationError(): RuntimeError("Couldn't allocate memory!") {};
173 };
174
180 REGISTER_EXCEPTION(SecurityException, -61, "SecurityException")
181 public:
182 inline explicit SecurityException(const std::string& msg): DomainError(std::string("SECURITY EXCEPTION: ") + msg) {};
183 };
184
190 REGISTER_EXCEPTION(SecurityError, -12, "SecurityError")
191 public:
192 inline explicit SecurityError(const std::string& msg): RuntimeError(std::string("SECURITY ERROR: ") + msg) {};
193 };
194
200 REGISTER_EXCEPTION(LowEntropy, -121, "LowEntropy")
201 public:
202 inline explicit LowEntropy(): SecurityError("Low entropy detected!") {};
203 };
204
210 REGISTER_EXCEPTION(UnknownNetwork, -62, "UnknownNetwork")
211 public:
212 inline explicit UnknownNetwork(): DomainError("Unknown network") {};
213 };
214
220 namespace wipeablestring {
221
227 REGISTER_EXCEPTION(UnsafeConversion, -1001, "UnsafeConversion")
228 public:
229 inline explicit UnsafeConversion(): SecurityException("Unsafe conversion to std::string, use wipeableString.insecure() instead, if you really need to do this!") {};
230 };
231 }
232
238 namespace wipeablevector {
243 REGISTER_EXCEPTION(UnsafeConversion, -2001, "UnsafeConversion")
244 public:
245 inline explicit UnsafeConversion(): SecurityException("Unsafe conversion to std::vector, use wipeableVector.insecure() instead, if you really need to do this!") {};
246 };
247 }
248
254 namespace sign {
260 REGISTER_EXCEPTION(InvalidSignature, -3001, "InvalidSignature")
261 public:
262 inline explicit InvalidSignature(): DomainError("Invalid signature") {};
263 inline explicit InvalidSignature(const std::string& msg): DomainError(msg) {};
264 };
265
271 REGISTER_EXCEPTION(EmptyMessage, -3002, "EmptyMessage")
272 public:
273 inline explicit EmptyMessage(): DomainError("Empty message") {};
274 };
275
281 REGISTER_EXCEPTION(EmptySignature, -3003, "EmptySignature")
282 public:
283 inline explicit EmptySignature(): DomainError("Empty signature") {};
284 };
285 }
286
292 namespace seed {
298 REGISTER_EXCEPTION(NoDefaultLanguageSet, -4001, "NoDefaultLanguageSet")
299 public:
300 inline explicit NoDefaultLanguageSet(): DomainError("No default language set for seed type") {};
301 };
302
308 REGISTER_EXCEPTION(LanguageNotFound, -4002, "LanguageNotFound")
309 public:
310 inline explicit LanguageNotFound(): OutOfRange("Language not found") {};
311 inline explicit LanguageNotFound(const std::string& msg): OutOfRange(msg) {};
312 };
313
319 REGISTER_EXCEPTION(LanguageNotSupportedBySeedType, -4003, "LanguageNotSupportedBySeedType")
320 public:
321 inline explicit LanguageNotSupportedBySeedType(): DomainError("Language not supported by seed type") {};
322 };
323
329 REGISTER_EXCEPTION(WordCount, -4004, "WordCount")
330 public:
331 inline explicit WordCount(): OutOfRange("Wrong number of words in seed phrase") {};
332 };
333
339 REGISTER_EXCEPTION(SeedEncodingFailed, -4005, "SeedEncodingFailed")
340 public:
341 inline explicit SeedEncodingFailed(): DomainError("Unable to encode seed") {};
342 inline explicit SeedEncodingFailed(const std::string& msg): DomainError(msg) {};
343 };
344
350 REGISTER_EXCEPTION(SeedDecodingFailed, -4006, "SeedDecodingFailed")
351 public:
352 inline explicit SeedDecodingFailed(): DomainError("Unable to decode seed") {};
353 inline explicit SeedDecodingFailed(const std::string& msg): DomainError(msg) {};
354 };
355
362 REGISTER_EXCEPTION(LengthMismatch, -4007, "LengthMismatch")
363 public:
364 inline explicit LengthMismatch(): DomainError("Seed length mismatch") {};
365 };
366
372 REGISTER_EXCEPTION(TooFewValues, -4008, "TooFewValues")
373 public:
374 inline explicit TooFewValues(): DomainError("Too few values provided") {};
375 };
376
382 REGISTER_EXCEPTION(PasswordNotSupported, -4009, "PasswordNotSupported")
383 public:
384 inline explicit PasswordNotSupported(): DomainError("Password not supported for seed type") {};
385 };
386
391 class MergeError : public DomainError {
392 REGISTER_EXCEPTION(MergeError, -4010, "MergeError")
393 public:
394 explicit MergeError(const std::string& msg) : DomainError(msg) {}
395 };
396 }
397
403 namespace polyseed {
411
417 REGISTER_EXCEPTION(UnsupportedLanguage, -5002, "UnsupportedLanguage")
418 public:
419 inline explicit UnsupportedLanguage(): ots::exception::seed::LanguageNotFound("Unsupported Language") {};
420 };
421
427 REGISTER_EXCEPTION(ChecksumMismatch, -5003, "ChecksumMismatch")
428 public:
429 inline explicit ChecksumMismatch(): DomainError("Checksum mismatch") {};
430 };
431
437 REGISTER_EXCEPTION(UnsupportedFeatures, -5004, "UnsupportedFeatures")
438 public:
439 inline explicit UnsupportedFeatures(): DomainError("One or more features are not supported") {};
440 };
441
447 REGISTER_EXCEPTION(InvalidSeedFormat, -5005, "InvalidSeedFormat")
448 public:
449 inline explicit InvalidSeedFormat(): DomainError("Invalid format of provided seed phrase") {};
450 };
451
459
465 REGISTER_EXCEPTION(AmbigousLanguage, -5007, "AmbigousLanguage")
466 public:
467 inline explicit AmbigousLanguage(): DomainError("Seed phrase language is ambigous. Language must be explicit specified") {};
468 };
469
475 REGISTER_EXCEPTION(NoPasswordProvided, -5008, "NoPasswordProvided")
476 public:
477 inline explicit NoPasswordProvided(): DomainError("Seed is encrypted, but no password provided") {};
478 };
479 }
480
486 namespace legacyseed {
488 REGISTER_EXCEPTION(InvalidSeedFormat, -6001, "InvalidSeedFormat")
489 public:
490 inline explicit InvalidSeedFormat(): ots::exception::seed::SeedDecodingFailed("Invalid format of provided seed phrase") {};
491 };
492 }
493
499 namespace seedjar {
500
506 REGISTER_EXCEPTION(SeedNotFound, -7001, "SeedNotFound")
507 public:
508 inline SeedNotFound(): OutOfRange("Seed not found") {};
509 };
510 }
511
517 namespace keystore {
523 REGISTER_EXCEPTION(LockedAccessAttempt, -8001, "LockedAccessAttempt")
524 public:
525 inline explicit LockedAccessAttempt(): SecurityException("Attempted to access locked key data") {};
526 inline explicit LockedAccessAttempt(const std::string& msg): SecurityException(msg) {};
527 };
528
534 REGISTER_EXCEPTION(LockedWriteAttempt, -8002, "LockedWriteAttempt")
535 public:
536 inline LockedWriteAttempt(): LockedAccessAttempt("Attempted to write to locked key data") {};
537 };
538
544 namespace polyseed {
550 REGISTER_EXCEPTION(ActivePolyseedDataSession, -8101, "ActivePolyseedDataSession")
551 public:
552 inline explicit ActivePolyseedDataSession(): DomainError("There is already an active polyseed data session running. Only one session at a time allowed") {};
553 };
554
560 REGISTER_EXCEPTION(NoActivePolyseedDataSession, -8102, "NoActivePolyseedDataSession")
561 public:
562 inline explicit NoActivePolyseedDataSession(): DomainError("There is no active polyseed data session running. Can't work on no existing session") {};
563 };
564
570 REGISTER_EXCEPTION(PolyseedDataReadOnlySession, -8103, "PolyseedDataReadOnlySession")
571 public:
572 inline explicit PolyseedDataReadOnlySession(): DomainError("Attempt to write in read only session") {};
573 };
574 }
575 }
576
582 namespace wallet {
583
589 REGISTER_EXCEPTION(AddressNotFound, -9001, "AddressNotFound")
590 public:
591 inline AddressNotFound(): OutOfRange("Address not found in wallet") {};
592 };
593
599 REGISTER_EXCEPTION(ImportOutputs, -9002, "ImportOutputs")
600 public:
601 inline explicit ImportOutputs(): InvalidArgument("Import outputs failed") {};
602 inline explicit ImportOutputs(const std::string& msg): InvalidArgument(msg) {};
603 };
604
610 REGISTER_EXCEPTION(ExportKeyImages, -9003, "ExportKeyImages")
611 public:
612 inline explicit ExportKeyImages(): DomainError("Import outputs failed") {};
613 inline explicit ExportKeyImages(const std::string& msg): DomainError(msg) {};
614 };
615
621 REGISTER_EXCEPTION(InvalidCiphertext, -9004, "InvalidCiphertext")
622 public:
623 inline explicit InvalidCiphertext(): DomainError("Invalid ciphertext") {};
624 inline explicit InvalidCiphertext(const std::string& msg): DomainError(msg) {};
625 };
626
632 REGISTER_EXCEPTION(CiphertextAuthenticationFailed, -9005, "CiphertextAuthenticationFailed")
633 public:
634 inline explicit CiphertextAuthenticationFailed(): DomainError("Ciphertext authentication failed") {};
635 inline explicit CiphertextAuthenticationFailed(const std::string& msg): DomainError(msg) {};
636 };
637
643 REGISTER_EXCEPTION(InternalError, -9006, "InternalError")
644 public:
645 inline explicit InternalError(): DomainError("Internal error") {};
646 inline explicit InternalError(const std::string& msg): DomainError(msg) {};
647 };
648 }
649
655 namespace account {
661 REGISTER_EXCEPTION(GenerationFailed, -10001, "GenerationFailed")
662 public:
663 inline explicit GenerationFailed(): DomainError("Account generation failed") {};
664 };
665 }
666
672 namespace tx {
673
679 REGISTER_EXCEPTION(Invalid, -11001, "Invalid")
680 public:
681 inline explicit Invalid(): InvalidArgument("Transaction is invalid") {};
682 inline explicit Invalid(const std::string& msg): InvalidArgument(msg) {};
683 };
684 }
685
691 namespace address {
692
698 REGISTER_EXCEPTION(Invalid, -12001, "Invalid")
699 public:
700 inline Invalid(): InvalidArgument("Not a valid Monero address") {};
701 };
702
708 REGISTER_EXCEPTION(NotIntegrated, -12002, "NotIntegrated")
709 public:
710 inline NotIntegrated(): InvalidArgument("Not an integrated address") {};
711 };
712 }
713 }
714}
size is bigger then buffer
Definition ots-exceptions.hpp:158
BufferOverflowException(const std::string &msg)
Definition ots-exceptions.hpp:162
BufferOverflowException()
Definition ots-exceptions.hpp:161
errors related to the library use itself
Definition ots-exceptions.hpp:134
const char * what() const noexcept override
Definition ots-exceptions.hpp:138
DomainError(const std::string &msg)
Definition ots-exceptions.hpp:137
Definition ots-exceptions.hpp:41
static bool registerException(int32_t code, const char *cls)
Definition ots-exceptions.hpp:56
virtual const char * what() const noexcept=0
static std::vector< RegisteredException > & registry()
Definition ots-exceptions.hpp:49
virtual ~Exception()=default
provided an invalid argument
Definition ots-exceptions.hpp:98
const char * what() const noexcept override
Definition ots-exceptions.hpp:102
InvalidArgument(const std::string &msg)
Definition ots-exceptions.hpp:101
violation of logical preconditions or class invariants
Definition ots-exceptions.hpp:85
const char * what() const noexcept override
Definition ots-exceptions.hpp:89
LogicError(const std::string &msg)
Definition ots-exceptions.hpp:88
Low entropy detected.
Definition ots-exceptions.hpp:199
LowEntropy()
Definition ots-exceptions.hpp:202
Could not allocate memory.
Definition ots-exceptions.hpp:169
MemoryAllocationError()
Definition ots-exceptions.hpp:172
Sole purpose of this exception is to create already the stub and mark as incomplete,...
Definition ots-exceptions.hpp:121
NotImplementedYet()
Definition ots-exceptions.hpp:124
NotImplementedYet(const std::string &msg)
Definition ots-exceptions.hpp:125
const char * what() const noexcept override
Definition ots-exceptions.hpp:126
arguments outside of expected range. Needle not in Haystack ;)
Definition ots-exceptions.hpp:147
OutOfRange(const std::string &msg)
Definition ots-exceptions.hpp:150
const char * what() const noexcept override
Definition ots-exceptions.hpp:151
range error in internal computation
Definition ots-exceptions.hpp:110
const char * what() const noexcept override
Definition ots-exceptions.hpp:114
RangeError(const std::string &msg)
Definition ots-exceptions.hpp:113
Conditions only detectable at runtime.
Definition ots-exceptions.hpp:72
RuntimeError(const std::string &msg)
Definition ots-exceptions.hpp:75
const char * what() const noexcept override
Definition ots-exceptions.hpp:76
Any security realted error: like no random generator available.
Definition ots-exceptions.hpp:189
SecurityError(const std::string &msg)
Definition ots-exceptions.hpp:192
Any security realted issue.
Definition ots-exceptions.hpp:179
SecurityException(const std::string &msg)
Definition ots-exceptions.hpp:182
a network is not known
Definition ots-exceptions.hpp:209
UnknownNetwork()
Definition ots-exceptions.hpp:212
account generation failed
Definition ots-exceptions.hpp:660
GenerationFailed()
Definition ots-exceptions.hpp:663
The provided string is not a valid Monero address.
Definition ots-exceptions.hpp:697
Invalid()
Definition ots-exceptions.hpp:700
The provided string is not an integrated address.
Definition ots-exceptions.hpp:707
NotIntegrated()
Definition ots-exceptions.hpp:710
a process tried to access locked key data
Definition ots-exceptions.hpp:522
LockedAccessAttempt(const std::string &msg)
Definition ots-exceptions.hpp:526
LockedAccessAttempt()
Definition ots-exceptions.hpp:525
a process tried to write to locked key data
Definition ots-exceptions.hpp:533
LockedWriteAttempt()
Definition ots-exceptions.hpp:536
a process tried to start a new session during an active session ongoing
Definition ots-exceptions.hpp:549
ActivePolyseedDataSession()
Definition ots-exceptions.hpp:552
no active session ongoing which could be commited or discarded
Definition ots-exceptions.hpp:559
NoActivePolyseedDataSession()
Definition ots-exceptions.hpp:562
write attempt while read only session
Definition ots-exceptions.hpp:569
PolyseedDataReadOnlySession()
Definition ots-exceptions.hpp:572
Definition ots-exceptions.hpp:487
InvalidSeedFormat()
Definition ots-exceptions.hpp:490
Seed phrase language is ambigous. Language must be explicit specified.
Definition ots-exceptions.hpp:464
AmbigousLanguage()
Definition ots-exceptions.hpp:467
a checksum mismatch detected
Definition ots-exceptions.hpp:426
ChecksumMismatch()
Definition ots-exceptions.hpp:429
a seed phrase is not in the expected format
Definition ots-exceptions.hpp:446
InvalidSeedFormat()
Definition ots-exceptions.hpp:449
Could not allocate memory.
Definition ots-exceptions.hpp:456
Seed encrypted, but no password provided.
Definition ots-exceptions.hpp:474
NoPasswordProvided()
Definition ots-exceptions.hpp:477
a feature is not supported by polyseed
Definition ots-exceptions.hpp:436
UnsupportedFeatures()
Definition ots-exceptions.hpp:439
a language is not supported by polyseed
Definition ots-exceptions.hpp:416
UnsupportedLanguage()
Definition ots-exceptions.hpp:419
a polyseed expected has a different word count. Polyseed are 16 words
Definition ots-exceptions.hpp:408
a language expected if not found
Definition ots-exceptions.hpp:307
LanguageNotFound()
Definition ots-exceptions.hpp:310
LanguageNotFound(const std::string &msg)
Definition ots-exceptions.hpp:311
a language is not supported by the seed type
Definition ots-exceptions.hpp:318
LanguageNotSupportedBySeedType()
Definition ots-exceptions.hpp:321
a seed expected has a different length, and is used instead of WordCount on merging Values/seed phras...
Definition ots-exceptions.hpp:361
LengthMismatch()
Definition ots-exceptions.hpp:364
a seed index could not be merged
Definition ots-exceptions.hpp:391
MergeError(const std::string &msg)
Definition ots-exceptions.hpp:394
a default language is expected but not set
Definition ots-exceptions.hpp:297
NoDefaultLanguageSet()
Definition ots-exceptions.hpp:300
a password is not supported for the seed type
Definition ots-exceptions.hpp:381
PasswordNotSupported()
Definition ots-exceptions.hpp:384
a seed could not be encoded
Definition ots-exceptions.hpp:349
SeedDecodingFailed(const std::string &msg)
Definition ots-exceptions.hpp:353
SeedDecodingFailed()
Definition ots-exceptions.hpp:352
a seed could not be encoded
Definition ots-exceptions.hpp:338
SeedEncodingFailed()
Definition ots-exceptions.hpp:341
SeedEncodingFailed(const std::string &msg)
Definition ots-exceptions.hpp:342
you need at least two values to merge.
Definition ots-exceptions.hpp:371
TooFewValues()
Definition ots-exceptions.hpp:374
a seed expected has a different word count. Polyseed are 16 words, Monero Seeds are 25 words,...
Definition ots-exceptions.hpp:328
WordCount()
Definition ots-exceptions.hpp:331
a seed expected if not found
Definition ots-exceptions.hpp:505
SeedNotFound()
Definition ots-exceptions.hpp:508
a message is empty
Definition ots-exceptions.hpp:270
EmptyMessage()
Definition ots-exceptions.hpp:273
a signature is empty
Definition ots-exceptions.hpp:280
EmptySignature()
Definition ots-exceptions.hpp:283
a signature is invalid
Definition ots-exceptions.hpp:259
InvalidSignature(const std::string &msg)
Definition ots-exceptions.hpp:263
InvalidSignature()
Definition ots-exceptions.hpp:262
the provided unsigned transaction is not valid
Definition ots-exceptions.hpp:678
Invalid(const std::string &msg)
Definition ots-exceptions.hpp:682
Invalid()
Definition ots-exceptions.hpp:681
wallet does not contain the provided address
Definition ots-exceptions.hpp:588
AddressNotFound()
Definition ots-exceptions.hpp:591
the provided ciphertext is not valid
Definition ots-exceptions.hpp:631
CiphertextAuthenticationFailed()
Definition ots-exceptions.hpp:634
CiphertextAuthenticationFailed(const std::string &msg)
Definition ots-exceptions.hpp:635
export key images failed
Definition ots-exceptions.hpp:609
ExportKeyImages()
Definition ots-exceptions.hpp:612
ExportKeyImages(const std::string &msg)
Definition ots-exceptions.hpp:613
Import outputs failed.
Definition ots-exceptions.hpp:598
ImportOutputs()
Definition ots-exceptions.hpp:601
ImportOutputs(const std::string &msg)
Definition ots-exceptions.hpp:602
an internal error occurred (monero specific)
Definition ots-exceptions.hpp:642
InternalError(const std::string &msg)
Definition ots-exceptions.hpp:646
InternalError()
Definition ots-exceptions.hpp:645
the provided ciphertext is not valid
Definition ots-exceptions.hpp:620
InvalidCiphertext()
Definition ots-exceptions.hpp:623
InvalidCiphertext(const std::string &msg)
Definition ots-exceptions.hpp:624
a conversion to std::string is not allowed
Definition ots-exceptions.hpp:226
UnsafeConversion()
Definition ots-exceptions.hpp:229
a conversion to std::vector is not allowed
Definition ots-exceptions.hpp:242
UnsafeConversion()
Definition ots-exceptions.hpp:245
The library exists complete only in this namespace.
Definition account.hpp:39
#define REGISTER_EXCEPTION(CLASS, CODE, NAME)
Definition ots-exceptions.hpp:15
Definition ots-exceptions.hpp:43
const std::type_info & type
Definition ots-exceptions.hpp:46
int32_t error_code
Definition ots-exceptions.hpp:44
const char * error_class
Definition ots-exceptions.hpp:45