Electroneum
Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1
// Copyright (c) 2017-Present, Electroneum
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 ELECTRONEUM_EXCEPTIONS_H
31
#define ELECTRONEUM_EXCEPTIONS_H
32
33
#include <exception>
34
#include <string>
35
#include <boost/optional.hpp>
36
37
namespace
hw
{
38
namespace
trezor
{
39
namespace
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
54
class
Poly1305TagInvalid
:
public
SecurityException
{
55
public
:
56
using
SecurityException::SecurityException
;
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
73
class
CommunicationException
:
public
TrezorException
{
74
public
:
75
using
TrezorException::TrezorException
;
76
CommunicationException
():
TrezorException
(
"Trezor communication error"
){}
77
};
78
79
class
EncodingException
:
public
CommunicationException
{
80
public
:
81
using
CommunicationException::CommunicationException
;
82
EncodingException
():
CommunicationException
(
"Trezor message encoding error"
){}
83
};
84
85
class
NotConnectedException
:
public
CommunicationException
{
86
public
:
87
using
CommunicationException::CommunicationException
;
88
NotConnectedException
():
CommunicationException
(
"Trezor not connected"
){}
89
};
90
91
class
DeviceNotResponsiveException
:
public
CommunicationException
{
92
public
:
93
using
CommunicationException::CommunicationException
;
94
DeviceNotResponsiveException
():
CommunicationException
(
"Trezor does not respond to ping"
){}
95
};
96
97
class
DeviceAcquireException
:
public
CommunicationException
{
98
public
:
99
using
CommunicationException::CommunicationException
;
100
DeviceAcquireException
():
CommunicationException
(
"Trezor could not be acquired"
){}
101
};
102
103
class
SessionException
:
public
CommunicationException
{
104
public
:
105
using
CommunicationException::CommunicationException
;
106
SessionException
():
CommunicationException
(
"Trezor session expired"
){}
107
};
108
109
class
TimeoutException
:
public
CommunicationException
{
110
public
:
111
using
CommunicationException::CommunicationException
;
112
TimeoutException
():
CommunicationException
(
"Trezor communication timeout"
){}
113
};
114
115
class
ProtocolException
:
public
CommunicationException
{
116
public
:
117
using
CommunicationException::CommunicationException
;
118
ProtocolException
():
CommunicationException
(
"Trezor protocol error"
){}
119
};
120
121
// Communication protocol namespace
122
// Separated to distinguish between client and Trezor side exceptions.
123
namespace
proto
{
124
125
class
SecurityException
:
public
ProtocolException
{
126
public
:
127
using
ProtocolException::ProtocolException
;
128
SecurityException
():
ProtocolException
(
"Security assertion violated in the protocol"
){}
129
};
130
131
class
FailureException
:
public
ProtocolException
{
132
private
:
133
boost::optional<uint32_t> code;
134
boost::optional<std::string> message;
135
public
:
136
using
ProtocolException::ProtocolException
;
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
147
class
UnexpectedMessageException
:
public
FailureException
{
148
public
:
149
using
FailureException::FailureException
;
150
UnexpectedMessageException
():
FailureException
(
"Trezor claims unexpected message received"
){}
151
};
152
153
class
CancelledException
:
public
FailureException
{
154
public
:
155
using
FailureException::FailureException
;
156
CancelledException
():
FailureException
(
"Trezor returned: cancelled operation"
){}
157
};
158
159
class
PinExpectedException
:
public
FailureException
{
160
public
:
161
using
FailureException::FailureException
;
162
PinExpectedException
():
FailureException
(
"Trezor claims PIN is expected"
){}
163
};
164
165
class
InvalidPinException
:
public
FailureException
{
166
public
:
167
using
FailureException::FailureException
;
168
InvalidPinException
():
FailureException
(
"Trezor claims PIN is invalid"
){}
169
};
170
171
class
NotEnoughFundsException
:
public
FailureException
{
172
public
:
173
using
FailureException::FailureException
;
174
NotEnoughFundsException
():
FailureException
(
"Trezor claims not enough funds"
){}
175
};
176
177
class
NotInitializedException
:
public
FailureException
{
178
public
:
179
using
FailureException::FailureException
;
180
NotInitializedException
():
FailureException
(
"Trezor claims not initialized"
){}
181
};
182
183
class
FirmwareErrorException
:
public
FailureException
{
184
public
:
185
using
FailureException::FailureException
;
186
FirmwareErrorException
():
FailureException
(
"Trezor returned firmware error"
){}
187
};
188
189
}
190
}
191
}
192
}
193
#endif
//ELECTRONEUM_EXCEPTIONS_H
hw::trezor::exc::CommunicationException::CommunicationException
CommunicationException()
Definition
exceptions.hpp:76
hw::trezor::exc::CommunicationException::TrezorException
TrezorException()
Definition
exceptions.hpp:65
hw::trezor::exc::DeviceAcquireException::CommunicationException
CommunicationException()
Definition
exceptions.hpp:76
hw::trezor::exc::DeviceAcquireException::DeviceAcquireException
DeviceAcquireException()
Definition
exceptions.hpp:100
hw::trezor::exc::DeviceNotResponsiveException::CommunicationException
CommunicationException()
Definition
exceptions.hpp:76
hw::trezor::exc::DeviceNotResponsiveException::DeviceNotResponsiveException
DeviceNotResponsiveException()
Definition
exceptions.hpp:94
hw::trezor::exc::EncodingException::CommunicationException
CommunicationException()
Definition
exceptions.hpp:76
hw::trezor::exc::EncodingException::EncodingException
EncodingException()
Definition
exceptions.hpp:82
hw::trezor::exc::NotConnectedException::CommunicationException
CommunicationException()
Definition
exceptions.hpp:76
hw::trezor::exc::NotConnectedException::NotConnectedException
NotConnectedException()
Definition
exceptions.hpp:88
hw::trezor::exc::Poly1305TagInvalid::Poly1305TagInvalid
Poly1305TagInvalid()
Definition
exceptions.hpp:57
hw::trezor::exc::Poly1305TagInvalid::SecurityException
SecurityException()
Definition
exceptions.hpp:46
hw::trezor::exc::ProtocolException::CommunicationException
CommunicationException()
Definition
exceptions.hpp:76
hw::trezor::exc::ProtocolException::ProtocolException
ProtocolException()
Definition
exceptions.hpp:118
hw::trezor::exc::SecurityException::SecurityException
SecurityException(std::string what)
Definition
exceptions.hpp:47
hw::trezor::exc::SecurityException::SecurityException
SecurityException()
Definition
exceptions.hpp:46
hw::trezor::exc::SecurityException::reason
boost::optional< std::string > reason
Definition
exceptions.hpp:43
hw::trezor::exc::SecurityException::what
virtual const char * what() const
Definition
exceptions.hpp:49
hw::trezor::exc::SessionException::CommunicationException
CommunicationException()
Definition
exceptions.hpp:76
hw::trezor::exc::SessionException::SessionException
SessionException()
Definition
exceptions.hpp:106
hw::trezor::exc::TimeoutException::TimeoutException
TimeoutException()
Definition
exceptions.hpp:112
hw::trezor::exc::TimeoutException::CommunicationException
CommunicationException()
Definition
exceptions.hpp:76
hw::trezor::exc::TrezorException::what
virtual const char * what() const
Definition
exceptions.hpp:68
hw::trezor::exc::TrezorException::TrezorException
TrezorException(std::string what)
Definition
exceptions.hpp:66
hw::trezor::exc::TrezorException::reason
boost::optional< std::string > reason
Definition
exceptions.hpp:62
hw::trezor::exc::TrezorException::TrezorException
TrezorException()
Definition
exceptions.hpp:65
hw::trezor::exc::proto::CancelledException::CancelledException
CancelledException()
Definition
exceptions.hpp:156
hw::trezor::exc::proto::CancelledException::FailureException
FailureException()
Definition
exceptions.hpp:137
hw::trezor::exc::proto::FailureException::FailureException
FailureException(boost::optional< uint32_t > code, boost::optional< std::string > message)
Definition
exceptions.hpp:138
hw::trezor::exc::proto::FailureException::FailureException
FailureException()
Definition
exceptions.hpp:137
hw::trezor::exc::proto::FailureException::ProtocolException
ProtocolException()
Definition
exceptions.hpp:118
hw::trezor::exc::proto::FirmwareErrorException::FirmwareErrorException
FirmwareErrorException()
Definition
exceptions.hpp:186
hw::trezor::exc::proto::FirmwareErrorException::FailureException
FailureException()
Definition
exceptions.hpp:137
hw::trezor::exc::proto::InvalidPinException::InvalidPinException
InvalidPinException()
Definition
exceptions.hpp:168
hw::trezor::exc::proto::InvalidPinException::FailureException
FailureException()
Definition
exceptions.hpp:137
hw::trezor::exc::proto::NotEnoughFundsException::NotEnoughFundsException
NotEnoughFundsException()
Definition
exceptions.hpp:174
hw::trezor::exc::proto::NotEnoughFundsException::FailureException
FailureException()
Definition
exceptions.hpp:137
hw::trezor::exc::proto::NotInitializedException::NotInitializedException
NotInitializedException()
Definition
exceptions.hpp:180
hw::trezor::exc::proto::NotInitializedException::FailureException
FailureException()
Definition
exceptions.hpp:137
hw::trezor::exc::proto::PinExpectedException::PinExpectedException
PinExpectedException()
Definition
exceptions.hpp:162
hw::trezor::exc::proto::PinExpectedException::FailureException
FailureException()
Definition
exceptions.hpp:137
hw::trezor::exc::proto::SecurityException::SecurityException
SecurityException()
Definition
exceptions.hpp:128
hw::trezor::exc::proto::SecurityException::ProtocolException
ProtocolException()
Definition
exceptions.hpp:118
hw::trezor::exc::proto::UnexpectedMessageException::UnexpectedMessageException
UnexpectedMessageException()
Definition
exceptions.hpp:150
hw::trezor::exc::proto::UnexpectedMessageException::FailureException
FailureException()
Definition
exceptions.hpp:137
hw::trezor::exc::proto
Definition
exceptions.hpp:123
hw::trezor::exc
Definition
exceptions.hpp:39
hw::trezor
Definition
device_trezor.cpp:33
hw
Definition
device.cpp:38
src
device_trezor
trezor
exceptions.hpp
Generated on
for Electroneum by
1.16.1