Monero
Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1// Copyright (c) 2017-2022, The Monero Project
2//
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without modification, are
6// permitted provided that the following conditions are met:
7//
8// 1. Redistributions of source code must retain the above copyright notice, this list of
9// conditions and the following disclaimer.
10//
11// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12// of conditions and the following disclaimer in the documentation and/or other
13// materials provided with the distribution.
14//
15// 3. Neither the name of the copyright holder nor the names of its contributors may be
16// used to endorse or promote products derived from this software without specific
17// prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29
30#ifndef MONERO_EXCEPTIONS_H
31#define MONERO_EXCEPTIONS_H
32
33#include <exception>
34#include <string>
35#include <boost/optional.hpp>
36
37namespace hw {
38namespace trezor {
39namespace exc {
40
41 class SecurityException : public std::exception {
42 protected:
43 boost::optional<std::string> reason;
44
45 public:
46 SecurityException(): reason("General Security exception"){}
47 explicit SecurityException(std::string what): reason(what){}
48
49 virtual const char* what() const throw() {
50 return reason.get().c_str();
51 }
52 };
53
55 public:
57 Poly1305TagInvalid(): SecurityException("Poly1305 authentication tag invalid"){}
58 };
59
60 class TrezorException : public std::exception {
61 protected:
62 boost::optional<std::string> reason;
63
64 public:
65 TrezorException(): reason("General Trezor exception"){}
66 explicit TrezorException(std::string what): reason(what){}
67
68 virtual const char* what() const throw() {
69 return reason.get().c_str();
70 }
71 };
72
74 public:
76 CommunicationException(): TrezorException("Trezor communication error"){}
77 };
78
80 public:
82 EncodingException(): CommunicationException("Trezor message encoding error"){}
83 };
84
90
96
102
108
110 public:
112 TimeoutException(): CommunicationException("Trezor communication timeout"){}
113 };
114
120
121 // Communication protocol namespace
122 // Separated to distinguish between client and Trezor side exceptions.
123namespace proto {
124
126 public:
128 SecurityException(): ProtocolException("Security assertion violated in the protocol"){}
129 };
130
132 private:
133 boost::optional<uint32_t> code;
134 boost::optional<std::string> message;
135 public:
137 FailureException(): ProtocolException("Trezor returned failure"){}
138 FailureException(boost::optional<uint32_t> code,
139 boost::optional<std::string> message)
140 : code(code), message(message) {
141 reason = "Trezor returned failure: code="
142 + (code ? std::to_string(code.get()) : "")
143 + ", message=" + (message ? message.get() : "");
144 };
145 };
146
148 public:
150 UnexpectedMessageException(): FailureException("Trezor claims unexpected message received"){}
151 };
152
154 public:
156 CancelledException(): FailureException("Trezor returned: cancelled operation"){}
157 };
158
160 public:
162 PinExpectedException(): FailureException("Trezor claims PIN is expected"){}
163 };
164
166 public:
168 InvalidPinException(): FailureException("Trezor claims PIN is invalid"){}
169 };
170
172 public:
174 NotEnoughFundsException(): FailureException("Trezor claims not enough funds"){}
175 };
176
178 public:
180 NotInitializedException(): FailureException("Trezor claims not initialized"){}
181 };
182
184 public:
186 FirmwareErrorException(): FailureException("Trezor returned firmware error"){}
187 };
188
189}
190}
191}
192}
193#endif //MONERO_EXCEPTIONS_H
CommunicationException()
Definition exceptions.hpp:76
TrezorException()
Definition exceptions.hpp:65
CommunicationException()
Definition exceptions.hpp:76
DeviceAcquireException()
Definition exceptions.hpp:100
CommunicationException()
Definition exceptions.hpp:76
DeviceNotResponsiveException()
Definition exceptions.hpp:94
CommunicationException()
Definition exceptions.hpp:76
EncodingException()
Definition exceptions.hpp:82
CommunicationException()
Definition exceptions.hpp:76
NotConnectedException()
Definition exceptions.hpp:88
Poly1305TagInvalid()
Definition exceptions.hpp:57
SecurityException()
Definition exceptions.hpp:46
CommunicationException()
Definition exceptions.hpp:76
ProtocolException()
Definition exceptions.hpp:118
SecurityException(std::string what)
Definition exceptions.hpp:47
SecurityException()
Definition exceptions.hpp:46
boost::optional< std::string > reason
Definition exceptions.hpp:43
virtual const char * what() const
Definition exceptions.hpp:49
CommunicationException()
Definition exceptions.hpp:76
SessionException()
Definition exceptions.hpp:106
TimeoutException()
Definition exceptions.hpp:112
CommunicationException()
Definition exceptions.hpp:76
virtual const char * what() const
Definition exceptions.hpp:68
TrezorException(std::string what)
Definition exceptions.hpp:66
boost::optional< std::string > reason
Definition exceptions.hpp:62
TrezorException()
Definition exceptions.hpp:65
CancelledException()
Definition exceptions.hpp:156
FailureException()
Definition exceptions.hpp:137
FailureException(boost::optional< uint32_t > code, boost::optional< std::string > message)
Definition exceptions.hpp:138
boost::optional< std::string > message
Definition exceptions.hpp:134
FailureException()
Definition exceptions.hpp:137
ProtocolException()
Definition exceptions.hpp:118
boost::optional< uint32_t > code
Definition exceptions.hpp:133
FirmwareErrorException()
Definition exceptions.hpp:186
FailureException()
Definition exceptions.hpp:137
InvalidPinException()
Definition exceptions.hpp:168
FailureException()
Definition exceptions.hpp:137
NotEnoughFundsException()
Definition exceptions.hpp:174
FailureException()
Definition exceptions.hpp:137
NotInitializedException()
Definition exceptions.hpp:180
FailureException()
Definition exceptions.hpp:137
PinExpectedException()
Definition exceptions.hpp:162
FailureException()
Definition exceptions.hpp:137
SecurityException()
Definition exceptions.hpp:128
ProtocolException()
Definition exceptions.hpp:118
UnexpectedMessageException()
Definition exceptions.hpp:150
FailureException()
Definition exceptions.hpp:137
Definition exceptions.hpp:123
Definition exceptions.hpp:39
Definition device_trezor.cpp:35
Definition device.cpp:38